address.nvue 4.6 KB

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