addrlist.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view class="pages">
  3. <u-navbar
  4. title="收货地址"
  5. :placeholder="true"
  6. @leftClick="leftClick"
  7. :autoBack="false"
  8. :safeAreaInsetTop="true"
  9. >
  10. </u-navbar>
  11. <view class="page-wrap">
  12. <view class="full-btn" @click="newAddr">新增收货地址</view>
  13. <view v-if="dataList.length>0" class="addr" @click="addrClick(item)" v-for="(item,index) in dataList" :key="item.id">
  14. <u-swipe-action>
  15. <u-swipe-action-item :show="item.show" :index="index" @click.stop="swipeClick(index)" :options="options">
  16. <view class="u-flex">
  17. <view class="icon-wrap" v-if="item.ifDefault==1">
  18. <u-icon size="36rpx" :name="staticUrl+'/img/arrows.png'"></u-icon>
  19. </view>
  20. <view class="info u-flex-1">
  21. <view class="up">
  22. <text>{{item.receiveName}}</text>
  23. <text>{{item.receivePhone}}</text>
  24. <text class="default" v-if="item.ifDefault==1">默认</text>
  25. </view>
  26. <view class="down">{{item.receiveAdress}}{{item.address}}</view>
  27. </view>
  28. <u-icon name="edit-pen" color="#333" size="20" @click.native.stop="editAddr(item)"></u-icon>
  29. </view>
  30. </u-swipe-action-item>
  31. </u-swipe-action>
  32. </view>
  33. <u-empty v-else mode="list"></u-empty>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. staticUrl:this.$commonConfig.staticUrl,
  42. dataList:[],
  43. options:[
  44. {
  45. text: '删除',
  46. style: {
  47. backgroundColor: '#FF3C3F',
  48. 'padding-left':'10px'
  49. }
  50. }
  51. ],
  52. fromPage:'',
  53. backUrl:'',
  54. }
  55. },
  56. onShow() {
  57. this.getAddrList();
  58. },
  59. onLoad(page) {
  60. console.log('page',page);
  61. this.fromPage = page.from;
  62. this.backUrl = page.backUrl;
  63. },
  64. methods: {
  65. leftClick(e){
  66. let pages = getCurrentPages();
  67. if(pages.length==1){
  68. uni.$u.route('/pages/index/index')
  69. }else{
  70. uni.navigateBack()
  71. };
  72. },
  73. newAddr(){
  74. uni.$u.route('/center/addrForm', {type: 'add',backUrl:this.backUrl});
  75. },
  76. editAddr(item){
  77. uni.$u.route('/center/addrForm', {type: 'edit',id:item.id});
  78. },
  79. getAddrList(){
  80. this.$u.api.addrList().then(res=>{
  81. this.dataList = res.data.rows;
  82. }).catch(err=>{
  83. console.log('getAddrList',err.data);
  84. })
  85. },
  86. swipeClick(index){
  87. let that = this;
  88. // console.log('swipeClick',this.dataList[index]);
  89. let item = this.dataList[index];
  90. uni.showModal({
  91. title: '温馨提示',
  92. content: '确定要删除吗?',
  93. success: res => {
  94. if (res.confirm) {
  95. that.deleteAddr(item.id);
  96. }
  97. },
  98. complete:()=>{}
  99. })
  100. },
  101. deleteAddr(id){
  102. this.$u.api.delAddr({id:id}).then(res=>{
  103. this.getAddrList()
  104. }).catch(err=>{
  105. console.log('deleteAddr',err.data);
  106. })
  107. },
  108. addrClick(item){
  109. console.log('selectAddr',item);
  110. if(this.fromPage == 'submitorder'){
  111. let pages = getCurrentPages(); //获取所有页面栈实例列表
  112. let nowPage = pages[ pages.length - 1]; //当前页页面实例
  113. let prevPage = pages[ pages.length - 2 ]; //上一页页面实例
  114. prevPage.$vm.fromPage = 'addrlist';
  115. prevPage.$vm.receive.id = item.id; // 修改上一页data里面的content参数值
  116. uni.navigateBack()
  117. }
  118. }
  119. }
  120. }
  121. </script>
  122. <style>
  123. page{
  124. background-color: #F5F5F5;
  125. }
  126. </style>
  127. <style lang="scss" scoped>
  128. .addr{
  129. background-color: #fff;
  130. padding: 30rpx;
  131. margin-bottom: 20rpx;
  132. .info{
  133. margin-left: 30rpx;
  134. }
  135. .up{
  136. margin-bottom: 10rpx;
  137. font-size: 32rpx;
  138. font-weight: 600;
  139. text{margin-right: 20rpx;}
  140. .default{
  141. padding: 5rpx 16rpx;
  142. border-radius: 4rpx;
  143. color: #FF3C3F;
  144. background-color: #FFECEC;
  145. font-size: 22rpx
  146. }
  147. }
  148. .down{
  149. font-size: 26rpx;
  150. color: #999;
  151. }
  152. }
  153. </style>