小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
6.6 KiB

  1. <template>
  2. <view
  3. class="address-management"
  4. :class="addressList.length < 1 && page > 1 ? 'on' : ''"
  5. ref="container"
  6. >
  7. <view class="line" v-if="addressList.length > 0">
  8. <image :src="`${$VUE_APP_RESOURCES_URL}/images/line.jpg`" />
  9. </view>
  10. <view class="item" v-for="(item, addressListIndex) in addressList" :key="addressListIndex">
  11. <view class="address">
  12. <view class="consignee">
  13. 收货人{{ item.realName }}
  14. <text class="phone">{{ item.phone }}</text>
  15. </view>
  16. <view>
  17. 收货地址{{ item.province }}{{ item.city }}{{ item.district
  18. }}{{ item.detail }}
  19. </view>
  20. </view>
  21. <view class="operation acea-row row-between-wrapper">
  22. <view class="select-btn">
  23. <view class="checkbox-wrapper">
  24. <checkbox-group @change="radioChange(item.id)">
  25. <label class="well-check">
  26. <checkbox :value="item.isDefault==1?'checked':''" :checked="item.isDefault||item.isDefault=='1' ? true : false"></checkbox>
  27. <text class="default">设为默认</text>
  28. </label>
  29. </checkbox-group>
  30. <!-- <label class="well-check">
  31. <input
  32. type="radio"
  33. name="default"
  34. value
  35. :checked="item.isDefault ? true : false"
  36. @click="radioChange(addressListIndex)"
  37. />
  38. <i class="icon"></i>
  39. <text class="default">设为默认</text>
  40. </label>-->
  41. </view>
  42. </view>
  43. <view class="acea-row row-middle">
  44. <view @click="editAddress(addressListIndex)">
  45. <text class="iconfont icon-bianji"></text>编辑
  46. </view>
  47. <view @click="delAddress(addressListIndex)">
  48. <text class="iconfont icon-shanchu"></text>删除
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <Loading :loaded="loadend" :loading="loading"></Loading>
  54. <view class="noCommodity" v-if="addressList.length < 1 && page > 1">
  55. <view class="noPictrue">
  56. <image :src="`${$VUE_APP_RESOURCES_URL}/images/noAddress.png`" class="image" />
  57. </view>
  58. </view>
  59. <view style="height:100rpx;"></view>
  60. <view class="footer acea-row row-between-wrapper">
  61. <view class="addressBnt bg-color-red" v-if="isWechat" @click="addAddress">
  62. <text class="iconfont icon-tianjiadizhi"></text>添加新地址
  63. </view>
  64. <view class="addressBnt on bg-color-red" v-else @click="addAddress">
  65. <text class="iconfont icon-tianjiadizhi"></text>添加新地址
  66. </view>
  67. <!--<view class="addressBnt wxbnt" v-if="isWechat" @click="getAddress">-->
  68. <!--<text class="iconfont icon-weixin2"></text>导入微信地址-->
  69. <!--</view>-->
  70. </view>
  71. </view>
  72. </template>
  73. <style scoped lang="less">
  74. .address-management.on {
  75. background-color: #fff;
  76. height: 100vh;
  77. }
  78. </style>
  79. <script type="text/babel">
  80. import {
  81. getAddressList,
  82. getAddressRemove,
  83. getAddressDefaultSet,
  84. postAddress
  85. } from "@/api/user";
  86. import Loading from "@/components/Loading";
  87. import { isWeixin } from "@/utils";
  88. // import { openAddress } from "@/libs/wechat";
  89. export default {
  90. components: {
  91. Loading
  92. },
  93. data() {
  94. return {
  95. page: 1,
  96. limit: 20,
  97. addressList: [],
  98. loadTitle: "",
  99. loading: false,
  100. loadend: false,
  101. isWechat: isWeixin()
  102. };
  103. },
  104. mounted: function() {
  105. this.AddressList();
  106. },
  107. onReachBottom() {
  108. !this.loading && this.AddressList();
  109. },
  110. onShow: function() {
  111. this.refresh();
  112. },
  113. methods: {
  114. refresh: function() {
  115. this.addressList = [];
  116. this.page = 1;
  117. this.loadend = false;
  118. this.AddressList();
  119. },
  120. /**
  121. * 获取地址列表
  122. *
  123. */
  124. AddressList: function() {
  125. let that = this;
  126. if (that.loading) return; //阻止下次请求(false可以进行请求);
  127. if (that.loadend) return; //阻止结束当前请求(false可以进行请求);
  128. that.loading = true;
  129. getAddressList({ page: that.page, limit: that.limit }).then(res => {
  130. that.loading = false;
  131. //apply();js将一个数组插入另一个数组;
  132. that.addressList.push.apply(that.addressList, res.data);
  133. that.loadend = res.data.length < that.limit; //判断所有数据是否加载完成;
  134. that.page = that.page + 1;
  135. });
  136. },
  137. /**
  138. * 编辑地址
  139. */
  140. editAddress: function(index) {
  141. this.$yrouter.push({
  142. path: "/pages/user/address/AddAddress/index",
  143. query: { id: this.addressList[index].id }
  144. });
  145. },
  146. /**
  147. * 删除地址
  148. */
  149. delAddress: function(index) {
  150. let that = this;
  151. let address = this.addressList[index];
  152. let id = address.id;
  153. getAddressRemove(id).then(function() {
  154. uni.showToast({
  155. title: "删除成功!",
  156. icon:"success",
  157. duration: 2000,
  158. complete: () => {
  159. that.addressList.splice(index, 1);
  160. that.$set(that, "addressList", that.addressList);
  161. }
  162. });
  163. });
  164. },
  165. /**
  166. * 设置默认地址
  167. */
  168. radioChange: function(id) {
  169. getAddressDefaultSet(id).then(res => {
  170. this.refresh();
  171. uni.showToast({ title: res.msg, icon: "none", duration: 2000 });
  172. });
  173. },
  174. /**
  175. * 新增地址
  176. */
  177. addAddress: function() {
  178. this.$yrouter.push({
  179. path: "/pages/user/address/AddAddress/index"
  180. });
  181. },
  182. getAddress() {
  183. // openAddress().then(userInfo => {
  184. // uni.showLoading({ title: "加载中" });
  185. // postAddress({
  186. // real_name: userInfo.userName,
  187. // phone: userInfo.telNumber,
  188. // address: {
  189. // province: userInfo.provinceName,
  190. // city: userInfo.cityName,
  191. // district: userInfo.countryName
  192. // },
  193. // detail: userInfo.detailInfo,
  194. // post_code: userInfo.postalCode,
  195. // wx_export: 1
  196. // })
  197. // .then(() => {
  198. // this.page = 1;
  199. // this.loading = false;
  200. // this.loadend = false;
  201. // this.addressList = [];
  202. // this.AddressList();
  203. // uni.hideLoading();
  204. // uni.showToast({
  205. // title: "添加成功",
  206. // icon: 'success',
  207. // duration: 2000
  208. // });
  209. // })
  210. // .catch(err => {
  211. // uni.hideLoading();
  212. // uni.showToast({
  213. // title: err.msg || err.response.data.msg|| err.response.data.message,
  214. // icon: 'none',
  215. // duration: 2000
  216. // });
  217. // });
  218. // });
  219. }
  220. }
  221. };
  222. </script>