东风启辰小程序端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

235 Zeilen
5.4KB

  1. // pages/address/address.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. submitData:{
  10. realName:"",
  11. mobile: "",//电话
  12. province: "",//省份
  13. city: "",//城市
  14. district: "",//地区
  15. addressDetail:""//详细
  16. },
  17. isAddress: false,//是否有地址
  18. phoneInputShow: false,//是否显示电话输入框
  19. marginT:0,
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. app.globalData.nowPage = 4;
  26. if (app.globalData.userPhoneType=="ios"){
  27. this.setData({
  28. marginT:-20
  29. })
  30. }
  31. if (app.globalData.openid) {
  32. this.loadFun();
  33. } else {
  34. app.globalData.openidSuccessFuc = this.loadFun;
  35. }
  36. // if (app.globalData.userMobile) {
  37. // this.data.submitData.mobile = app.globalData.userMobile;
  38. // this.setData({
  39. // phoneInputShow: true,
  40. // submitData: this.data.submitData
  41. // })
  42. // }
  43. },
  44. loadFun: function () {
  45. this.getAddress();
  46. },
  47. /**
  48. * 生命周期函数--监听页面初次渲染完成
  49. */
  50. onReady: function () {
  51. },
  52. /**
  53. * 生命周期函数--监听页面显示
  54. */
  55. onShow: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面隐藏
  59. */
  60. onHide: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面卸载
  64. */
  65. onUnload: function () {
  66. },
  67. /**
  68. * 页面相关事件处理函数--监听用户下拉动作
  69. */
  70. onPullDownRefresh: function () {
  71. },
  72. /**
  73. * 页面上拉触底事件的处理函数
  74. */
  75. onReachBottom: function () {
  76. },
  77. /**
  78. * 用户点击右上角分享
  79. */
  80. onShareAppMessage: function () {
  81. return app.sharePack();
  82. },
  83. addressChange:function(e){//所在地区发生改变
  84. this.data.submitData.province = e.detail.value[0];
  85. this.data.submitData.city = e.detail.value[1];
  86. this.data.submitData.district = e.detail.value[2];
  87. this.setData({
  88. submitData:this.data.submitData
  89. })
  90. },
  91. getRealName: function (e) {//获取收货人
  92. this.data.submitData.realName = e.detail.value;
  93. this.setData({
  94. submitData: this.data.submitData
  95. })
  96. },
  97. getMobile: function (e) {//获取手机号码
  98. this.data.submitData.mobile = e.detail.value;
  99. this.setData({
  100. submitData: this.data.submitData
  101. })
  102. },
  103. getAddressDetail: function (e) {//获取详细地址
  104. this.data.submitData.addressDetail = e.detail.value;
  105. this.setData({
  106. submitData: this.data.submitData
  107. })
  108. },
  109. getAddress: function () {//获取地址
  110. app.wxRequest(app.globalData.urlRoot +"address/getAddress",{},res=>{
  111. if(res.code == 200){
  112. if(res.data){
  113. this.data.isAddress = true;
  114. this.data.submitData.realName = res.data.realName;
  115. this.data.submitData.mobile = res.data.mobile;
  116. this.data.submitData.province = res.data.province;
  117. this.data.submitData.city = res.data.city;
  118. this.data.submitData.district = res.data.district;
  119. this.data.submitData.addressDetail = res.data.addressDetail;
  120. this.setData({
  121. submitData: this.data.submitData
  122. })
  123. }
  124. }else{
  125. wx.showToast({
  126. title: res.msg,
  127. icon:"none"
  128. })
  129. }
  130. },this);
  131. },
  132. addAddress:function(){//添加地址
  133. app.wxRequest(app.globalData.urlRoot + "address/addAddress", this.data.submitData,res => {
  134. wx.showToast({
  135. title: res.msg,
  136. })
  137. if (res.code == 200) {
  138. wx.navigateBack({
  139. delta: 1
  140. })
  141. }
  142. },this,"POST")
  143. },
  144. updateAddress: function () {//更新地址
  145. app.wxRequest(app.globalData.urlRoot + "address/updateAddress", this.data.submitData, res => {
  146. wx.showToast({
  147. title: res.msg,
  148. })
  149. if (res.code == 200) {
  150. wx.navigateBack({
  151. delta:1
  152. })
  153. }
  154. }, this,"POST");
  155. },
  156. getUserPhone: function (e) {//获取用户手机号
  157. this.setData({
  158. phoneInputShow: true
  159. })
  160. if (e.detail.errMsg == 'getPhoneNumber:ok') {
  161. app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
  162. if (res.code == 200) {
  163. if (res.data && res.data.decodeData) {
  164. this.data.submitData.mobile = res.data.decodeData.phoneNumber;
  165. this.setData({
  166. submitData: this.data.submitData
  167. })
  168. }
  169. } else {
  170. wx.showToast({
  171. title: res.msg,
  172. icon: "none"
  173. })
  174. }
  175. }, this);
  176. }
  177. },
  178. submitAddress:function(){//保存地址
  179. if (!this.data.submitData.realName){
  180. wx.showToast({
  181. title: '请输入收货人',
  182. icon:"none"
  183. })
  184. return;
  185. }
  186. if (!app.mobileVerify(this.data.submitData.mobile)) {
  187. if (this.data.submitData.mobile) {
  188. wx.showToast({
  189. title: '请输入正确的电话',
  190. icon: 'none'
  191. })
  192. } else {
  193. wx.showToast({
  194. title: '请输入电话',
  195. icon: 'none'
  196. })
  197. }
  198. return;
  199. }
  200. if (!this.data.submitData.province) {
  201. wx.showToast({
  202. title: '请选择所在地区',
  203. icon: 'none'
  204. })
  205. return;
  206. }
  207. if (!this.data.submitData.addressDetail) {
  208. wx.showToast({
  209. title: '请输入详细地址',
  210. icon: "none"
  211. })
  212. return;
  213. }
  214. if(this.data.isAddress){
  215. this.updateAddress();
  216. } else {
  217. this.addAddress();
  218. }
  219. }
  220. })