addressList.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 ? 'address-first-name-active' : ''">{{item.username ? item.username.slice(0,1) : ''}}</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 v-if="item.isDefault || item.tag" class="address-type" :class="item.isDefault? 'address-type-active' : ''">{{item.isDefault ? '默认' : 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. position: relative;
  143. .address-first-name {
  144. width: 36px;
  145. height: 36px;
  146. float: left;
  147. background: #fe9900;
  148. border-radius: 50%;
  149. color: #FFFFFF;
  150. font-size: 18px;
  151. font-family: PingFang SC;
  152. text-align: center;
  153. line-height: 36px;
  154. top: 50%;
  155. position: absolute;
  156. transform: translateY(-50%);
  157. }
  158. .address-first-name-active {
  159. background: #51A539;
  160. }
  161. .address-info {
  162. width: calc(100% - 103px);
  163. // height: 36px;
  164. float: left;
  165. margin: 0 10px 0 51px;
  166. .address-name-phone {
  167. width: 100%;
  168. // height: 16px;
  169. float: left;
  170. line-height: 16px;
  171. font-family: PingFang SC;
  172. .address-name {
  173. color: #333333;
  174. font-size: 15px;
  175. margin-right: 16px;
  176. }
  177. .address-phone {
  178. color: #656565;
  179. font-size: 12px;
  180. }
  181. }
  182. .address-type-text {
  183. width: 100%;
  184. // height: 16px;
  185. margin-top: 4px;
  186. float: left;
  187. line-height: 16px;
  188. font-family: PingFang SC;
  189. .address-type {
  190. height: 16px;
  191. padding: 0 6px;
  192. display: inline-block;
  193. border-radius: 4px;
  194. font-size: 12px;
  195. color: #FFFFFF;
  196. background: #fe9900;
  197. margin-right: 6px;
  198. }
  199. .address-type-active {
  200. background: #51A539;
  201. }
  202. .address-text {
  203. font-size: 12px;
  204. color: #333333;
  205. word-break:break-all;
  206. }
  207. }
  208. }
  209. .address-edit {
  210. width: 42px;
  211. height: 26px;
  212. margin: 5px 0;
  213. float: left;
  214. border-left: 1px solid #DBDBDB;
  215. line-height: 26px;
  216. text-align: right;
  217. font-size: 12px;
  218. font-family: PingFang SC;
  219. color: #656565;
  220. top: 50%;
  221. right: 15px;
  222. position: absolute;
  223. transform: translateY(-50%);
  224. }
  225. }
  226. }
  227. .address-handle {
  228. width: calc(100% - 30px);
  229. height: 40px;
  230. position: fixed;
  231. bottom: 20px;
  232. left: 15px;
  233. .handle-custom {
  234. background-color: #56a83a;
  235. /deep/button {
  236. background-color: #56a83a;
  237. }
  238. /deep/.u-btn--success--disabled {
  239. background-color: #74bd60 !important;
  240. }
  241. }
  242. }
  243. }
  244. </style>