address.vue 8.7 KB

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