address.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="app">
  3. <view class="app-items">
  4. <view class="item" @tap="clickView(item)" v-for="(item,index) of addList" :key="index">
  5. <view class="fx-r">
  6. <view class="name">{{ item.name }}</view>
  7. <view class="tag" v-if="item.status == 1">默认地址</view>
  8. </view>
  9. <view class="fx-r fx-bc">
  10. <view class="address">{{item.province}}{{item.city}}{{item.area}}{{item.address}}</view>
  11. <view class="edit" @tap="editClick(item.id)"><image src="/static/img/edit.png"></image></view>
  12. </view>
  13. <view class="mobile">{{mobileTap(item.tel)}}</view>
  14. <view class="item-foot fx-r">
  15. <view class="default fx-r fx-bc" @tap="set_default_address(item.id,index)">
  16. <image src="/static/img/radio_buttons_btn.png" v-if="item.status == 1"></image>
  17. <image src="/static/img/radio_buttons.png" v-else></image>
  18. 默认地址
  19. </view>
  20. <view class="fx-g1"></view>
  21. <view class="del" @tap="del_address(item.id,index)">删除</view>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="foot" style="height: 40px;"></view>
  26. <view class="foot-wiget">
  27. <view class="foot-btn fx-r fx-bc fx-ac" @tap="addClick"><image src="/static/nimg/address-add.png"></image>新增地址</view>
  28. </view>
  29. </view>
  30. </template>
  31. <style lang="scss">
  32. .app {
  33. padding: 10px;
  34. .app-items{
  35. .item{
  36. background: #fff;
  37. border-radius: 10px;
  38. padding: 10px 15px;
  39. margin-bottom: 10px;
  40. .name{color: #333;font-size: 16px;font-weight: 600;}
  41. .tag{background: rgba(1, 149, 96, 0.1);font-size: 12px;color: #db292b;padding: 2px 6px;margin-left: 4px;border-radius: 4px;}
  42. .address{width: calc(100% - 20px);color: #333;font-size: 14px;padding: 4px 0;}
  43. .edit{width: 16px;height: 16px;image{width: 100%;height: 100%;}}
  44. .mobile{color: #919191;font-size: 14px;margin: 4px 0;}
  45. .default{
  46. color: #727272;
  47. font-size: 14px;
  48. image{width: 14px;height: 14px;margin-right: 4px;}
  49. }
  50. .del{color: #727272;font-size: 14px;}
  51. }
  52. }
  53. .foot-wiget{
  54. position: fixed;
  55. bottom: 10px;
  56. left: 10px;
  57. width: calc(100% - 20px);
  58. .foot-btn{
  59. background: #db292b;
  60. image{width: 15px;height: 15px;margin-right: 6px;}
  61. border-radius: 25px;
  62. padding: 14px 0;
  63. color: #FFF;
  64. }
  65. }
  66. }
  67. </style>
  68. <script>
  69. export default {
  70. data() {
  71. return {
  72. addList:[],
  73. type : ""
  74. }
  75. },
  76. onShow() {
  77. this.initView();
  78. },
  79. onLoad(options) {
  80. this.type = options.type || '';
  81. },
  82. methods: {
  83. /**
  84. * 地址栏目
  85. */
  86. initView:function(){
  87. this
  88. .request
  89. .post("userAddress")
  90. .then(res=>{
  91. if(res.code == 200) {
  92. this.addList = res.data;
  93. }
  94. })
  95. .catch(err=>{
  96. this.utils.Tip("网络错误,请稍后尝试");
  97. });
  98. },
  99. // 设置默认地址
  100. set_default_address(id,index){
  101. this.utils.loadIng("提交中..");
  102. this
  103. .request
  104. .post("userAddressDeflault",{id:id})
  105. .then(res=>{
  106. uni.hideLoading();
  107. if(res.code == 200) {
  108. this.addList.forEach((v,k)=>{
  109. if(index == k){
  110. v.status = 1;
  111. }else{
  112. v.status = 0;
  113. }
  114. })
  115. }
  116. })
  117. .catch(err=>{
  118. uni.hideLoading();
  119. this.utils.Tip("网络错误,请稍后尝试");
  120. });
  121. },
  122. // 删除地址
  123. del_address(id,index){
  124. uni.showModal({
  125. title:"提示",
  126. content:"确认删除该地址吗?",
  127. success: (res) => {
  128. if(res.confirm){
  129. this.utils.loadIng("提交中...");
  130. this
  131. .request
  132. .post("userAddressDel",{id:id})
  133. .then(res=>{
  134. uni.hideLoading();
  135. if(res.code == 200) {
  136. this.addList.splice(index,1);
  137. }
  138. })
  139. .catch(err=>{
  140. uni.hideLoading();
  141. this.utils.Tip("网络错误,请稍后尝试");
  142. });
  143. }
  144. }
  145. })
  146. },
  147. // 编辑地址
  148. editClick(id){
  149. uni.navigateTo({
  150. url:`/pages/user/address/add/add?id=${id}`
  151. })
  152. },
  153. mobileTap(str1){
  154. let reg = /^(\d{3})\d*(\d{4})$/;
  155. return str1.replace(reg,'$1****$2')
  156. },
  157. addClick(){
  158. uni.navigateTo({
  159. url:`/pages/user/address/add/add`
  160. })
  161. },
  162. clickView:function(item) {
  163. if(this.type == 'select') {
  164. uni.$emit("selectAddress",{addressId:item.id});
  165. uni.navigateBack();
  166. }
  167. }
  168. },
  169. }
  170. </script>