address.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <view class="container clearfix">
  3. <view v-if="isEmpty" class="empty-container">
  4. <image
  5. class="empty-container-image"
  6. src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AFmO1AAGxLZjSeDg040.png"
  7. mode="aspectFit"
  8. ></image>
  9. <view class="txt">您还没有收货地址</view> <view class="txt">点击底部按钮添加收货地址吧~~</view>
  10. <view class="login-btn" @click="addAddress('add')">添加新地址</view>
  11. </view>
  12. <view v-else class="address-list" :style="{ height: scrollHeight + 'px' }">
  13. <scroll-view scroll-y="true" :style="{ height: scrollHeight + 'px' }">
  14. <view class="list" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
  15. <view class="wrapper">
  16. <view class="u-box">
  17. <text class="name">{{ item.receiver }}</text> <text class="mobile">{{ item.mobile }}</text>
  18. </view>
  19. <view class="u-box b-b">
  20. <text class="address"
  21. >收货地址:{{ item.province }}{{ item.city }}{{ item.town }}{{ item.address }}</text
  22. >
  23. </view>
  24. <view class="u-box b-t">
  25. <view v-if="item.defaultFlag == 1" class="tag-left">
  26. <view class="tag">默认地址</view>
  27. </view>
  28. <view v-else class="tag-left"></view>
  29. <view class="tag-right">
  30. <view class="t-b" @click.stop="deleteAddress(item.addressId)">
  31. <text class="iconfont icon-shanchu"></text> <text class="txt">删除</text>
  32. </view>
  33. <view class="t-b" @click.stop="addAddress('edit', item)">
  34. <text class="iconfont icon-bianji"></text> <text class="txt">编辑</text>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </scroll-view>
  41. <view class="add-btn" @click="addAddress('add')" :style="{ bottom: isIphoneX ? '68rpx' : '34rpx' }"
  42. >添加新地址</view
  43. >
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import authorize from '@/common/config/authorize.js'
  49. export default {
  50. data() {
  51. return {
  52. isIphoneX: this.$store.state.isIphoneX,
  53. isSelect: false,
  54. isEmpty: false,
  55. listQuery: {
  56. userId: 0,
  57. pageNum: 1,
  58. pageSize: 10
  59. },
  60. addressList: [],
  61. hasNextPage: false,
  62. allowDataStatus: true,
  63. wrapperHeight: '100%',
  64. scrollHeight: '',
  65. currPage: '', //当前页面
  66. prevPage: '' //上一个页面
  67. }
  68. },
  69. onLoad(option) {
  70. if (option.type == 'select') {
  71. this.isSelect = true
  72. }
  73. this.setScrollHeight()
  74. },
  75. methods: {
  76. setScrollHeight() {
  77. // 窗口高度 - 底部距离
  78. setTimeout(() => {
  79. const query = wx.createSelectorQuery().in(this)
  80. query.selectAll('.add-btn').boundingClientRect()
  81. query.exec(res => {
  82. if (res[0][0]) {
  83. let winHeight = this.$api.getWindowHeight(),
  84. eleTop = res[0][0].top - 1
  85. this.scrollHeight = eleTop
  86. }
  87. })
  88. }, 500)
  89. },
  90. getQueryAddressList() {
  91. //初始化地址列表数据
  92. this.UserService.QueryAddressList(this.listQuery)
  93. .then(response => {
  94. let data = response.data
  95. if (data.list && data.list.length > 0) {
  96. this.isEmpty = false
  97. this.hasNextPage = data.hasNextPage
  98. this.addressList = data.list
  99. } else {
  100. this.isEmpty = true
  101. }
  102. })
  103. .catch(error => {
  104. this.$util.msg(error.msg, 2000)
  105. })
  106. },
  107. getOnReachBottomData() {
  108. // 上滑加载分页
  109. this.listQuery.pageNum += 1
  110. this.UserService.QueryAddressList(this.listQuery)
  111. .then(response => {
  112. let data = response.data
  113. if (data.list && data.list.length > 0) {
  114. this.hasNextPage = data.hasNextPage
  115. this.addressList = this.addressList.concat(data.list)
  116. }
  117. })
  118. .catch(error => {
  119. this.$util.msg(error.msg, 2000)
  120. })
  121. },
  122. checkAddress(item) {
  123. //选择地址
  124. //是否需要返回地址(从订单确认页跳过来选收货地址)
  125. if (!this.isSelect) {
  126. return
  127. }
  128. uni.setStorageSync('selectAddress', item)
  129. var pages = getCurrentPages()
  130. var prevPage = pages[pages.length - 2] //上一个页面
  131. prevPage.setData({ select: 'select' })
  132. uni.navigateBack()
  133. },
  134. addAddress(type, item) {
  135. uni.navigateTo({
  136. url: `/pages/user/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
  137. })
  138. },
  139. deleteAddress(addressId) {
  140. //删除收货地址
  141. this.$util.modal('', '确定要删除该地址?', '确定', '取消', true, () => {
  142. this.UserService.DeleteAddress({ addressId: addressId, userId: this.listQuery.userId })
  143. .then(response => {
  144. this.$util.msg('删除成功', 2000, true, 'success')
  145. setTimeout(() => {
  146. this.listQuery.pageNum = 1
  147. this.addressList = []
  148. this.getQueryAddressList()
  149. }, 2000)
  150. })
  151. .catch(error => {
  152. this.$util.msg(error.msg, 2000)
  153. })
  154. })
  155. }
  156. },
  157. onReachBottom() {
  158. if (this.hasNextPage) {
  159. this.getOnReachBottomData()
  160. }
  161. },
  162. onShow() {
  163. this.$api.getStorage().then(resolve => {
  164. this.listQuery.userId = resolve.userId ? resolve.userId : 0
  165. this.listQuery.pageNum = 1
  166. this.addressList = []
  167. this.getQueryAddressList()
  168. var pages = getCurrentPages()
  169. var prevPage = pages[pages.length - 2] //上一个页面
  170. // prevPage.setData({select:''})
  171. })
  172. }
  173. }
  174. </script>
  175. <style lang="scss">
  176. page {
  177. height: auto;
  178. }
  179. page,
  180. .container {
  181. /* padding-bottom: 120upx; */
  182. background: #f7f7f7;
  183. border-top: 1px solid #ebebeb;
  184. }
  185. .container {
  186. position: relative;
  187. }
  188. .address-list {
  189. width: 100%;
  190. box-sizing: border-box;
  191. padding: 24rpx;
  192. }
  193. .list {
  194. display: flex;
  195. align-items: center;
  196. width: 100%;
  197. height: auto;
  198. padding: 24rpx;
  199. background: #ffffff;
  200. position: relative;
  201. box-sizing: border-box;
  202. margin-bottom: 24rpx;
  203. border-radius: 16rpx;
  204. }
  205. .wrapper {
  206. display: flex;
  207. flex-direction: column;
  208. flex: 1;
  209. }
  210. .u-box.b-b {
  211. }
  212. .u-box.b-b {
  213. margin-bottom: 24rpx;
  214. }
  215. .u-box.b-t {
  216. margin-bottom: 0;
  217. }
  218. .u-box {
  219. display: flex;
  220. align-items: center;
  221. font-size: $font-size-28;
  222. color: $text-color;
  223. line-height: 40rpx;
  224. margin-bottom: 12rpx;
  225. .name {
  226. margin-right: 40rpx;
  227. font-weight: bold;
  228. }
  229. .mobile {
  230. font-weight: bold;
  231. }
  232. .tag-left {
  233. flex: 6;
  234. .tag {
  235. width: 120rpx;
  236. height: 40rpx;
  237. background: $color-system;
  238. border-radius: 20rpx;
  239. font-size: $font-size-24;
  240. color: #ffffff;
  241. line-height: 40rpx;
  242. text-align: center;
  243. padding: 0 6rpx;
  244. }
  245. }
  246. .tag-right {
  247. flex: 4;
  248. display: flex;
  249. text-align: right;
  250. .t-b {
  251. flex: 1;
  252. line-height: 40rpx;
  253. .txt {
  254. font-size: $font-size-24;
  255. color: $text-color;
  256. line-height: 40rpx;
  257. }
  258. }
  259. .icon-shanchu {
  260. color: #ff2a2a;
  261. margin-right: 8rpx;
  262. }
  263. .icon-bianji {
  264. color: #2a7aff;
  265. margin-right: 8rpx;
  266. }
  267. }
  268. .address {
  269. font-size: $font-size-28;
  270. color: $text-color;
  271. line-height: 40rpx;
  272. -o-text-overflow: ellipsis;
  273. text-overflow: ellipsis;
  274. display: -webkit-box;
  275. word-break: break-all;
  276. -webkit-box-orient: vertical;
  277. -webkit-line-clamp: 2;
  278. overflow: hidden;
  279. }
  280. }
  281. .add-btn {
  282. position: fixed;
  283. left: 75rpx;
  284. right: 75rpx;
  285. bottom: 34rpx;
  286. z-index: 95;
  287. display: flex;
  288. align-items: center;
  289. justify-content: center;
  290. width: 600rpx;
  291. height: 88rpx;
  292. font-size: $font-size-28;
  293. line-height: 88rpx;
  294. color: #ffffff;
  295. text-align: center;
  296. background: $btn-confirm;
  297. border-radius: 44rpx;
  298. }
  299. .adds-btn {
  300. width: 600rpx;
  301. height: 88rpx;
  302. font-size: 28rpx;
  303. line-height: 88rpx;
  304. color: #ffffff;
  305. margin: 0 auto;
  306. text-align: center;
  307. background: #000000;
  308. border-radius: 44rpx;
  309. }
  310. </style>