list.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="app-container">
  3. <view class="list-container">
  4. <block v-for="(item, index) in addressList" :key="index">
  5. <view class="item" @tap="chooseAddress(index)">
  6. <view class="top">
  7. <view class="left">
  8. <view class="name">{{ item.name }}</view>
  9. <view class="phone">{{ item.phone }}</view>
  10. <view class="default" v-if="item.defaultAddr">默认</view>
  11. </view>
  12. <image class="right" src="@/static/icon/edit.png" @tap.stop="toEditAddress(item.userAddressId)">
  13. </image>
  14. </view>
  15. <view class="bottom">{{ item.province }}{{ item.city }}{{ item.area }}{{ item.street
  16. }}{{ item.address }}{{ item.houseNo }}</view>
  17. </view>
  18. </block>
  19. </view>
  20. <no-data v-if="!addressList.length" :showText="'暂无收货地址'"></no-data>
  21. <view class="bottom-container">
  22. <view class="button red" @tap="toAddAddress">新增收货地址</view>
  23. <view class="button white" @tap="getWxAddress">获取收货地址</view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. mapState
  30. } from 'vuex';
  31. import EventBus from '@/utils/eventbus.js';
  32. export default {
  33. data() {
  34. return {
  35. addressList: [], // 收货地址列表
  36. isChoose: false, // 是否进来选择地址
  37. };
  38. },
  39. computed: {
  40. ...mapState(['userInfo', 'isLogin', 'userId']),
  41. },
  42. onShow() {
  43. this.getAddressList();
  44. },
  45. onLoad({
  46. isChoose
  47. }) {
  48. this.isChoose = isChoose;
  49. },
  50. methods: {
  51. // 获取收货地址列表
  52. getAddressList() {
  53. this.$axios({
  54. url: '/user/address/list',
  55. method: 'get',
  56. params: {
  57. pageNum: 1,
  58. pageSize: 100,
  59. userId: this.userId,
  60. },
  61. }).then((res) => {
  62. this.addressList = res.data.records;
  63. });
  64. },
  65. // 选择地址
  66. chooseAddress(index) {
  67. if (!this.isChoose) {
  68. return false;
  69. }
  70. EventBus.$emit('chooseAddress', this.addressList[index]);
  71. uni.navigateBack({
  72. delta: 1,
  73. });
  74. },
  75. // 获取微信收货地址
  76. getWxAddress() {
  77. let that = this;
  78. uni.chooseAddress({
  79. success(res) {
  80. let params = {
  81. userId: that.userId,
  82. name: res.userName,
  83. phone: res.telNumber,
  84. province: res.provinceName,
  85. city: res.cityName,
  86. area: res.countyName,
  87. address: res.detailInfo,
  88. houseNo: '',
  89. };
  90. uni.navigateTo({
  91. url: '/pages/mine/address/form?addressData=' + JSON.stringify(params),
  92. });
  93. // that.$axios({
  94. // url: '/user/address/save',
  95. // type: 'application/json',
  96. // params,
  97. // isLoading: 1,
  98. // }).then(res => {
  99. // that.getAddressList();
  100. // that.$successToast('添加成功');
  101. // })
  102. },
  103. });
  104. },
  105. // 去新增收货地址
  106. toAddAddress() {
  107. uni.navigateTo({
  108. url: '/pages/mine/address/form',
  109. });
  110. },
  111. // 去编辑收货地址
  112. toEditAddress(id) {
  113. uni.navigateTo({
  114. url: '/pages/mine/address/form?id=' + id,
  115. });
  116. },
  117. },
  118. };
  119. </script>
  120. <style lang="scss">
  121. .app-container {
  122. background: #f4f2f2;
  123. padding: 20rpx;
  124. padding-bottom: 250rpx;
  125. box-sizing: border-box;
  126. }
  127. .list-container {
  128. .item {
  129. background: #ffffff;
  130. border-radius: 20rpx;
  131. margin-bottom: 20rpx;
  132. padding: 20rpx;
  133. .top {
  134. display: flex;
  135. justify-content: space-between;
  136. align-items: center;
  137. .left {
  138. display: flex;
  139. align-items: flex-end;
  140. .name {
  141. font-size: 32rpx;
  142. color: #333333;
  143. line-height: 32rpx;
  144. }
  145. .phone {
  146. font-size: 28rpx;
  147. color: #666666;
  148. margin-left: 20rpx;
  149. line-height: 28rpx;
  150. }
  151. .default {
  152. font-size: 22rpx;
  153. color: #ffffff;
  154. background: #fe781f;
  155. padding: 6rpx 8rpx;
  156. line-height: 20rpx;
  157. margin-left: 20rpx;
  158. }
  159. }
  160. .right {
  161. width: 32rpx;
  162. height: 32rpx;
  163. }
  164. }
  165. .bottom {
  166. font-size: 28rpx;
  167. color: #333333;
  168. line-height: 38rpx;
  169. margin-top: 20rpx;
  170. }
  171. }
  172. }
  173. .bottom-container {
  174. position: fixed;
  175. bottom: 0;
  176. left: 0;
  177. width: 100%;
  178. box-sizing: border-box;
  179. padding: 20rpx 20rpx 60rpx;
  180. background: #f4f2f2;
  181. .button {
  182. width: 100%;
  183. height: 72rpx;
  184. border-radius: 72rpx;
  185. text-align: center;
  186. line-height: 72rpx;
  187. &.red {
  188. background: #ff3f42;
  189. color: #ffffff;
  190. margin-bottom: 20rpx;
  191. }
  192. &.white {
  193. background: #ffffff;
  194. color: #333333;
  195. }
  196. }
  197. }
  198. </style>