address.vue 11 KB

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