address.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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.GetAddressList()
  209. })
  210. .catch(err => {
  211. this.GetAddressList()
  212. })
  213. }
  214. },
  215. onPullDownRefresh() {
  216. //下拉刷新
  217. this.listQuery.pageNum = 1
  218. this.GetAddressList()
  219. uni.stopPullDownRefresh()
  220. },
  221. onReachBottom() {
  222. console.log("用户把这个页面上拉100时触发我的")
  223. if (this.hasNextPage) {
  224. this.GetOnReachBottomAddressList()
  225. }
  226. },
  227. onShow() {
  228. this.pageNum = 1
  229. this.addressList = []
  230. this.GetAddressList()
  231. },
  232. }
  233. </script>
  234. <style lang="scss">
  235. page {
  236. height: auto;
  237. }
  238. page,
  239. .container {
  240. /* padding-bottom: 120upx; */
  241. background: #f7f7f7;
  242. border-top: 1px solid #ebebeb;
  243. }
  244. .container {
  245. position: relative;
  246. }
  247. .list {
  248. display: flex;
  249. align-items: center;
  250. width: 702rpx;
  251. height: auto;
  252. padding: 24rpx;
  253. background: #ffffff;
  254. position: relative;
  255. margin-bottom: 20rpx;
  256. }
  257. .wrapper {
  258. display: flex;
  259. flex-direction: column;
  260. flex: 1;
  261. }
  262. .u-box .label {
  263. color: #999999;
  264. }
  265. .u-box.b-b {
  266. margin-bottom: 24rpx;
  267. }
  268. .u-box.b-t {
  269. margin-bottom: 0;
  270. }
  271. .u-box {
  272. display: flex;
  273. align-items: center;
  274. font-size: $font-size-26;
  275. color: $text-color;
  276. line-height: 40rpx;
  277. margin-bottom: 12rpx;
  278. .name {
  279. margin-right: 40rpx;
  280. font-weight: bold;
  281. }
  282. .mobile {
  283. font-weight: bold;
  284. }
  285. .default-tags {
  286. margin-left: 15rpx;
  287. display: block;
  288. width: 72rpx;
  289. height: 32rpx;
  290. border-radius: 16rpx;
  291. background-color: #fff3f7;
  292. color: $color-system;
  293. line-height: 32rpx;
  294. text-align: center;
  295. font-size: 22rpx;
  296. }
  297. .tag-left {
  298. flex: 6;
  299. .tag {
  300. width: 280rpx;
  301. height: 40rpx;
  302. font-size: $font-size-26;
  303. color: #999999;
  304. line-height: 40rpx;
  305. .icon-xuanze {
  306. color: $color-system;
  307. font-size: 38rpx;
  308. margin-right: 10rpx;
  309. }
  310. .icon-weixuanze {
  311. color: #999999;
  312. font-size: 38rpx;
  313. margin-right: 10rpx;
  314. }
  315. }
  316. }
  317. .tag-right {
  318. flex: 4;
  319. display: flex;
  320. text-align: right;
  321. .t-b {
  322. flex: 1;
  323. line-height: 40rpx;
  324. .txt {
  325. font-size: $font-size-24;
  326. color: $text-color;
  327. line-height: 40rpx;
  328. }
  329. }
  330. .icon-shanchu {
  331. color: #333333;
  332. margin-right: 8rpx;
  333. }
  334. .icon-bianji {
  335. color: #333333;
  336. margin-right: 8rpx;
  337. }
  338. }
  339. .address {
  340. font-size: $font-size-28;
  341. color: $text-color;
  342. line-height: 40rpx;
  343. -o-text-overflow: ellipsis;
  344. text-overflow: ellipsis;
  345. display: -webkit-box;
  346. word-break: break-all;
  347. -webkit-box-orient: vertical;
  348. -webkit-line-clamp: 2;
  349. overflow: hidden;
  350. }
  351. }
  352. .add-btn {
  353. position: fixed;
  354. left: 24rpx;
  355. right: 24rpx;
  356. bottom: 34rpx;
  357. z-index: 95;
  358. display: flex;
  359. align-items: center;
  360. justify-content: center;
  361. width: 702rpx;
  362. height: 88rpx;
  363. font-size: $font-size-28;
  364. line-height: 88rpx;
  365. color: #ffffff;
  366. text-align: center;
  367. background: $btn-confirm;
  368. border-radius: 45rpx;
  369. }
  370. .adds-btn {
  371. width: 702rpx;
  372. height: 88rpx;
  373. font-size: 28rpx;
  374. line-height: 88rpx;
  375. color: #ffffff;
  376. margin: 0 auto;
  377. text-align: center;
  378. background: #000000;
  379. border-radius: 14rpx;
  380. }
  381. </style>