address.vue 8.6 KB

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