edit.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // pages/mine/wxml/edit/edit.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. focus: false,
  9. inputValue: '',
  10. animationAddressMenu: {},
  11. addressMenuIsShow: false,
  12. region: ['山西省', '太原市', '迎泽区'],
  13. customItem: '',
  14. dataObj: {},
  15. array: [],
  16. },
  17. bindRegionChange: function (e) {
  18. //console.log('picker发送选择改变,携带值为', e.detail.value)
  19. this.setData({
  20. region: e.detail.value
  21. })
  22. },
  23. //上传
  24. formSubmit: function (e) {
  25. // //console.log(222)
  26. var _this = this;
  27. var province = '', city = '', district = '';
  28. var reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
  29. // //console.log('form发生了submit事件,携带数据为:', e.detail.value)
  30. var dataname = e.detail.value.name,
  31. dataphone = e.detail.value.phone,
  32. dataaddress = e.detail.value.address,
  33. dataarea = e.detail.value.area,
  34. datachecked = e.detail.value.checked;
  35. var is_default = "";
  36. //console.log()
  37. if (datachecked) {
  38. is_default = "是"
  39. } else {
  40. is_default = "否"
  41. }
  42. if (dataname !== "") {
  43. if (reg.test(dataphone) && dataphone !== "") {
  44. if (dataarea !== "") {
  45. wx.getStorage({
  46. key: 'key',
  47. success: function (cookies) {
  48. wx.request({
  49. url: app.globalData.prodUrl + 'web-pm/wx/address/update',
  50. header: {
  51. 'ydw-token': cookies.data.ydw_token
  52. },
  53. data: {
  54. user_name: dataname,
  55. user_mobile: dataphone,
  56. address: dataaddress,
  57. detail: dataarea,
  58. is_default: is_default,
  59. province: dataaddress[0],
  60. city: dataaddress[1],
  61. district: dataaddress[2],
  62. kid: _this.data.array.kid
  63. },
  64. success: function (data) {
  65. //console.log(data)
  66. wx.navigateBack({
  67. delta: 1,
  68. success: function () {
  69. var pages = getCurrentPages();
  70. var page = getCurrentPages().pop();
  71. //console.log(pages)
  72. if (page == undefined || page == null) return;
  73. pages[1].onLoad(pages[1].options);
  74. }
  75. })
  76. }
  77. })
  78. }
  79. })
  80. } else {
  81. wx.showToast({
  82. title: '请填写地址',
  83. icon: 'none',
  84. duration: 2000
  85. })
  86. }
  87. } else {
  88. wx.showToast({
  89. title: '请正确填写手机号',
  90. icon: 'none',
  91. duration: 2000
  92. })
  93. }
  94. } else {
  95. wx.showToast({
  96. title: '请填写姓名',
  97. icon: 'none',
  98. duration: 2000
  99. })
  100. }
  101. // wx.navigateTo({
  102. // url: '../receivingaddress/receivingaddress',
  103. // })
  104. },
  105. /**
  106. * 生命周期函数--监听页面加载
  107. */
  108. onLoad: function (options) {
  109. //console.log(options.kid)
  110. var _this = this;
  111. wx.request({
  112. url: app.globalData.prodUrl + 'web-pm/wx/address/get',
  113. header: {
  114. 'ydw-token': wx.getStorageSync('key').ydw_token
  115. },
  116. data: {
  117. kid: options.kid
  118. },
  119. success: function (data) {
  120. //console.log(data.data)
  121. _this.setData({
  122. array: data.data.t_receive_address,
  123. })
  124. var region = new Array;
  125. region[0] = data.data.t_receive_address.province;
  126. region[1] = data.data.t_receive_address.city;
  127. region[2] = data.data.t_receive_address.district;
  128. //console.log(region)
  129. _this.setData({
  130. region: region
  131. })
  132. var is_default = data.data.t_receive_address.is_default;
  133. if (is_default == "是"){
  134. //console.log(111)
  135. _this.setData({
  136. checked : true
  137. })
  138. }else{
  139. _this.setData({
  140. checked: false
  141. })
  142. }
  143. }
  144. })
  145. },
  146. /**
  147. * 生命周期函数--监听页面初次渲染完成
  148. */
  149. onReady: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面显示
  153. */
  154. onShow: function () {
  155. },
  156. /**
  157. * 生命周期函数--监听页面隐藏
  158. */
  159. onHide: function () {
  160. },
  161. /**
  162. * 生命周期函数--监听页面卸载
  163. */
  164. onUnload: function () {
  165. },
  166. /**
  167. * 页面相关事件处理函数--监听用户下拉动作
  168. */
  169. onPullDownRefresh: function () {
  170. },
  171. /**
  172. * 页面上拉触底事件的处理函数
  173. */
  174. onReachBottom: function () {
  175. }
  176. })