address.vue 8.2 KB

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