address.js 4.9 KB

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