add.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // customized/pages/address/add/add.js
  2. let app = getApp();
  3. let host = app.globalData.servsers; // 请求的url
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. name:'',
  10. phone:'',
  11. region: ['上海市', '上海市', '黄浦区'],
  12. detailAddress:'',
  13. switchChecked:false, //是否默认
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. },
  20. /**
  21. * 生命周期函数--监听页面初次渲染完成
  22. */
  23. onReady: function () {
  24. },
  25. /**
  26. * 生命周期函数--监听页面显示
  27. */
  28. onShow: function () {
  29. },
  30. /**
  31. * 生命周期函数--监听页面隐藏
  32. */
  33. onHide: function () {
  34. },
  35. /**
  36. * 生命周期函数--监听页面卸载
  37. */
  38. onUnload: function () {
  39. },
  40. /**
  41. * 页面相关事件处理函数--监听用户下拉动作
  42. */
  43. onPullDownRefresh: function () {
  44. },
  45. /**
  46. * 页面上拉触底事件的处理函数
  47. */
  48. onReachBottom: function () {
  49. },
  50. /**
  51. * 用户点击右上角分享
  52. */
  53. onShareAppMessage: function () {
  54. },
  55. bindRegionChange(e) {
  56. console.log('picker发送选择改变,携带值为', e.detail.value)
  57. this.setData({
  58. region: e.detail.value
  59. })
  60. },
  61. switchChange(e){
  62. this.setData({
  63. switchChecked: e.detail.value
  64. })
  65. },
  66. nameChange(e){
  67. this.setData({
  68. name: e.detail.value
  69. })
  70. },
  71. phoneChange(e) {
  72. this.setData({
  73. phone: e.detail.value
  74. })
  75. },
  76. addressInput(e){ // 详细地址
  77. console.log(e)
  78. this.setData({
  79. detailAddress: e.detail.value
  80. })
  81. },
  82. addAddress(){ // 保存地址
  83. let that =this;
  84. if(!that.data.name){
  85. wx.showToast({
  86. title: '收货人没有输入',
  87. icon:"none"
  88. });
  89. return
  90. }
  91. if(!that.data.phone){
  92. wx.showToast({
  93. title: '手机号码没有输入',
  94. icon: "none"
  95. });
  96. return
  97. }
  98. if (!that.data.detailAddress) {
  99. wx.showToast({
  100. title: '详细地址没有输入',
  101. icon: "none"
  102. });
  103. return
  104. }
  105. wx.request({
  106. url: host +'/adressapi/insertadd',
  107. header: {
  108. 'content-type': 'application/x-www-form-urlencoded'
  109. },
  110. data:{
  111. user_id: app.globalData.user_id, //'oovpNwjlsY6xx8ceCebFa1dOLd9E', //app.globalData.user_id,
  112. consignee: that.data.name, //收货人
  113. province:that.data.region[0],
  114. city: that.data.region[1],
  115. area: that.data.region[2],
  116. adress:that.data.detailAddress,
  117. phone:that.data.phone,
  118. adress_flag: that.data.switchChecked ? 0 : 1 // 是否默认 0是 1 否
  119. },
  120. success(res){
  121. console.log(res,"地址保存")
  122. wx.showToast({
  123. title: '地址添加成功',
  124. icon:'none',
  125. success(){
  126. setTimeout(()=>{
  127. wx.navigateBack({
  128. delta: 1
  129. })
  130. },1000)
  131. }
  132. })
  133. }
  134. })
  135. },
  136. getEditAddress(){ // 获取编辑的地址
  137. let address = wx.getStorageSync('address'),
  138. name = address.consignee,
  139. phone =address.phone,
  140. region = [address.province,address.city,address.area],
  141. detailAddress =address.adress,
  142. switchChecked = address.switchChecked;
  143. console.log(address)
  144. this.setData({
  145. name:name,
  146. phone:phone,
  147. region: region,
  148. detailAddress: detailAddress,
  149. switchChecked: switchChecked
  150. })
  151. }
  152. })