address.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/address/address.js
  2. var app = getApp();
  3. Page({
  4. data: {
  5. _num:'',
  6. cartId: '',
  7. pinkId: '',
  8. couponId: '',
  9. addressArray:[]
  10. },
  11. onLoad: function (options) {
  12. app.setBarColor();
  13. app.setUserInfo();
  14. console.log(options);
  15. if (options.cartId) {
  16. this.setData({
  17. cartId: options.cartId,
  18. pinkId: options.pinkId,
  19. couponId: options.couponId,
  20. })
  21. }
  22. this.getAddress();
  23. },
  24. getAddress: function () {
  25. var that = this;
  26. var header = {
  27. 'content-type': 'application/x-www-form-urlencoded',
  28. };
  29. wx.request({
  30. url: app.globalData.url + '/routine/auth_api/user_address_list?uid=' + app.globalData.uid,
  31. method: 'POST',
  32. header: header,
  33. success: function (res) {
  34. if (res.data.code == 200) {
  35. if (res.data.data.length < 1) {
  36. wx.showToast({
  37. title: '暂无收货地址,请先添加收货地址',
  38. icon: 'none',
  39. duration: 1000,
  40. })
  41. setTimeout(function () {
  42. that.addAddress();
  43. }, 1100)
  44. } else {
  45. that.setData({
  46. addressArray: res.data.data
  47. })
  48. for (var i in res.data.data){
  49. if (res.data.data[i].is_default){
  50. that.setData({
  51. _num: res.data.data[i].id
  52. })
  53. }
  54. }
  55. }
  56. }
  57. }
  58. })
  59. },
  60. addAddress:function(){
  61. var cartId = this.data.cartId;
  62. var pinkId = this.data.pinkId;
  63. var couponId = this.data.couponId;
  64. this.setData({
  65. cartId: '',
  66. pinkId:'',
  67. couponId:'',
  68. })
  69. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  70. url: '/pages/addaddress/addaddress?cartId=' + cartId + '&pinkId=' + pinkId + '&couponId=' + couponId
  71. })
  72. },
  73. goOrder:function(e){
  74. var id = e.currentTarget.dataset.id;
  75. var cartId = '';
  76. var pinkId = '';
  77. var couponId = '';
  78. if (this.data.cartId && id){
  79. cartId = this.data.cartId;
  80. pinkId = this.data.pinkId;
  81. couponId = this.data.couponId;
  82. this.setData({
  83. cartId : '',
  84. pinkId : '',
  85. couponId : '',
  86. })
  87. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  88. url: '/pages/order-confirm/order-confirm?id=' + cartId + '&addressId=' + id + '&pinkId=' + pinkId + '&couponId=' + couponId
  89. })
  90. }
  91. },
  92. delAddress:function(e){
  93. var id = e.currentTarget.dataset.id;
  94. var that = this;
  95. var header = {
  96. 'content-type': 'application/x-www-form-urlencoded',
  97. };
  98. wx.request({
  99. url: app.globalData.url + '/routine/auth_api/remove_user_address?uid=' + app.globalData.uid,
  100. method: 'GET',
  101. header: header,
  102. data:{
  103. addressId:id
  104. },
  105. success: function (res) {
  106. if (res.data.code == 200) {
  107. wx.showToast({
  108. title: '删除成功',
  109. icon: 'success',
  110. duration: 1000,
  111. })
  112. that.getAddress();
  113. } else {
  114. wx.showToast({
  115. title: res.data.msg,
  116. icon: 'none',
  117. duration: 1000,
  118. })
  119. }
  120. }
  121. })
  122. },
  123. editAddress: function (e) {
  124. var cartId = this.data.cartId;
  125. var pinkId = this.data.pinkId;
  126. var couponId = this.data.couponId;
  127. this.setData({
  128. cartId: '',
  129. pinkId: '',
  130. couponId: '',
  131. })
  132. wx.navigateTo({ //跳转至指定页面并关闭其他打开的所有页面(这个最好用在返回至首页的的时候)
  133. url: '/pages/addaddress/addaddress?id=' + e.currentTarget.dataset.id + '&cartId=' + cartId + '&pinkId=' + pinkId + '&couponId=' + couponId
  134. })
  135. },
  136. activetap:function(e){
  137. var id = e.target.dataset.idx;
  138. var that = this;
  139. var header = {
  140. 'content-type': 'application/x-www-form-urlencoded',
  141. };
  142. wx.request({
  143. url: app.globalData.url + '/routine/auth_api/set_user_default_address?uid=' + app.globalData.uid,
  144. method: 'GET',
  145. header: header,
  146. data:{
  147. addressId:id
  148. },
  149. success: function (res) {
  150. if (res.data.code == 200) {
  151. wx.showToast({
  152. title: '设置成功',
  153. icon: 'success',
  154. duration: 1000,
  155. })
  156. that.setData({
  157. _num: id
  158. })
  159. } else {
  160. wx.showToast({
  161. title: res.data.msg,
  162. icon: 'none',
  163. duration: 1000,
  164. })
  165. }
  166. }
  167. })
  168. }
  169. })