address.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="container clearfix">
  3. <view v-if="isEmpty" class="empty-container">
  4. <image class="empty-container-image" :src="StaticUrl + 'icon-empty-address.png'" mode="aspectFit"></image>
  5. <view class="txt">您还没有收货地址</view> <view class="txt">点击底部按钮添加收货地址吧~~</view>
  6. <view class="login-btn" @click="addAddress('add')">添加新地址</view>
  7. </view>
  8. <view v-else class="address-list" :style="{ height: scrollHeight + 'px' }">
  9. <scroll-view scroll-y="true" :style="{ height: scrollHeight + 'px' }">
  10. <view class="list" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
  11. <view class="wrapper">
  12. <view class="u-box">
  13. <text class="name">{{ item.shouHuoRen }}</text>
  14. <text class="mobile">{{ item.mobile }}</text>
  15. <text v-if="item.defaultFlag == 1" class="default-tags">默认</text>
  16. </view>
  17. <view class="u-box b-b">
  18. <text class="address"
  19. ><text class="label">收货地址:</text>{{ item.provinceName }}{{ item.cityName
  20. }}{{ item.townName }}{{ item.address }}</text
  21. >
  22. </view>
  23. <view class="u-box b-t">
  24. <view v-if="item.defaultFlag == 1" class="tag-left">
  25. <view class="tag"
  26. ><text class="iconfont icon-xuanze"></text><text>已设为默认地址</text></view
  27. >
  28. </view>
  29. <view v-else class="tag-left">
  30. <view class="tag" @click.stop="setDefaultAddress(item.addressId)"
  31. ><text class="iconfont icon-weixuanze"></text><text>设为默认地址</text></view
  32. >
  33. </view>
  34. <view class="tag-right">
  35. <view class="t-b" @click.stop="deleteAddress(item.addressId)">
  36. <text class="iconfont icon-shanchu"></text> <text class="txt">删除</text>
  37. </view>
  38. <view class="t-b" @click.stop="addAddress('edit', item)">
  39. <text class="iconfont icon-bianji"></text> <text class="txt">编辑</text>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. <view class="add-btn" @click.stop="addAddress('add')">添加新地址</view>
  47. </view>
  48. <tui-modal
  49. :show="modal"
  50. @click="handleClick"
  51. @cancel="hideMobel"
  52. :content="contentModalText"
  53. color="#333"
  54. :size="32"
  55. shape="circle"
  56. :maskClosable="false"
  57. ></tui-modal>
  58. </view>
  59. </template>
  60. <script>
  61. export default {
  62. data() {
  63. return {
  64. StaticUrl: this.$Static,
  65. isSelect: false,
  66. isEmpty: false,
  67. addressList: [],
  68. hasNextPage: false,
  69. allowDataStatus: true,
  70. wrapperHeight: '100%',
  71. scrollHeight: '',
  72. currPage: '', //当前页面
  73. prevPage: '', //上一个页面
  74. modal: false,
  75. contentModalText: '',
  76. deleteaddressId: 0,
  77. listQuery: {
  78. userId: '',
  79. pageNum: 1,
  80. pageSize: 10
  81. }
  82. }
  83. },
  84. onLoad(option) {
  85. if (option.type == 'select') {
  86. this.isSelect = true
  87. }
  88. this.setScrollHeight()
  89. },
  90. methods: {
  91. setScrollHeight() {
  92. // 窗口高度 - 底部距离
  93. setTimeout(() => {
  94. const query = wx.createSelectorQuery().in(this)
  95. query.selectAll('.add-btn').boundingClientRect()
  96. query.exec(res => {
  97. if (res[0][0]) {
  98. let winHeight = this.$api.getWindowHeight(),
  99. eleTop = res[0][0].top - 1
  100. this.scrollHeight = eleTop
  101. }
  102. })
  103. }, 500)
  104. },
  105. GetAddressList() {
  106. // 初始化地址列表
  107. this.$api.getComStorage('userInfo').then(resolve => {
  108. this.listQuery.userId = resolve.userId ? resolve.userId : 0
  109. this.UserService.QueryAddressList(this.listQuery)
  110. .then(response => {
  111. const data = response.data
  112. if (data.list && data.list.length > 0) {
  113. this.isEmpty = false
  114. this.addressList = data.list
  115. this.hasNextPage = data.hasNextPage
  116. } else {
  117. this.isEmpty = true
  118. }
  119. })
  120. .catch(error => {
  121. this.$util.msg(error.msg, 2000)
  122. })
  123. })
  124. },
  125. GetOnReachBottomAddressList() {
  126. //上滑加载
  127. this.listQuery.pageNum += 1
  128. this.UserService.QueryAddressList(this.listQuery)
  129. .then(response => {
  130. const data = response.data
  131. this.hasNextPage = data.hasNextPage
  132. this.addressList = this.addressList.concat(data.list)
  133. })
  134. .catch(error => {
  135. this.$util.msg(error.msg, 2000)
  136. })
  137. },
  138. checkAddress(item) {
  139. //选择地址
  140. //是否需要返回地址(从订单确认页跳过来选收货地址)
  141. if (!this.isSelect) {
  142. return
  143. }
  144. uni.setStorageSync('selectAddress', item)
  145. var pages = getCurrentPages()
  146. var prevPage = pages[pages.length - 2] //上一个页面
  147. prevPage.setData({ select: 'select' })
  148. uni.navigateBack()
  149. },
  150. // 跳转添加地址页面 type:添加或修改
  151. addAddress(type, item) {
  152. uni.navigateTo({
  153. url: `/pages/user/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
  154. })
  155. },
  156. handleClick(e) {
  157. //用户操作订单
  158. let index = e.index
  159. if (index == 1) {
  160. this.UserService.DeleteOtherAddress({
  161. addressId: this.deleteaddressId,
  162. userId: this.listQuery.userId
  163. })
  164. .then(response => {
  165. this.$util.msg('删除成功', 2000, true, 'success')
  166. setTimeout(() => {
  167. this.GetAddressList()
  168. }, 2000)
  169. })
  170. .catch(error => {
  171. this.$util.msg(error.msg, 2000)
  172. })
  173. }
  174. this.modal = false
  175. },
  176. hideMobel() {
  177. this.modal = false
  178. },
  179. //删除收货地址
  180. deleteAddress(id) {
  181. this.modal = true
  182. this.contentModalText = '确认删除该地址吗?'
  183. this.deleteaddressId = id
  184. },
  185. // 修改默认地址
  186. setDefaultAddress(id) {
  187. this.UserService.SetDefaultOtherAddress({
  188. addressId: id,
  189. userId: this.listQuery.userId
  190. })
  191. .then(res => {
  192. this.GetAddressList()
  193. })
  194. .catch(err => {
  195. this.GetAddressList()
  196. })
  197. }
  198. },
  199. onPullDownRefresh() {
  200. //下拉刷新
  201. this.listQuery.pageNum = 1
  202. this.GetAddressList()
  203. uni.stopPullDownRefresh()
  204. },
  205. onReachBottom() {
  206. console.log('用户把这个页面上拉100时触发我的')
  207. if (this.hasNextPage) {
  208. this.GetOnReachBottomAddressList()
  209. }
  210. },
  211. onShow() {
  212. this.pageNum = 1
  213. this.addressList = []
  214. this.GetAddressList()
  215. }
  216. }
  217. </script>
  218. <style lang="scss">
  219. page {
  220. height: auto;
  221. }
  222. page,
  223. .container {
  224. /* padding-bottom: 120upx; */
  225. background: #f7f7f7;
  226. border-top: 1px solid #ebebeb;
  227. }
  228. .container {
  229. position: relative;
  230. }
  231. .list {
  232. display: flex;
  233. align-items: center;
  234. width: 702rpx;
  235. height: auto;
  236. padding: 24rpx;
  237. background: #ffffff;
  238. position: relative;
  239. margin-bottom: 20rpx;
  240. }
  241. .wrapper {
  242. display: flex;
  243. flex-direction: column;
  244. flex: 1;
  245. }
  246. .u-box .label {
  247. color: #999999;
  248. }
  249. .u-box.b-b {
  250. margin-bottom: 24rpx;
  251. }
  252. .u-box.b-t {
  253. margin-bottom: 0;
  254. }
  255. .u-box {
  256. display: flex;
  257. align-items: center;
  258. font-size: $font-size-26;
  259. color: $text-color;
  260. line-height: 40rpx;
  261. margin-bottom: 12rpx;
  262. .name {
  263. margin-right: 40rpx;
  264. font-weight: bold;
  265. }
  266. .mobile {
  267. font-weight: bold;
  268. }
  269. .default-tags {
  270. margin-left: 15rpx;
  271. display: block;
  272. width: 72rpx;
  273. height: 32rpx;
  274. border-radius: 16rpx;
  275. background-color: #fff3f7;
  276. color: $color-system;
  277. line-height: 32rpx;
  278. text-align: center;
  279. font-size: 22rpx;
  280. }
  281. .tag-left {
  282. flex: 6;
  283. .tag {
  284. width: 280rpx;
  285. height: 40rpx;
  286. font-size: $font-size-26;
  287. color: #999999;
  288. line-height: 40rpx;
  289. .icon-xuanze {
  290. color: $color-system;
  291. font-size: 38rpx;
  292. margin-right: 10rpx;
  293. }
  294. .icon-weixuanze {
  295. color: #999999;
  296. font-size: 38rpx;
  297. margin-right: 10rpx;
  298. }
  299. }
  300. }
  301. .tag-right {
  302. flex: 4;
  303. display: flex;
  304. text-align: right;
  305. .t-b {
  306. flex: 1;
  307. line-height: 40rpx;
  308. .txt {
  309. font-size: $font-size-24;
  310. color: $text-color;
  311. line-height: 40rpx;
  312. }
  313. }
  314. .icon-shanchu {
  315. color: #333333;
  316. margin-right: 8rpx;
  317. }
  318. .icon-bianji {
  319. color: #333333;
  320. margin-right: 8rpx;
  321. }
  322. }
  323. .address {
  324. font-size: $font-size-28;
  325. color: $text-color;
  326. line-height: 40rpx;
  327. -o-text-overflow: ellipsis;
  328. text-overflow: ellipsis;
  329. display: -webkit-box;
  330. word-break: break-all;
  331. -webkit-box-orient: vertical;
  332. -webkit-line-clamp: 2;
  333. overflow: hidden;
  334. }
  335. }
  336. .add-btn {
  337. position: fixed;
  338. left: 24rpx;
  339. right: 24rpx;
  340. bottom: 34rpx;
  341. z-index: 95;
  342. display: flex;
  343. align-items: center;
  344. justify-content: center;
  345. width: 702rpx;
  346. height: 88rpx;
  347. font-size: $font-size-28;
  348. line-height: 88rpx;
  349. color: #ffffff;
  350. text-align: center;
  351. background: $btn-confirm;
  352. border-radius: 45rpx;
  353. }
  354. .adds-btn {
  355. width: 702rpx;
  356. height: 88rpx;
  357. font-size: 28rpx;
  358. line-height: 88rpx;
  359. color: #ffffff;
  360. margin: 0 auto;
  361. text-align: center;
  362. background: #000000;
  363. border-radius: 14rpx;
  364. }
  365. </style>