addressList.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view class="container">
  3. <view class="address-list">
  4. <u-swipe-action v-for="(item, index) in addressList" :key="index" :index="index" @click="deleteAddress" :options="options">
  5. <view class="address-row" @click="setAddress(item)">
  6. <view class="address-first-name" :class="item.isDefault == 1 ? 'address-first-name-active' : ''">{{item.username ? item.username.slice(1,2) : ''}}</view>
  7. <view class="address-info">
  8. <view class="address-name-phone">
  9. <text class="address-name">{{item.username}}</text>
  10. <text class="address-phone">{{item.phone}}</text>
  11. </view>
  12. <view class="address-type-text">
  13. <view class="address-type" :class="item.isDefault == 1 ? 'address-type-active' : ''">{{item.isDefault == 1 ? '默认' : item.tag}}</view>
  14. <text class="address-text">{{item.province}},{{item.city}},{{item.area}},{{item.address}}</text>
  15. </view>
  16. </view>
  17. <view class="address-edit" @click.stop="editAddress(item)">编辑</view>
  18. </view>
  19. </u-swipe-action>
  20. </view>
  21. <view class="address-handle">
  22. <u-button type="success" shape="circle" :ripple="true" @click="addAddress" class="handle-custom">新增地址</u-button>
  23. </view>
  24. <u-modal v-model="modalShow" content="是否将删除该地址" @confirm="submitDelete" :async-close="true" :show-cancel-button="true"></u-modal>
  25. <u-top-tips ref="uTips"></u-top-tips>
  26. </view>
  27. </template>
  28. <script>
  29. const NET = require('@/utils/request')
  30. const API = require('@/config/api')
  31. export default {
  32. data() {
  33. return {
  34. pageType: 1,
  35. addressList: [],
  36. options: [{
  37. text: '删除',
  38. style: {
  39. backgroundColor: '#dd524d'
  40. }
  41. }],
  42. modalShow: false,
  43. }
  44. },
  45. onLoad(options) {
  46. this.pageType = options.type
  47. },
  48. onShow() {
  49. this.getAddress()
  50. },
  51. onPullDownRefresh() {
  52. this.getAddress('refresh')
  53. },
  54. methods: {
  55. // 查询地址
  56. getAddress(type) {
  57. NET.request(API.getAddressList, {}, 'POST').then(res => {
  58. if (type == 'refresh') {
  59. uni.stopPullDownRefresh();
  60. }
  61. this.addressList = res.data
  62. }).catch(error => {
  63. this.$refs.uTips.show({
  64. title: '获取默认地址失败',
  65. type: 'warning',
  66. })
  67. })
  68. },
  69. // 设置地址
  70. setAddress(item) {
  71. if (this.pageType == 2) {
  72. uni.setStorage({
  73. key: 'defaultAddress',
  74. data: {
  75. memberAddressId: item.id,
  76. username: item.username,
  77. phone: item.phone,
  78. province: item.province,
  79. city: item.city,
  80. area: item.area,
  81. address: item.address,
  82. }
  83. });
  84. uni.navigateBack()
  85. }
  86. },
  87. // 删除地址
  88. deleteAddress(index, index1) {
  89. this.addressId = this.addressList[index].id
  90. this.modalShow = true
  91. },
  92. // 提交删除地址
  93. submitDelete() {
  94. NET.request(API.deleteAddress + this.addressId, {}, 'GET').then(res => {
  95. this.getAddress()
  96. this.modalShow = false
  97. }).catch(error => {
  98. this.modalShow = false
  99. this.$refs.uTips.show({
  100. title: '删除该地址失败',
  101. type: 'warning',
  102. })
  103. })
  104. },
  105. // 编辑地址
  106. editAddress(item) {
  107. uni.navigateTo({
  108. url: '/pagesMain/addressForm?addressId=' + item.id
  109. });
  110. },
  111. // 新增地址
  112. addAddress() {
  113. uni.navigateTo({
  114. url: '/pagesMain/addressForm'
  115. });
  116. }
  117. },
  118. }
  119. </script>
  120. <style lang="less" scoped>
  121. page {
  122. width: 100%;
  123. height: 100%;
  124. }
  125. .container {
  126. width: 100%;
  127. height: 100%;
  128. float: left;
  129. box-sizing: border-box;
  130. padding-bottom: 70px;
  131. overflow-y: auto;
  132. .address-list {
  133. width: 100%;
  134. float: left;
  135. .address-row {
  136. width: 100%;
  137. height: 77px;
  138. float: left;
  139. border-bottom: 1px solid #DBDBDB;
  140. box-sizing: border-box;
  141. padding: 20px 15px;
  142. .address-first-name {
  143. width: 36px;
  144. height: 36px;
  145. float: left;
  146. background: #656565;
  147. border-radius: 50%;
  148. color: #FFFFFF;
  149. font-size: 18px;
  150. font-family: PingFang SC;
  151. text-align: center;
  152. line-height: 36px;
  153. }
  154. .address-first-name-active {
  155. background: #51A539;
  156. }
  157. .address-info {
  158. width: calc(100% - 103px);
  159. height: 36px;
  160. float: left;
  161. margin: 0 10px 0 15px;
  162. .address-name-phone {
  163. width: 100%;
  164. height: 16px;
  165. float: left;
  166. line-height: 16px;
  167. font-family: PingFang SC;
  168. .address-name {
  169. color: #333333;
  170. font-size: 15px;
  171. margin-right: 16px;
  172. }
  173. .address-phone {
  174. color: #656565;
  175. font-size: 12px;
  176. }
  177. }
  178. .address-type-text {
  179. width: 100%;
  180. height: 16px;
  181. margin-top: 4px;
  182. float: left;
  183. line-height: 16px;
  184. font-family: PingFang SC;
  185. white-space: nowrap;
  186. text-overflow: ellipsis;
  187. overflow: hidden;
  188. .address-type {
  189. height: 16px;
  190. padding: 0 6px;
  191. display: inline-block;
  192. border-radius: 4px;
  193. font-size: 12px;
  194. color: #FFFFFF;
  195. background: #656565;
  196. margin-right: 6px;
  197. }
  198. .address-type-active {
  199. background: #51A539;
  200. }
  201. .address-text {
  202. font-size: 12px;
  203. color: #333333;
  204. }
  205. }
  206. }
  207. .address-edit {
  208. width: 42px;
  209. height: 26px;
  210. margin: 5px 0;
  211. float: left;
  212. border-left: 1px solid #DBDBDB;
  213. line-height: 26px;
  214. text-align: right;
  215. font-size: 12px;
  216. font-family: PingFang SC;
  217. color: #656565;
  218. }
  219. }
  220. }
  221. .address-handle {
  222. width: calc(100% - 30px);
  223. height: 40px;
  224. position: fixed;
  225. bottom: 20px;
  226. left: 15px;
  227. .handle-custom {
  228. background-color: #51A539;
  229. }
  230. }
  231. }
  232. </style>