东风启辰小程序端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

248 lines
6.8KB

  1. // pages/userMsg/userMsg.js
  2. const app = getApp()
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. },
  9. /**
  10. * 组件的初始数据
  11. */
  12. data: {
  13. imgUrl: app.globalData.urlStatic,//图片路径
  14. submitData: {
  15. realName: "",
  16. mobile: "",//电话
  17. province: "",//省份
  18. city: "",//城市
  19. district: "",//地区
  20. addressDetail: ""//详细
  21. },
  22. userData:{
  23. avatarUrl:"",
  24. nickName:""
  25. },
  26. isAddress: false,//是否有地址
  27. marginT: 0,
  28. },
  29. attached:function(){
  30. if (app.globalData.userPhoneType == "ios") {
  31. this.setData({
  32. marginT: -20
  33. })
  34. }
  35. if (app.globalData.openid) {
  36. this.loadFun();
  37. } else {
  38. app.globalData.openidSuccessFuc = this.loadFun;
  39. }
  40. },
  41. /**
  42. * 组件的方法列表
  43. */
  44. methods: {
  45. loadFun: function () {
  46. if (app.globalData.userInfoData) {
  47. this.data.userData.avatarUrl = app.globalData.userInfoData.avatarUrl;
  48. this.data.userData.nickName = app.globalData.userInfoData.nickName;
  49. this.setData({
  50. userData: this.data.userData
  51. })
  52. }
  53. this.getAddress();
  54. },
  55. getAddress: function () {//获取地址
  56. app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => {
  57. if (res.code == 200) {
  58. if (res.data) {
  59. this.data.isAddress = true;
  60. this.data.submitData.realName = res.data.realName;
  61. this.data.submitData.mobile = res.data.mobile;
  62. this.data.submitData.province = res.data.province;
  63. this.data.submitData.city = res.data.city;
  64. this.data.submitData.district = res.data.district;
  65. this.data.submitData.addressDetail = res.data.addressDetail;
  66. this.setData({
  67. submitData: this.data.submitData
  68. })
  69. }
  70. } else {
  71. wx.showToast({
  72. title: res.msg,
  73. icon: "none"
  74. })
  75. }
  76. }, this);
  77. },
  78. addAddress: function () {//添加地址
  79. app.wxRequest(app.globalData.urlRoot + "address/addAddress", this.data.submitData, res => {
  80. wx.showToast({
  81. title: res.msg,
  82. })
  83. if (res.code == 200) {
  84. if (app.globalData.skipType == 'mycenter') {
  85. app.globalData.skipType = null;
  86. wx.reLaunch({
  87. url: '/pages/myCenter/myCenter',
  88. })
  89. } else {
  90. this.closeXieyi();
  91. }
  92. }
  93. }, this, "POST")
  94. },
  95. updateAddress: function () {//更新地址
  96. app.wxRequest(app.globalData.urlRoot + "address/updateAddress", this.data.submitData, res => {
  97. wx.showToast({
  98. title: res.msg,
  99. })
  100. if (res.code == 200) {
  101. if (app.globalData.skipType == 'mycenter') {
  102. app.globalData.skipType = null;
  103. wx.reLaunch({
  104. url: '/pages/myCenter/myCenter',
  105. })
  106. } else {
  107. this.closeXieyi();
  108. }
  109. }
  110. }, this, "POST");
  111. },
  112. addressChange: function (e) {//所在地区发生改变
  113. this.data.submitData.province = e.detail.value[0];
  114. this.data.submitData.city = e.detail.value[1];
  115. this.data.submitData.district = e.detail.value[2];
  116. this.setData({
  117. submitData: this.data.submitData
  118. })
  119. },
  120. getNickName: function(e) {//获取昵称
  121. this.data.userData.nickName = e.detail.value;
  122. this.setData({
  123. userData: this.data.userData
  124. })
  125. },
  126. getRealName: function (e) {//获取收货人
  127. this.data.submitData.realName = e.detail.value;
  128. this.setData({
  129. submitData: this.data.submitData
  130. })
  131. },
  132. getMobile: function (e) {//获取手机号码
  133. this.data.submitData.mobile = e.detail.value;
  134. this.setData({
  135. submitData: this.data.submitData
  136. })
  137. },
  138. getAddressDetail: function (e) {//获取详细地址
  139. this.data.submitData.addressDetail = e.detail.value;
  140. this.setData({
  141. submitData: this.data.submitData
  142. })
  143. },
  144. saveUserMsg:function(){
  145. if (!this.data.submitData.realName) {
  146. wx.showToast({
  147. title: '请输入收货人',
  148. icon: "none"
  149. })
  150. return;
  151. }
  152. if (!app.mobileVerify(this.data.submitData.mobile)) {
  153. if (this.data.submitData.mobile) {
  154. wx.showToast({
  155. title: '请输入正确的电话',
  156. icon: 'none'
  157. })
  158. } else {
  159. wx.showToast({
  160. title: '请输入电话',
  161. icon: 'none'
  162. })
  163. }
  164. return;
  165. }
  166. if (!this.data.submitData.province) {
  167. wx.showToast({
  168. title: '请选择所在地区',
  169. icon: 'none'
  170. })
  171. return;
  172. }
  173. if (!this.data.submitData.addressDetail) {
  174. wx.showToast({
  175. title: '请输入详细地址',
  176. icon: "none"
  177. })
  178. return;
  179. }
  180. wx.showLoading({
  181. title: '保存中',
  182. mask: true
  183. })
  184. app.wxRequest(app.globalData.urlRoot + "userInfo/updateUserInfo", this.data.userData, res => {
  185. if (res.code == 200) {
  186. app.globalData.userInfoData.avatarUrl = this.data.userData.avatarUrl;
  187. app.globalData.userInfoData.nickName = this.data.userData.nickName;
  188. var userInfoData = wx.getStorageSync("userInfoData");
  189. userInfoData.avatarUrl = this.data.userData.avatarUrl;
  190. userInfoData.nickName = this.data.userData.nickName;
  191. wx.setStorageSync('userInfoData', userInfoData)
  192. this.submitAddress();
  193. }
  194. }, this, "POST")
  195. },
  196. submitAddress: function () {//保存地址
  197. if (this.data.isAddress) {
  198. this.updateAddress();
  199. } else {
  200. this.addAddress();
  201. }
  202. },
  203. closeXieyi: function () {
  204. this.triggerEvent('address')
  205. },
  206. changeHeadImg:function(){
  207. wx.chooseImage({
  208. count:1,
  209. success:(res)=>{
  210. wx.showLoading({
  211. title: '上传中',
  212. mask: true
  213. })
  214. wx.uploadFile({
  215. url: app.globalData.urlRoot + "upload/uploadImage",
  216. header: {
  217. "OPENID": app.globalData.openid,
  218. "VERSION": 100
  219. },
  220. filePath: res.tempFilePaths[0],
  221. name: "file",
  222. formData:{
  223. filePath:"avatar"
  224. },
  225. success: option => {
  226. wx.hideLoading();
  227. var json = JSON.parse(option.data);
  228. if (json.code==200){
  229. this.data.userData.avatarUrl = json.data[0].url;
  230. this.setData({
  231. userData: this.data.userData
  232. })
  233. }else{
  234. wx.showToast({
  235. title: option.msg,
  236. icon: 'none'
  237. })
  238. }
  239. }
  240. })
  241. }
  242. })
  243. }
  244. }
  245. })