address.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view class="content" :class="['qn-page-' + theme]">
  3. <!-- 空白页 -->
  4. <Aempty text="您还没有收货地址哦~~" src="https://onlineimg.qianniao.vip/address.png" v-if="addressList.length === 0"></Aempty>
  5. <!-- #ifdef MP-WEIXIN -->
  6. <!-- <view class="get-WX-Address clearfix" @click="chooseWxAddress">
  7. <text class="ibonfont ibonweixin"></text>
  8. <text>获取微信收货地址</text>
  9. <text class="ibonfont ibonjinru float_right"></text>
  10. </view> -->
  11. <!-- #endif -->
  12. <view @scrolltolower="lower" v-for="(item, index) in addressList" :key="index" class="address-item">
  13. <view class="list-item-in clearfix" @click="checkAddress(item)">
  14. <view class="wrapper float_left">
  15. <view class="u-box">
  16. <text>收货人:</text>
  17. <text class="name">{{ item.name }}</text>
  18. <text class="mobile">{{ item.mobile }}</text>
  19. </view>
  20. <view class="address-box ">
  21. <text class="address">收货地址:{{ item.area.provinceName }}{{ item.area.cityName }}{{ item.area.districtName }}{{ item.address }}</text>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="ad-bottom-view clearfix">
  26. <view class="float_left" @click="editAddress(item)">
  27. <text class="icon-del ibonfont" :class="[item.defaultStatus===5?'ibonxuanze1 primary-color':'ibonweixuanze']"></text>
  28. 设为默认
  29. </view>
  30. <view class="float_right">
  31. <view style="margin-right: 40rpx;display: inline-block" @click="addAddress(item.id)">
  32. <text class="ibonfont ibonbianji icon-del"></text>
  33. 编辑
  34. </view>
  35. <view @click="delData(item.id)" style="display: inline-block">
  36. <text class="ibonfont ibonshanchu icon-del"></text>
  37. 删除
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <u-loadmore margin-top="20" v-if="addressList.length" :status="loading_status" />
  43. <button class="add-btn primary-bg" @click="addAddress('add')">新增地址</button>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. pageTotal: 0,
  51. pageSize: 10,
  52. page: 1,
  53. loading_status: 'loadmore',
  54. source: 0,
  55. isLoding: false,
  56. addressList: [],
  57. options: [
  58. {
  59. text: '删除',
  60. style: {
  61. backgroundColor: 'rgb(255,58,49)'
  62. }
  63. }
  64. ]
  65. };
  66. },
  67. onLoad(option) {
  68. this.source = option.source;
  69. },
  70. onShow() {
  71. this.getAllShippingAddress();
  72. },
  73. onPullDownRefresh() {
  74. if (this.pageTotal / this.pageSize > this.page) {
  75. this.page += 1;
  76. this.getAllShippingAddress();
  77. }
  78. },
  79. methods: {
  80. chooseWxAddress() {
  81. uni.chooseAddress({
  82. success(res) {
  83. console.log(res);
  84. }
  85. });
  86. },
  87. // 设为默认
  88. editAddress(item) {
  89. this.$u.api
  90. .updateShippingAddress(item.id, {
  91. name: item.name,
  92. mobile: item.mobile,
  93. provinceCode: item.provinceCode,
  94. cityCode: item.cityCode,
  95. districtCode: item.districtCode,
  96. address: item.address,
  97. defaultStatus: 5
  98. })
  99. .then(res => {
  100. this.getAllShippingAddress();
  101. });
  102. },
  103. // 点击按钮
  104. delData(id) {
  105. uni.showModal({
  106. title: '提示',
  107. content: '你确定删除地址',
  108. success: () => {
  109. this.$u.api.deleteShippingAddress(id).then(res => {
  110. uni.showToast({
  111. title: '删除成功',
  112. icon: 'none'
  113. });
  114. this.getAllShippingAddress();
  115. });
  116. }
  117. });
  118. },
  119. //选择地址
  120. checkAddress(item) {
  121. if (parseInt(this.source) === 1) {
  122. this.$api.prePage().addressData = item;
  123. uni.navigateBack();
  124. }
  125. },
  126. addAddress(type, item) {
  127. uni.navigateTo({
  128. url: `/pagesT/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
  129. });
  130. },
  131. // 获取客户地址列表 getAllShippingAddress
  132. getAllShippingAddress() {
  133. this.loading_status = 'loading';
  134. this.$u.api
  135. .getAllShippingAddress({
  136. page: this.page,
  137. pageSize: 10
  138. })
  139. .then(data => {
  140. uni.stopPullDownRefresh();
  141. if (this.page === 1) {
  142. this.addressList = data.data;
  143. } else {
  144. this.addressList = this.addressList.concat(data.data);
  145. }
  146. const address = data.data.find(item => item.defaultStatus === 5) || this.addressList[0];
  147. const addressData = {
  148. provinceCode: address.provinceCode,
  149. cityCode: address.cityCode,
  150. districtCode: address.districtCode,
  151. provinceName: address.area.provinceName,
  152. cityName: address.area.cityName,
  153. districtName: address.area.districtName
  154. };
  155. this.$store.commit('commit_nowAddress', addressData);
  156. this.pageTotal = data.pageTotal;
  157. this.loading_status = this.$_utils.loadStatus(this.page, this.pageSize, this.pageTotal);
  158. });
  159. }
  160. }
  161. };
  162. </script>
  163. <style lang="scss">
  164. page {
  165. padding-bottom: 120upx;
  166. background: #fafafa;
  167. }
  168. .content {
  169. position: relative;
  170. }
  171. .no-select {
  172. display: inline-block;
  173. width: 34upx;
  174. height: 34upx;
  175. border-radius: 100%;
  176. border: 1px solid #999;
  177. }
  178. .list {
  179. display: flex;
  180. align-items: center;
  181. background: #fff;
  182. position: relative;
  183. }
  184. .address-box {
  185. font-size: 26upx;
  186. color: #666;
  187. font-weight: 300;
  188. }
  189. .u-box {
  190. font-size: 28upx;
  191. color: $font-color-dark;
  192. padding-bottom: 10upx;
  193. .name {
  194. margin-right: 30upx;
  195. }
  196. }
  197. .address-item {
  198. width: 702upx;
  199. margin: 20upx auto;
  200. background: #ffffff;
  201. padding: 28upx 24upx;
  202. border-radius: 8upx;
  203. box-shadow: 0px 0px 20upx 0px #eee;
  204. /*margin-bottom: 20upx;*/
  205. .ad-bottom-view {
  206. font-size: 24upx;
  207. font-weight: 300;
  208. padding-top: 20upx;
  209. .icon-del {
  210. width: 26upx;
  211. height: 26upx;
  212. font-size: 26upx;
  213. line-height: 26upx;
  214. margin-right: 10upx;
  215. transform: translateY(4upx);
  216. }
  217. .ibonfont{
  218. font-size: 28rpx;
  219. }
  220. }
  221. .list-item-in {
  222. padding-bottom: 20upx;
  223. border-bottom: 1upx solid #f5f5f5;
  224. }
  225. }
  226. .icon-bianji {
  227. display: flex;
  228. align-items: center;
  229. height: 80upx;
  230. font-size: 40upx;
  231. color: $font-color-light;
  232. padding-left: 30upx;
  233. }
  234. .add-btn {
  235. position: fixed;
  236. left: 30upx;
  237. right: 30upx;
  238. bottom: 16upx;
  239. z-index: 95;
  240. display: flex;
  241. align-items: center;
  242. justify-content: center;
  243. width: 690upx;
  244. height: 80upx;
  245. font-size: 32upx;
  246. color: #fff;
  247. // background: $base-btn-bg;
  248. // box-shadow: 0px 2upx 14upx 0px rgba(116, 190, 66, 0.4);
  249. border-radius: 10upx;
  250. }
  251. .add-btn:after {
  252. border: 0 none;
  253. }
  254. .get-WX-Address {
  255. line-height: 88upx;
  256. height: 88upx;
  257. width: 702upx;
  258. box-shadow: 0px 0px 20rpx 0px #eee;
  259. margin: 20upx auto 0;
  260. background-color: #ffffff;
  261. padding: 0 24rpx;
  262. border-radius: 8upx;
  263. .ibonweixin {
  264. font-size: 40upx;
  265. color: #04be02;
  266. margin-right: 10upx;
  267. }
  268. .ibonjinru {
  269. color: #999;
  270. font-size: 26upx;
  271. }
  272. }
  273. </style>