address.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <view>
  3. <view class="container">
  4. <view v-if="addressList.length>0" class="addressList">
  5. <scroll-view scroll-y="true">
  6. <u-swipe-action v-for="(item, index) in addressList" :key="item.id"
  7. :index="index" :options="options"
  8. :show="item.show"
  9. bg-color="#f3f4f6"
  10. style="margin: 20rpx 20rpx 0rpx 20rpx"
  11. @click="click"
  12. >
  13. <view class="item" @click="selectAddress(item)">
  14. <view class="title">
  15. {{ item.userName }}
  16. <view class="phone">{{ item.phone }}</view>
  17. <view v-if="item.isDefault == 1" class="default">
  18. 默认
  19. </view>
  20. </view>
  21. <view class="desc">
  22. {{ item.address }}
  23. </view>
  24. </view>
  25. </u-swipe-action>
  26. </scroll-view>
  27. <view class="bottomView">
  28. <u-button :custom-style="customStyle" hover-class="none" shape="circle" @click="addAddress">新增收货地址
  29. </u-button>
  30. </view>
  31. </view>
  32. <view v-else class="empty">
  33. <image :src="empty" style="width: 200px;height: 200px;"></image>
  34. <view class="title">找不到您的收获地址哦</view>
  35. <view class="tip">先去添加一个吧</view>
  36. <view class="bottomView">
  37. <u-button :custom-style="customStyle" hover-class="none" shape="circle" @click="addAddress">新增收货地址
  38. </u-button>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. export default {
  46. data() {
  47. return {
  48. addressList: [],
  49. empty: '/static/empty/address.png',
  50. options: [
  51. {
  52. text: '修改',
  53. style: {
  54. backgroundColor: 'orange'
  55. }
  56. },
  57. {
  58. text: '删除',
  59. style: {
  60. backgroundColor: '#ff536f'
  61. }
  62. }
  63. ],
  64. customStyle: {
  65. marginTop: '40rpx', // 注意驼峰命名,并且值必须用引号包括,因为这是对象
  66. marginBottom: '40rpx',
  67. marginLeft: '40rpx',
  68. marginRight: '40rpx',
  69. color: '#FFF',
  70. backgroundColor: '#ff536f'
  71. }
  72. };
  73. },
  74. onLoad() {
  75. // 获取收货列表
  76. this.findAddressList();
  77. },
  78. methods: {
  79. addAddress() {
  80. this.$u.route('/pages/address/addAddress')
  81. },
  82. click(index, index1) {
  83. if (index1 == 0) {
  84. this.$u.route({
  85. url: '/pages/address/addAddress',
  86. params: {
  87. addressId: this.addressList[index].id
  88. }
  89. })
  90. } else if (index1 == 1) {
  91. let url = "/api/mallApi/deleteAddress/" + this.addressList[index].id;
  92. this.$u.delete(url).then(result => {
  93. this.addressList.splice(index, 1);
  94. this.$mytip.toast('删除成功')
  95. });
  96. }
  97. },
  98. selectAddress(item) {
  99. this.$u.route({
  100. url: '/pages/order/preOrder',
  101. params: {
  102. addressId: item.id,
  103. userName: item.userName,
  104. phone: item.phone,
  105. addressName: item.address
  106. }
  107. })
  108. },
  109. findAddressList() {
  110. let url = "/api/mallApi/findAddressList";
  111. this.$u.get(url, {
  112. orderByColumn: 'create_time',
  113. isAsc: 'desc',
  114. pageNum: 1,
  115. pageSize: 100,
  116. }).then(result => {
  117. // 商品数据
  118. this.addressList = result.rows;
  119. });
  120. }
  121. }
  122. };
  123. </script>
  124. <style lang="scss" scoped>
  125. .container {
  126. text-align: center;
  127. overflow: hidden;
  128. border-radius: 8 rpx;
  129. .addressList {
  130. text-align: left;
  131. .item {
  132. padding: 10 rpx 20 rpx;
  133. background-color: #ffffff;
  134. .title {
  135. width: 430 rpx;
  136. font-size: 16px;
  137. color: $u-main-color;
  138. text-overflow: ellipsis;
  139. overflow: hidden;
  140. white-space: normal;
  141. overflow: hidden;
  142. text-overflow: ellipsis;
  143. display: -webkit-box;
  144. -webkit-box-orient: vertical;
  145. -webkit-line-clamp: 1;
  146. display: flex;
  147. align-items: center;
  148. margin: 10 rpx 20 rpx 30 rpx 0;
  149. .phone {
  150. margin-left: 20 rpx;
  151. color: $u-tips-color;
  152. font-size: 16px;
  153. }
  154. .default {
  155. margin-left: 20 rpx;
  156. padding: 2 rpx 8 rpx;
  157. font-size: 14px;
  158. color: #fff;
  159. border-radius: 8 rpx;
  160. background-color: #ff536f;
  161. }
  162. }
  163. .desc {
  164. font-weight: normal;
  165. font-size: 14px;
  166. color: $u-tips-color;
  167. margin: 10 rpx 20 rpx 20 rpx 0;
  168. }
  169. }
  170. }
  171. .empty {
  172. margin-top: 220 rpx;
  173. width: 100%;
  174. text-align: center;
  175. .title {
  176. margin: 20 rpx 0 10 rpx 0;
  177. color: $u-tips-color;
  178. font-size: 14px;
  179. }
  180. .tip {
  181. color: $u-tips-color;
  182. font-size: 14px;
  183. }
  184. .btn {
  185. color: #fff;
  186. background-image: linear-gradient(to left, #ff536f, rgba(#ff536f, 0.6));
  187. width: 200 rpx;
  188. padding: 15 rpx 28 rpx;
  189. border-radius: 130 rpx;
  190. margin: 300 rpx 0 0 275 rpx;
  191. }
  192. }
  193. .bottomView {
  194. // box-shadow:0 -1px 1px 0 rgba(0, 0, 0, 0.05);
  195. position: fixed;
  196. left: 0;
  197. right: 0;
  198. bottom: 0;
  199. z-index: 999;
  200. // background-color: #fff;
  201. }
  202. }
  203. </style>