address.vue 8.4 KB

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