addressList.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. methods: {
  52. // 查询地址
  53. getAddress() {
  54. NET.request(API.getAddressList, {}, 'POST').then(res => {
  55. this.addressList = res.data
  56. }).catch(error => {
  57. this.$refs.uTips.show({
  58. title: '获取默认地址失败',
  59. type: 'warning',
  60. })
  61. })
  62. },
  63. // 设置地址
  64. setAddress(item) {
  65. if (this.pageType == 2) {
  66. uni.setStorage({
  67. key: 'defaultAddress',
  68. data: {
  69. memberAddressId: item.id,
  70. username: item.username,
  71. phone: item.phone,
  72. province: item.province,
  73. city: item.city,
  74. area: item.area,
  75. address: item.address,
  76. }
  77. });
  78. uni.navigateBack()
  79. }
  80. },
  81. // 删除地址
  82. deleteAddress(index, index1) {
  83. this.addressId = this.addressList[index].id
  84. this.modalShow = true
  85. },
  86. // 提交删除地址
  87. submitDelete() {
  88. NET.request(API.deleteAddress + this.addressId, {}, 'GET').then(res => {
  89. this.getAddress()
  90. this.modalShow = false
  91. }).catch(error => {
  92. this.modalShow = false
  93. this.$refs.uTips.show({
  94. title: '删除该地址失败',
  95. type: 'warning',
  96. })
  97. })
  98. },
  99. // 编辑地址
  100. editAddress(item) {
  101. uni.navigateTo({
  102. url: '/pagesMain/addressForm?addressId=' + item.id
  103. });
  104. },
  105. // 新增地址
  106. addAddress() {
  107. uni.navigateTo({
  108. url: '/pagesMain/addressForm'
  109. });
  110. }
  111. },
  112. }
  113. </script>
  114. <style lang="less" scoped>
  115. page {
  116. width: 100%;
  117. height: 100%;
  118. }
  119. .container {
  120. width: 100%;
  121. height: 100%;
  122. float: left;
  123. box-sizing: border-box;
  124. padding-bottom: 70px;
  125. overflow-y: auto;
  126. .address-list {
  127. width: 100%;
  128. float: left;
  129. .address-row {
  130. width: 100%;
  131. height: 77px;
  132. float: left;
  133. border-bottom: 1px solid #DBDBDB;
  134. box-sizing: border-box;
  135. padding: 20px 15px;
  136. .address-first-name {
  137. width: 36px;
  138. height: 36px;
  139. float: left;
  140. background: #656565;
  141. border-radius: 50%;
  142. color: #FFFFFF;
  143. font-size: 18px;
  144. font-family: PingFang SC;
  145. text-align: center;
  146. line-height: 36px;
  147. }
  148. .address-first-name-active {
  149. background: #51A539;
  150. }
  151. .address-info {
  152. width: calc(100% - 103px);
  153. height: 36px;
  154. float: left;
  155. margin: 0 10px 0 15px;
  156. .address-name-phone {
  157. width: 100%;
  158. height: 16px;
  159. float: left;
  160. line-height: 16px;
  161. font-family: PingFang SC;
  162. .address-name {
  163. color: #333333;
  164. font-size: 15px;
  165. margin-right: 16px;
  166. }
  167. .address-phone {
  168. color: #656565;
  169. font-size: 12px;
  170. }
  171. }
  172. .address-type-text {
  173. width: 100%;
  174. height: 16px;
  175. margin-top: 4px;
  176. float: left;
  177. line-height: 16px;
  178. font-family: PingFang SC;
  179. white-space: nowrap;
  180. text-overflow: ellipsis;
  181. overflow: hidden;
  182. .address-type {
  183. height: 16px;
  184. padding: 0 6px;
  185. display: inline-block;
  186. border-radius: 4px;
  187. font-size: 12px;
  188. color: #FFFFFF;
  189. background: #656565;
  190. margin-right: 6px;
  191. }
  192. .address-type-active {
  193. background: #51A539;
  194. }
  195. .address-text {
  196. font-size: 12px;
  197. color: #333333;
  198. }
  199. }
  200. }
  201. .address-edit {
  202. width: 42px;
  203. height: 26px;
  204. margin: 5px 0;
  205. float: left;
  206. border-left: 1px solid #DBDBDB;
  207. line-height: 26px;
  208. text-align: right;
  209. font-size: 12px;
  210. font-family: PingFang SC;
  211. color: #656565;
  212. }
  213. }
  214. }
  215. .address-handle {
  216. width: calc(100% - 30px);
  217. height: 40px;
  218. position: fixed;
  219. bottom: 20px;
  220. left: 15px;
  221. .handle-custom {
  222. background-color: #51A539;
  223. }
  224. }
  225. }
  226. </style>