addressManagement.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view>
  3. <view class="top-tab">
  4. <view :class="{ select: manage == 1 }" @click="switchTab(1)">
  5. {{ i18n.inland }}
  6. </view>
  7. <view :class="{ select: manage == 0 }" @click="switchTab(0)">
  8. {{ i18n.international }}
  9. </view>
  10. </view>
  11. <view class="content" v-if="addressList.length != 0">
  12. <addressVue @deleteAddress="deleteAddress" @setDefault="setDefault" @toDetail="toDetail"
  13. @goBack="goBack(item)" v-for="item in addressList" :itemInfo="item" :key="item.id" />
  14. </view>
  15. <view class="empty" v-else> 空空如也~ </view>
  16. <view class="footer" v-if="manage == 1">
  17. <!-- <button class="wx">{{ i18n.wx }}</button> -->
  18. <button class="add-international" @click="toAddRess('/pageC/addEditAddress/addEditAddress?ifadd=1')">
  19. {{ i18n.add }}
  20. </button>
  21. </view>
  22. <view class="footer" v-else>
  23. <button class="add-international" @click="toAddRess('/pageC/internationalAddress/internationalAddress?')">
  24. {{ i18n.add }}
  25. </button>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import addressVue from "./component/address.vue";
  31. export default {
  32. components: {
  33. addressVue,
  34. },
  35. data() {
  36. return {
  37. manage: 1,
  38. addressList: [],
  39. type: "", //判断在哪个页面进来
  40. };
  41. },
  42. onLoad(options) {
  43. console.log(options);
  44. if (options.tabs) {
  45. this.manage = options.tabs;
  46. }
  47. this.type = options.type;
  48. },
  49. computed: {
  50. i18n() {
  51. return this.$t("index");
  52. },
  53. },
  54. methods: {
  55. goBack(item) {
  56. //从账号设置进入该页面,则不允许返回上一页面
  57. if (this.type == "setup") return;
  58. const eventChannel = this.getOpenerEventChannel();
  59. eventChannel.emit("getadd", item);
  60. uni.$emit("isRefresh", this.index);
  61. uni.navigateBack({
  62. delta: 1,
  63. });
  64. },
  65. switchTab(num) {
  66. this.manage = num;
  67. this.getAddressList(num);
  68. },
  69. //设置默认地址
  70. setDefault(value) {
  71. uni.$u.http
  72. .post(`/api/address/default/${value.id}`)
  73. .then((res) => {
  74. this.getAddressList(this.manage);
  75. })
  76. .catch(() => {});
  77. },
  78. //跳转地址详情页
  79. toDetail(id) {
  80. if (this.manage) {
  81. uni.navigateTo({
  82. url: `/pageC/addEditAddress/addEditAddress?id=${id}`,
  83. });
  84. } else {
  85. uni.navigateTo({
  86. url: `/pageC/internationalAddress/internationalAddress?id=${id}`,
  87. });
  88. }
  89. },
  90. //删除地址
  91. deleteAddress(value) {
  92. uni.$u.http.delete(`/api/address/${value.id}`).then((res) => {
  93. this.getAddressList(this.manage);
  94. });
  95. },
  96. toAddRess(url) {
  97. uni.navigateTo({
  98. url,
  99. });
  100. },
  101. getAddressList(num) {
  102. uni.$u.http
  103. .get(
  104. `/api/address?is_page=0&page=1&limit=10&is_domestic=${num}&is_default=`
  105. )
  106. .then((res) => {
  107. this.addressList = res;
  108. });
  109. },
  110. },
  111. onShow() {
  112. // this.getAddressList(this.manage);
  113. },
  114. mounted() {
  115. this.getAddressList(this.manage);
  116. // this.getAddressList(1);
  117. uni.setNavigationBarTitle({
  118. title: this.i18n.address,
  119. });
  120. },
  121. };
  122. </script>
  123. <style scoped lang="scss">
  124. .top-tab {
  125. display: flex;
  126. font-size: 32rpx;
  127. color: rgba(34, 34, 34, 0.8);
  128. justify-content: space-around;
  129. background-color: #fff;
  130. height: 80rpx;
  131. align-items: center;
  132. .select {
  133. position: relative;
  134. font-weight: 600;
  135. }
  136. .select::before {
  137. content: "";
  138. display: block;
  139. width: 50%;
  140. height: 4rpx;
  141. background-color: #f83224;
  142. position: absolute;
  143. bottom: -20rpx;
  144. left: 50%;
  145. transform: translate(-50%, -50%);
  146. }
  147. }
  148. .content {
  149. padding: 20rpx 24rpx;
  150. padding-bottom: 200rpx;
  151. }
  152. .empty {
  153. font-size: 28rpx;
  154. display: flex;
  155. justify-content: center;
  156. align-items: center;
  157. color: rgba(51, 51, 51, 0.7);
  158. margin-top: 200rpx;
  159. }
  160. .footer {
  161. position: fixed;
  162. bottom: 0;
  163. background-color: #fff;
  164. display: flex;
  165. justify-content: space-around;
  166. width: 750rpx;
  167. padding: 20rpx 0 66rpx;
  168. .wx {
  169. width: 338rpx;
  170. background-color: #fff;
  171. border-radius: 40rpx;
  172. height: 80rpx;
  173. font-size: 32rpx;
  174. color: #222;
  175. padding: 0;
  176. margin: 0;
  177. border: 2rpx solid #979797;
  178. }
  179. .add {
  180. width: 338rpx;
  181. background-color: #f83224;
  182. border-radius: 40rpx;
  183. height: 80rpx;
  184. font-size: 32rpx;
  185. color: #fff;
  186. padding: 0;
  187. margin: 0;
  188. }
  189. .add-international {
  190. width: 702rpx;
  191. background-color: #f83224;
  192. border-radius: 40rpx;
  193. height: 80rpx;
  194. font-size: 32rpx;
  195. color: #fff;
  196. margin: 0 auto;
  197. }
  198. }
  199. </style>