index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="addressList">
  3. <!-- header -->
  4. <cu-custom isBack bgColor="bg-gradual-blue"><view slot="content">地址列表</view></cu-custom>
  5. <!-- section -->
  6. <cu-scrollView :height="height" @refresherpulling="refresherpulling" @scroll="scroll">
  7. <radio-group @change="radioChange">
  8. <view v-for="(item, index) in ListValue" :key="index" class="item bg-white margin padding radius flex align-center">
  9. <view class="margin-right-sm"><radio style="transform: scale(0.6);" class="radio" :value="item.id" :checked="item.default" /></view>
  10. <view style="flex: auto;">
  11. <view class="flex align-center text-xl">
  12. <text class="margin-right-sm text-black">{{ item.name }}</text>
  13. <text class="margin-right-sm text-black">{{ item.tel }}</text>
  14. <text v-if="item.default" class="cu-tag text-white round sm" style="background-color:#ee0a24;">默认</text>
  15. </view>
  16. <view class="a">{{ item.province }}{{ item.city }}{{ item.area }}{{ item.address }}</view>
  17. </view>
  18. <view class="margin-left-sm flex flex-direction align-center justify-center">
  19. <text @click="update(item)" class="cuIcon-writefill text-xxl text-green"></text>
  20. <text @click="deleteItem(item)" class="cuIcon-deletefill margin-top text-red text-xxl "></text>
  21. </view>
  22. </view>
  23. </radio-group>
  24. <!-- 状态管理 -->
  25. <view class="cu-load" :class="{ loading: currentPage <= totalPage, over: currentPage > totalPage }"></view>
  26. </cu-scrollView>
  27. <!-- footer -->
  28. <view class="footer">
  29. <view class="footer-content padding bg-white"><button @click="handler" class="cu-btn block">新增地址</button></view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import { mapState, mapActions } from 'vuex';
  35. import { CustomBarHeight } from '@/common/device/index.js';
  36. import api from './api.js';
  37. export default {
  38. computed: {
  39. ...mapState('requestList', ['ListValue', 'currentPage', 'totalPage']),
  40. height() {
  41. return `calc(100vh - 140rpx + env(safe-area-inset-bottom) / 2 - ${CustomBarHeight}px)`;
  42. }
  43. },
  44. data() {
  45. return {};
  46. },
  47. async onShow() {
  48. await this.reset();
  49. await this.requestFunc({ method: 'get', url: `/customer/address/`, data: { limit: 10 } });
  50. },
  51. methods: {
  52. ...mapActions('requestList', ['reset', 'requestFunc']),
  53. // 新增地址
  54. handler() {
  55. uni.navigateTo({
  56. url: '/loginPages/addaddress/index'
  57. });
  58. },
  59. // 下拉刷新
  60. async refresherpulling() {
  61. await this.reset();
  62. await this.requestFunc({ method: 'get', url: `/customer/address/`, data: { limit: 10 } });
  63. },
  64. // 上拉加载
  65. async scroll() {
  66. await this.requestFunc({ method: 'get', url: `/customer/address/`, data: { limit: 10 } });
  67. },
  68. // 修改默认
  69. async radioChange(e) {
  70. var { value } = e.detail;
  71. var result = await api.isDefault(value);
  72. if (result.code == 0) {
  73. await this.reset();
  74. await this.requestFunc({ method: 'get', url: `/customer/address/`, data: { limit: 10 } });
  75. }
  76. },
  77. // 修改
  78. update(item) {
  79. let { province, city, default: checked, address, area, ...keys } = item;
  80. let object = {
  81. ...keys,
  82. region: [province, city, area],
  83. checked,
  84. textarea: address
  85. };
  86. uni.navigateTo({
  87. url: `/loginPages/addaddress/index?data=${JSON.stringify(object)}`
  88. });
  89. },
  90. // 删除
  91. async deleteItem(item) {
  92. var result = await api.deleteItem(item.id);
  93. if (result.code == 0) {
  94. await this.reset();
  95. await this.requestFunc({ method: 'get', url: `/customer/address/`, data: { limit: 10 } });
  96. }
  97. }
  98. }
  99. };
  100. </script>
  101. <style lang="scss" scoped>
  102. .addressList {
  103. .section {
  104. .item {
  105. width: calc(100vw - 60upx);
  106. box-sizing: border-box;
  107. }
  108. }
  109. .footer {
  110. height: calc(140rpx + env(safe-area-inset-bottom) / 2);
  111. padding-bottom: calc(env(safe-area-inset-bottom) / 2);
  112. .footer-content {
  113. position: fixed;
  114. bottom: 0;
  115. left: 0;
  116. width: 100%;
  117. button {
  118. background-color: #ee0a24;
  119. color: #fff;
  120. height: 80upx;
  121. border-radius: 80upx;
  122. }
  123. }
  124. }
  125. }
  126. </style>