address.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <view class="content">
  3. <view class="list" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
  4. <view class="wrapper">
  5. <view class="address-box">
  6. <text class="name">{{ item.real_name }}</text>
  7. <text class="mobile">{{ item.phone }}</text>
  8. </view>
  9. <view class="u-box">
  10. <text class="address">{{ item.province + item.city + item.district }} {{ item.detail }}</text>
  11. </view>
  12. </view>
  13. <view class="buttom">
  14. <view class="default-buttom" @click.stop="defaultUp(item, index)">
  15. <view class="checkbox" :class="{ checked: item.is_default == 1 }"></view>
  16. <text class="text">设为默认地址</text>
  17. </view>
  18. <view class="operation">
  19. <view @click.stop="addAddress('edit', item)">
  20. <text class="iconfont iconedit"></text>
  21. <text class="text">编辑</text>
  22. </view>
  23. <view class="blank"></view>
  24. <view @click.stop="delAddress(item)">
  25. <text class="iconfont icondelete"></text>
  26. <text class="text">删除</text>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="add-btn flex">
  32. <button class="btn" @click="addAddress('add')">新增地址</button>
  33. <!-- #ifdef H5 -->
  34. <!-- <button v-show="isShow" class="btn" @click="getAddress">获取微信地址</button> -->
  35. <!-- #endif -->
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import { getAddressList, addressEdit, addressDel } from '@/api/address.js';
  41. import { mapState } from 'vuex';
  42. import { wechatConfig } from '@/api/wx';
  43. export default {
  44. data() {
  45. return {
  46. source: 0,
  47. addressList: [],
  48. isShow: false
  49. };
  50. },
  51. onLoad(option) {
  52. console.log(option, 1);
  53. this.source = option.source || 0;
  54. this.loadAddress();
  55. },
  56. onShow() {
  57. this.loadAddress();
  58. },
  59. methods: {
  60. //加载数据
  61. loadAddress() {
  62. getAddressList({
  63. page: 1,
  64. limit: 100
  65. }).then(({ data }) => {
  66. console.log(data, 1101);
  67. this.addressList = data;
  68. });
  69. },
  70. defaultUp(data, ind) {
  71. this.addressList = this.addressList.map(e => {
  72. e.is_default = 0;
  73. return e;
  74. });
  75. this.addressList[ind].is_default = 1;
  76. addressEdit({
  77. real_name: data.real_name,
  78. phone: data.phone,
  79. address: {
  80. province: data.province,
  81. city: data.city,
  82. district: data.district
  83. },
  84. detail: data.detail,
  85. is_default: 1,
  86. id: data.id,
  87. type: 1
  88. })
  89. .then(({ data }) => {
  90. this.loadAddress();
  91. })
  92. .catch(e => {
  93. console.log(e);
  94. });
  95. },
  96. //选择地址
  97. checkAddress(item) {
  98. if (this.source == 1) {
  99. //this.$api.prePage()获取上一页实例,在App.vue定义
  100. this.$api.prePage().addressData = item;
  101. this.$api.prePage().address.address = true;
  102. uni.navigateBack();
  103. console.log(121);
  104. } else {
  105. this.$api.prePage().addressData = item;
  106. uni.navigateBack();
  107. console.log(121);
  108. }
  109. },
  110. addAddress(type, item) {
  111. uni.navigateTo({
  112. url: `/pages/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
  113. });
  114. },
  115. delAddress(item) {
  116. uni.showModal({
  117. content: '确认是否删除收货地址',
  118. confirmText: '确认删除',
  119. success: res => {
  120. if (res.confirm) {
  121. addressDel({
  122. id: item.id
  123. }).then(({ data }) => {
  124. this.$api.msg('删除成功');
  125. // this.loadAddress();
  126. });
  127. let s = this.addressList.indexOf(item);
  128. this.addressList.splice(s, 1);
  129. } else if (res.cancel) {
  130. }
  131. }
  132. });
  133. }
  134. }
  135. };
  136. </script>
  137. <style lang="scss">
  138. page {
  139. padding-top: 20rpx;
  140. }
  141. .content {
  142. position: relative;
  143. padding-bottom: 100rpx;
  144. }
  145. .list {
  146. align-items: center;
  147. padding: 20rpx 25rpx;
  148. background: #fff;
  149. margin: 25rpx;
  150. margin-top: 0;
  151. border-radius: 10rpx;
  152. .wrapper {
  153. border-bottom: 1px solid #f0f0f0;
  154. .address-box {
  155. display: flex;
  156. align-items: center;
  157. justify-content: space-between;
  158. .name {
  159. margin-right: 30rpx;
  160. font-size: 30rpx;
  161. font-weight: 500;
  162. color: #1d2023;
  163. }
  164. .mobile {
  165. font-size: 28rpx;
  166. font-weight: 400;
  167. color: #333333;
  168. }
  169. }
  170. .u-box {
  171. margin-bottom: 20rpx;
  172. .address {
  173. font-size: 26rpx;
  174. font-weight: 500;
  175. color: #666666;
  176. text-overflow: -o-ellipsis-lastline;
  177. overflow: hidden;
  178. text-overflow: ellipsis;
  179. display: -webkit-box;
  180. -webkit-line-clamp: 2;
  181. -webkit-box-orient: vertical;
  182. }
  183. }
  184. }
  185. .buttom {
  186. display: flex;
  187. align-items: center;
  188. justify-content: space-between;
  189. padding-top: 10rpx;
  190. .checkbox {
  191. width: 35rpx;
  192. height: 35rpx;
  193. border-radius: 50px;
  194. background-image: url(../../static/img/gou.png) 35rpx;
  195. border: 1px solid #eeeeee;
  196. }
  197. .checkbox.checked {
  198. background: url(../../static/img/gou.png) no-repeat center #f93a3a;
  199. background-size: 70%;
  200. width: 35rpx;
  201. height: 35rpx;
  202. }
  203. .default-buttom {
  204. display: flex;
  205. align-items: center;
  206. }
  207. .operation {
  208. display: flex;
  209. align-items: center;
  210. .blank {
  211. width: 30rpx;
  212. }
  213. }
  214. .text {
  215. padding-left: 10rpx;
  216. font-size: 24rpx;
  217. color: #666666;
  218. }
  219. }
  220. }
  221. .icon-bianji {
  222. display: flex;
  223. align-items: center;
  224. height: 80rpx;
  225. font-size: 40rpx;
  226. color: $font-color-light;
  227. padding-left: 30rpx;
  228. }
  229. .add-btn {
  230. // margin-top: 80rpx;
  231. z-index: 95;
  232. display: flex;
  233. align-items: center;
  234. justify-content: center;
  235. position: fixed;
  236. bottom: 40rpx;
  237. width: 100%;
  238. }
  239. .btn {
  240. width: 40%;
  241. height: 80rpx;
  242. font-size: $font-lg;
  243. color: #fff;
  244. background-color: $base-color;
  245. background: linear-gradient(0deg, rgba(250, 39, 64, 1), rgba(254, 85, 68, 1));
  246. border-radius: 10rpx;
  247. }
  248. </style>