addressManagement.vue 4.6 KB

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