address.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view>
  3. <!--标题栏-->
  4. <bar-title bgColor="bg-white" isBack>
  5. <block slot="content">我的地址</block>
  6. </bar-title>
  7. <!--列表-->
  8. <view class="bg-white zaiui-address-card-view" v-for="item in addressList" :key="item.id">
  9. <view class="flex text-black text-lg" :data-item="item" @click="selectAddressTap">
  10. <view class="flex-sub text-left">{{item.name}}</view>
  11. <view class="flex-sub text-right">{{item.phone}}</view>
  12. </view>
  13. <view class="margin-tb-sm text-gray" :data-item="item" @click="selectAddressTap">
  14. {{item.area_string}} {{item.address}}
  15. </view>
  16. <view class="zaiui-line-view"/>
  17. <view class="zaiui-right-view">
  18. <text>
  19. <checkbox class='round red sm zaiui-checked' style="transform: scale(0.7);" :class="item.type == 1?'checked':''"
  20. :checked="item.type == 1?true:false" :data-item="item" @click="setDefaultAddress" /><text>设为默认</text>
  21. </text>
  22. <text class="cuIcon-write" @click="editAddressTap(item)">编辑</text>
  23. <text class="cuIcon-delete" @click="deleteAddress(item)">删除</text>
  24. </view>
  25. </view>
  26. <!--按钮-->
  27. <view class="bg-white wecanui-footer-fixed foot-pb">
  28. <view class="flex flex-direction">
  29. <button class="cu-btn bg-red" @click="AddAddressTap">添加新地址</button>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import barTitle from '@/components/zaiui-common/basics/bar-title';
  36. import _tool from '@/static/zaiui/util/tools.js'; //工具函数
  37. export default {
  38. components: {
  39. barTitle
  40. },
  41. data() {
  42. return {
  43. addressList: [],
  44. fromOrder: false
  45. }
  46. },
  47. onLoad(options) {
  48. this.fromOrder = options.from==='cart'
  49. },
  50. onShow() {
  51. this.getList()
  52. },
  53. onReady() {
  54. _tool.setBarColor(true);
  55. uni.pageScrollTo({
  56. scrollTop: 0,
  57. duration: 0
  58. });
  59. },
  60. methods: {
  61. editAddressTap(item) {
  62. uni.navigateTo({
  63. url: '/pages/my/add-address?id='+item.id
  64. });
  65. },
  66. AddAddressTap() {
  67. uni.navigateTo({
  68. url: '/pages/my/add-address'
  69. });
  70. },
  71. selectAddressTap(e) {
  72. if(this.fromOrder) {
  73. let pages = getCurrentPages();
  74. if(pages[pages.length - 2] && pages[pages.length - 2].$vm.setAddress) {
  75. pages[pages.length - 2].$vm.setAddress(e.currentTarget.dataset.item);
  76. uni.navigateBack({
  77. delta: 1
  78. })
  79. }
  80. }
  81. },
  82. getList() {
  83. this.reqByuser({
  84. url: '?l=address.list',
  85. // method: 'POST',
  86. data: {
  87. },
  88. success: res => {
  89. if(res.data.status == 1) {
  90. this.addressList = res.data.data;
  91. }else {
  92. uni.showToast({
  93. icon: 'error',
  94. title: '加载失败'
  95. })
  96. }
  97. }
  98. })
  99. },
  100. setDefaultAddress(e) {
  101. let {id, province_id, city_id, county_id, address, name, phone} = e.currentTarget.dataset.item;
  102. let data = {
  103. id, province: province_id, city: city_id, county: county_id, address, name, phone,
  104. type: 1
  105. };
  106. this.reqByuser({
  107. url: '?l=address.up',
  108. data,
  109. success: res => {
  110. if(res.data.status == 1) {
  111. uni.showToast({
  112. icon: 'success',
  113. title: '更新成功'
  114. })
  115. this.getList()
  116. }
  117. }
  118. })
  119. },
  120. deleteAddress(item) {
  121. uni.showModal({
  122. title: '提醒',
  123. content: '确定要删除吗?',
  124. success: (res) => {
  125. if(res.confirm) {
  126. this.reqByuser({
  127. url: '?l=address.delete',
  128. data: {
  129. id: item.id
  130. },
  131. success: res => {
  132. if(res.data.status == 1) {
  133. uni.showToast({
  134. icon: 'success',
  135. title: '删除成功'
  136. })
  137. this.getList()
  138. }
  139. }
  140. })
  141. }
  142. }
  143. })
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="scss">
  149. /* #ifdef APP-PLUS */
  150. @import "../../static/colorui/main.css";
  151. @import "../../static/colorui/icon.css";
  152. @import "../../static/zaiui/style/app.scss";
  153. /* #endif */
  154. .zaiui-address-card-view {
  155. position: relative;
  156. margin: 36.36upx 27.27upx;
  157. border-radius: 10.9upx;
  158. padding: 18.18upx;
  159. .zaiui-line-view {
  160. position: relative;
  161. background: #f9f9f9;
  162. margin-bottom: 20upx;
  163. height: 2upx;
  164. }
  165. .zaiui-right-view {
  166. position: relative;
  167. text-align: right;
  168. text {
  169. &:before {
  170. margin-right: 5px;
  171. }
  172. }
  173. text + text {
  174. margin-left: 20px;
  175. }
  176. }
  177. }
  178. .wecanui-footer-fixed .flex-direction {
  179. padding: 18.18upx;
  180. }
  181. </style>