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.

168 lines
3.8 KiB

3 years ago
  1. <template>
  2. <view class="app">
  3. <view class="main-wrap" :class="{show: loaded}">
  4. <view class="item column" v-for="(item, index) in list" :key="index" @click="chooseAddress(item)">
  5. <view class="row">
  6. <text class="name">{{ item.name }}</text>
  7. <text class="mobile">{{ item.mobile }}</text>
  8. <text v-if="item.is_default" class="tag">默认</text>
  9. </view>
  10. <text class="content">{{ item.address.address }} {{ item.address.room }}</text>
  11. <view class="bot row b-t" @click.stop.prevent="stopPrevent">
  12. <view class="btn center" @click="showDelModal(index)">
  13. <text class="mix-icon icon-lajitong"></text>
  14. <text>删除</text>
  15. </view>
  16. <view class="btn center" @click="editAddr(item)">
  17. <text class="mix-icon icon-bianji"></text>
  18. <text>编辑</text>
  19. </view>
  20. </view>
  21. </view>
  22. <view v-if="list.length > 0" class="bot-btn-wrap fix-bot">
  23. <mix-button text="新增收货地址" icon="icon-jia2" :iconSize="36" :isConfirm="false" @onConfirm="navTo('manage')"></mix-button>
  24. </view>
  25. </view>
  26. <mix-modal ref="mixModal" title="提示" text="确定要删除该地址吗" @onConfirm="deleteAddr"></mix-modal>
  27. <mix-loading v-if="isLoading" :type="list.length > 0 ? 1 : 2"></mix-loading>
  28. <!-- 缺省 -->
  29. <mix-empty v-else-if="loaded && list.length === 0" type="address" backgroundColor="#fff"></mix-empty>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. data() {
  35. return {
  36. list: []
  37. }
  38. },
  39. onLoad(options) {
  40. this.isChoose = !!options.choose;
  41. this.choosedId = options.id;
  42. this.loadData();
  43. },
  44. methods: {
  45. async loadData(){
  46. const res = await this.$request('address', 'get', {}, {
  47. showLoading: !this.loaded
  48. });
  49. this.list = res.data;
  50. },
  51. //选择地址
  52. chooseAddress(item){
  53. if(!this.isChoose){
  54. return;
  55. }
  56. this.$util.prePage().setAddress(item);
  57. uni.navigateBack();
  58. },
  59. /**
  60. * 删除地址
  61. * 注意 删除成功已选择的地址需要清空
  62. */
  63. async deleteAddr(){
  64. const res = await this.$request('address', 'remove', {
  65. id: this.list[this.curIndex]._id
  66. }, {
  67. showLoading: true
  68. })
  69. this.$util.msg(res.msg);
  70. if(res.status === 1){
  71. this.list.splice(this.curIndex, 1);
  72. this.isChoose && this.choosedId && this.$util.prePage().setAddress({});
  73. }
  74. },
  75. //编辑地址
  76. editAddr(item){
  77. this.navTo(`manage?data=${JSON.stringify(item)}`);
  78. },
  79. showDelModal(index){
  80. this.curIndex = index;
  81. this.$refs.mixModal.open();
  82. }
  83. }
  84. }
  85. </script>
  86. <style>
  87. page{
  88. background-color: #f7f7f7;
  89. }
  90. </style>
  91. <style scoped lang="scss">
  92. .app{
  93. padding-top: 20rpx;
  94. }
  95. .main-wrap{
  96. opacity: 0;
  97. transition: opacity .2s;
  98. &.show{
  99. opacity: 1;
  100. }
  101. }
  102. .item{
  103. padding: 30rpx 28rpx 0;
  104. margin: 0 20rpx 20rpx;
  105. background-color: #fff;
  106. border-radius: 12rpx;
  107. box-shadow: 0rpx 0rpx 20rpx rgba(0,0,0,.03);
  108. .name{
  109. margin-right: 28rpx;
  110. font-size: 32rpx;
  111. color: #333;
  112. }
  113. .mobile{
  114. margin-right: 32rpx;
  115. font-size: 28rpx;
  116. color: #999;
  117. }
  118. .tag{
  119. padding: 0 8rpx;
  120. font-size: 20rpx;
  121. color: #fff;
  122. line-height: 28rpx;
  123. background-color: $base-color;
  124. border-radius: 2rpx;
  125. }
  126. .content{
  127. width: 560rpx;
  128. min-height: 70rpx;
  129. margin: 28rpx 0 20rpx;
  130. font-size: 28rpx;
  131. color: #999;
  132. line-height: 1.44;
  133. }
  134. .bot{
  135. justify-content: flex-end;
  136. height: 79rpx;
  137. &:before{
  138. left: -26rpx;
  139. right: -26rpx;
  140. border-color: #f0f0f0;
  141. }
  142. }
  143. .btn{
  144. margin-left: 50rpx;
  145. font-size: 26rpx;
  146. color: #444;
  147. .mix-icon{
  148. margin-right: 16rpx;
  149. font-size: 34rpx;
  150. }
  151. }
  152. }
  153. .bot-btn-wrap{
  154. position: fixed;
  155. left: 0;
  156. bottom: 30rpx;
  157. z-index: 90;
  158. width: 100%;
  159. }
  160. </style>