address-manage.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="container">
  3. <Navbar title="收货地址" background-color="#ffffff" color="#333333"></Navbar>
  4. <view class="list">
  5. <NoData :show="!isLoad && !addressList.length" topNum="10"></NoData>
  6. <view v-for="(item, i) in addressList" :key="i" class="address-wrap" @click="selectAddress(item)">
  7. <view class="top">
  8. <text class="name">{{ item.name }}</text>
  9. <text class="phone">{{ item.phone | phoneStatus }}</text>
  10. </view>
  11. <text class="detail">
  12. {{item.province_str + item.city_str + item.county_str}}{{item.address}}
  13. </text>
  14. <view class="bottom">
  15. <view class="default" @click.stop="setDefault(item.id)">
  16. <!-- <text :class="{ 'icon-red': item.is_default, 'icon-gray': !item.is_default }">
  17. &#xe645;
  18. </text> -->
  19. <view class="default-icon-box">
  20. <IconText class="default-icon" :color="item.isDefault === 1 ? '#D3325C' : '#D4D4D4'"
  21. :code="`\ue73f`" size="14"></IconText>
  22. </view>
  23. <text class="word12">默认地址</text>
  24. </view>
  25. <view class="edit-wrap">
  26. <view @click.stop="editAddress(item.id)">
  27. <IconText :code="`\ue758`" size="12" color="#666"></IconText>
  28. <text class="word12">编辑</text>
  29. </view>
  30. <view @click.stop="delAddress(item.id)">
  31. <IconText :code="`\ue740`" size="12" color="#666"></IconText>
  32. <text class="word12">删除</text>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="fixed-bottom" @click="createAddress">
  39. <view class="solid-btn">+ 添加新地址</view>
  40. </view>
  41. </view>
  42. </template>
  43. <script lang="ts">
  44. import {
  45. Component,
  46. Prop,
  47. Vue
  48. } from 'vue-property-decorator';
  49. import {
  50. namespace
  51. } from 'vuex-class';
  52. import {
  53. types
  54. } from '@/common/store';
  55. const baseModule = namespace('base');
  56. @Component({
  57. filters: {
  58. phoneStatus(val: string): string {
  59. val = val + '';
  60. if (!val) return '';
  61. return val.substring(0, 3) + '****' + val.substring(7);
  62. }
  63. }
  64. })
  65. export default class Address extends Vue {
  66. @baseModule.Mutation(types.SET_ADDRESS) setAddress: any
  67. addressList: any[] = [];
  68. isLoad: boolean = false;
  69. // img: string = this.$oss_url + 'zwdd.png';
  70. onShow() {
  71. this.getList();
  72. }
  73. getList() {
  74. uni.showLoading({
  75. title: '加载中',
  76. });
  77. this.isLoad = true;
  78. this.$http
  79. .get({
  80. url: this.$api.addressList,
  81. data: {}
  82. })
  83. .then((res: any) => {
  84. this.addressList = res.list;
  85. this.isLoad = false;
  86. uni.hideLoading();
  87. }, (err: any) => {
  88. this.isLoad = false;
  89. uni.hideLoading();
  90. });
  91. }
  92. delAddress(id: number): void {
  93. let that = this;
  94. uni.showModal({
  95. title: '请再次确认',
  96. content: '确认删除该地址吗?',
  97. cancelText: '再看看',
  98. success: function(res) {
  99. if (res.confirm) {
  100. // 设置默认
  101. that.$http
  102. .delete({
  103. url: that.$api.deleteAddress,
  104. data: {
  105. id: id
  106. }
  107. })
  108. .then((res: any) => {
  109. uni.showToast({
  110. title: '删除成功!',
  111. icon: 'none'
  112. });
  113. that.getList();
  114. });
  115. } else if (res.cancel) {
  116. console.log('用户点击取消');
  117. }
  118. }
  119. });
  120. }
  121. setDefault(id: number): void {
  122. let that = this;
  123. uni.showModal({
  124. title: '提示',
  125. content: '确认设置该地址为默认地址?',
  126. success: function(res) {
  127. if (res.confirm) {
  128. // 设置默认
  129. that.$http
  130. .put({
  131. url: that.$api.addressDefault,
  132. data: {
  133. id: id
  134. }
  135. })
  136. .then((res: any) => {
  137. uni.showToast({
  138. title: '设置成功!',
  139. icon: 'none'
  140. });
  141. that.getList();
  142. });
  143. } else if (res.cancel) {
  144. console.log('用户点击取消');
  145. }
  146. }
  147. });
  148. }
  149. editAddress(id: any): void {
  150. this.$Router.push({
  151. path: '/packages/order/address-detail',
  152. query: {
  153. id: id
  154. }
  155. });
  156. }
  157. createAddress(): void {
  158. this.$Router.push({
  159. path: '/packages/order/address-detail'
  160. });
  161. }
  162. selectAddress(item: any) {
  163. let query = this.$Route.query;
  164. if (!query.from) return;
  165. this.setAddress(item);
  166. this.$Router.back(1);
  167. }
  168. }
  169. </script>
  170. <style lang="scss">
  171. @mixin word14() {
  172. @include word-vw(14);
  173. }
  174. .container {
  175. background: #F5F5F5;
  176. height: 100vh;
  177. @include flex-y();
  178. .list {
  179. width: 100%;
  180. margin-top: vw(1);
  181. flex: 1;
  182. overflow-y: auto;
  183. padding: 0 vw(10);
  184. box-sizing: border-box;
  185. }
  186. }
  187. .word12 {
  188. @include word-vw(12) margin-left: 5px;
  189. }
  190. .icon-red {
  191. @include icon(15, #FFDE4C);
  192. }
  193. .icon-gray {
  194. @include icon(15, #EFEFEF);
  195. }
  196. .address-wrap {
  197. width: 100%;
  198. display: flex;
  199. flex-wrap: wrap;
  200. align-content: space-between;
  201. padding: $cell-padding;
  202. box-sizing: border-box;
  203. background-color: white;
  204. margin-top: vw(10);
  205. border-radius: vw(5);
  206. .top,
  207. .bottom {
  208. width: 100%;
  209. @include flex-x();
  210. }
  211. .name {
  212. @include word14;
  213. // width: vw(225);
  214. }
  215. .phone {
  216. @include word14;
  217. // width: vw(120);
  218. text-align: right;
  219. }
  220. .detail {
  221. width: 100%;
  222. @include word-vw(12, $gray9);
  223. padding: 12px 0;
  224. border-bottom: 1px solid $line-color;
  225. margin-bottom: 6px;
  226. }
  227. .default {
  228. // width: vw(200);
  229. @include flex-x(flex-start);
  230. .default-icon-box {
  231. @include flex-x(center);
  232. .default-icon {
  233. @include flex-x(center);
  234. }
  235. }
  236. }
  237. .edit-wrap {
  238. @include flex-x(flex-end);
  239. // width: vw(145);
  240. .icon {
  241. @include icon(14, #8a8a8a);
  242. margin-left: 10px;
  243. }
  244. }
  245. }
  246. .fixed-bottom {
  247. height: vw(60);
  248. width: 100%;
  249. background: #fff;
  250. @include flex-x(center);
  251. .solid-btn {
  252. background: $bk-color;
  253. @include solid-btn(335, 48, #333);
  254. border-radius: vw(10);
  255. @include word-vw(14, #fff);
  256. }
  257. }
  258. </style>