addrlist.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="pages">
  3. <u-navbar
  4. title="收货地址"
  5. :placeholder="true"
  6. @leftClick="leftClick"
  7. :autoBack="true"
  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. console.log('leftClick',e);
  67. },
  68. newAddr(){
  69. uni.$u.route('/center/addrForm', {type: 'add',backUrl:this.backUrl});
  70. },
  71. editAddr(item){
  72. uni.$u.route('/center/addrForm', {type: 'edit',id:item.id});
  73. },
  74. getAddrList(){
  75. this.$u.api.addrList().then(res=>{
  76. this.dataList = res.data.rows;
  77. }).catch(err=>{
  78. console.log('getAddrList',err.data);
  79. })
  80. },
  81. swipeClick(index){
  82. let that = this;
  83. // console.log('swipeClick',this.dataList[index]);
  84. let item = this.dataList[index];
  85. uni.showModal({
  86. title: '温馨提示',
  87. content: '确定要删除吗?',
  88. success: res => {
  89. if (res.confirm) {
  90. that.deleteAddr(item.id);
  91. }
  92. },
  93. complete:()=>{}
  94. })
  95. },
  96. deleteAddr(id){
  97. this.$u.api.delAddr({id:id}).then(res=>{
  98. this.getAddrList()
  99. }).catch(err=>{
  100. console.log('deleteAddr',err.data);
  101. })
  102. },
  103. addrClick(item){
  104. console.log('selectAddr',item);
  105. if(this.fromPage == 'submitorder'){
  106. let pages = getCurrentPages(); //获取所有页面栈实例列表
  107. let nowPage = pages[ pages.length - 1]; //当前页页面实例
  108. let prevPage = pages[ pages.length - 2 ]; //上一页页面实例
  109. prevPage.$vm.fromPage = 'addrlist';
  110. prevPage.$vm.receive.id = item.id; // 修改上一页data里面的content参数值
  111. uni.navigateBack()
  112. }
  113. }
  114. }
  115. }
  116. </script>
  117. <style>
  118. page{
  119. background-color: #F5F5F5;
  120. }
  121. </style>
  122. <style lang="scss" scoped>
  123. .addr{
  124. background-color: #fff;
  125. padding: 30rpx;
  126. margin-bottom: 20rpx;
  127. .info{
  128. margin-left: 30rpx;
  129. }
  130. .up{
  131. margin-bottom: 10rpx;
  132. font-size: 32rpx;
  133. font-weight: 600;
  134. text{margin-right: 20rpx;}
  135. .default{
  136. padding: 5rpx 16rpx;
  137. border-radius: 4rpx;
  138. color: #FF3C3F;
  139. background-color: #FFECEC;
  140. font-size: 22rpx
  141. }
  142. }
  143. .down{
  144. font-size: 26rpx;
  145. color: #999;
  146. }
  147. }
  148. </style>