address.nvue 5.1 KB

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