address.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const api_order = require("../api/order.js");
  4. const common_assets = require("../common/assets.js");
  5. const _sfc_main = {
  6. data() {
  7. return {
  8. address: []
  9. };
  10. },
  11. onLoad() {
  12. this.getUserAddr();
  13. common_vendor.index.$on("refreshAddress", () => {
  14. this.getUserAddr();
  15. });
  16. },
  17. methods: {
  18. // 获取用户收货地址
  19. getUserAddr() {
  20. this.userInfo = JSON.parse(common_vendor.index.getStorageSync("userInfo"));
  21. api_order.userAddr(this.userInfo.userId).then(
  22. (res) => {
  23. if (res.code == 200) {
  24. console.log("用户收货地址>>>>", res.data);
  25. this.address = res.data;
  26. } else {
  27. common_vendor.index.showToast({
  28. title: res.msg,
  29. icon: "none"
  30. });
  31. }
  32. },
  33. (rej) => {
  34. }
  35. );
  36. },
  37. // 选地址
  38. selectAddress(item) {
  39. common_vendor.index.$emit("updateAddress", item);
  40. common_vendor.index.navigateBack({
  41. delta: 1
  42. });
  43. },
  44. // 编辑地址
  45. editAddress(item) {
  46. common_vendor.index.navigateTo({
  47. url: "./addAddress?type=edit&addressId=" + item.addressId
  48. });
  49. },
  50. // 删除所有地址(暂无)
  51. // delAllAddress(item) {
  52. // uni.showModal({
  53. // title: "提示",
  54. // content: "确认删除所有地址吗?",
  55. // showCancel: true,
  56. // cancelText: '取消',
  57. // confirmText: '确定',
  58. // success: res => {
  59. // if (res.confirm) {
  60. // var data = {}
  61. // delAllAddress(data).then(
  62. // res => {
  63. // if (res.code == 200) {
  64. // uni.showToast({
  65. // icon: 'success',
  66. // title: "操作成功",
  67. // });
  68. // this.getAddressList()
  69. // } else {
  70. // uni.showToast({
  71. // icon: 'none',
  72. // title: "请求失败",
  73. // });
  74. // }
  75. // },
  76. // rej => {}
  77. // );
  78. // } else {
  79. // // 否则点击了取消
  80. // }
  81. // }
  82. // })
  83. // },
  84. // 删除地址
  85. delAddress(item) {
  86. common_vendor.index.showModal({
  87. title: "提示",
  88. content: "确认删除此地址吗?",
  89. showCancel: true,
  90. cancelText: "取消",
  91. confirmText: "确定",
  92. success: (res) => {
  93. if (res.confirm) {
  94. var data = {
  95. addressId: item.addressId
  96. };
  97. api_order.delAddress(data).then(
  98. (res2) => {
  99. if (res2.code == 200) {
  100. common_vendor.index.showToast({
  101. icon: "success",
  102. title: "操作成功"
  103. });
  104. this.getUserAddr();
  105. } else {
  106. common_vendor.index.showToast({
  107. icon: "none",
  108. title: "请求失败"
  109. });
  110. }
  111. },
  112. (rej) => {
  113. }
  114. );
  115. }
  116. }
  117. });
  118. },
  119. // getAddressList(){
  120. // uni.showLoading({
  121. // title:"正在加载中"
  122. // })
  123. // getAddressList().then(
  124. // res => {
  125. // uni.hideLoading()
  126. // if(res.code==200){
  127. // this.address=res.data;
  128. // }else{
  129. // uni.showToast({
  130. // icon:'none',
  131. // title: "请求失败",
  132. // });
  133. // }
  134. // },
  135. // rej => {}
  136. // );
  137. // },
  138. // 新建收货地址
  139. addAdress() {
  140. common_vendor.index.navigateTo({
  141. url: "./addAddress?type=add"
  142. });
  143. }
  144. }
  145. };
  146. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  147. return common_vendor.e({
  148. a: common_vendor.f($data.address, (item, index, i0) => {
  149. return common_vendor.e({
  150. a: item.isDefault == 1
  151. }, item.isDefault == 1 ? {} : {}, {
  152. b: common_vendor.t(item.province),
  153. c: common_vendor.t(item.city),
  154. d: common_vendor.t(item.district),
  155. e: common_vendor.t(item.detail),
  156. f: common_vendor.t(item.realName),
  157. g: common_vendor.t(_ctx.$parsePhone(item.phone)),
  158. h: common_vendor.o(($event) => $options.selectAddress(item), index),
  159. i: common_vendor.o(($event) => $options.delAddress(item), index),
  160. j: common_vendor.o(($event) => $options.editAddress(item), index),
  161. k: index
  162. });
  163. }),
  164. b: common_assets._imports_0$14,
  165. c: common_assets._imports_1$9,
  166. d: $data.address.length == 0
  167. }, $data.address.length == 0 ? {
  168. e: common_assets._imports_2$3,
  169. f: common_vendor.o(($event) => _ctx.getAddressList())
  170. } : {}, {
  171. g: common_vendor.o((...args) => $options.addAdress && $options.addAdress(...args))
  172. });
  173. }
  174. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  175. wx.createPage(MiniProgramPage);