index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <view class="address" v-if="XCXIsSelect == '是'">
  3. <view class="bg-white radius margin-sm" v-for="(item, index) in list" :key="index">
  4. <view class="content_top" @click="goBack(item)">
  5. <view class="content_part1">
  6. <view class="content_name">{{ item.userName }}</view>
  7. <view class="content_number">
  8. {{ item.userPhone }}
  9. </view>
  10. <view class="content_btn" v-if="item.addressDefault">默认</view>
  11. </view>
  12. <view class="content_part2">{{ item.province }}{{ item.city }}{{ item.district }}{{ item.addressDetail }}</view>
  13. </view>
  14. <!-- 线条 -->
  15. <!-- <u-line color="#c1c1c1" border-style="solid" direction="row"></u-line> -->
  16. <view class="content_bottom">
  17. <view class="bottom_right">
  18. <view class="write" @click.stop="update(item)">
  19. <image src="../static/address/write.png"></image>
  20. </view>
  21. <view class="dete" @click.stop="del(item)">
  22. <image src="../static/address/dete.png"></image>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <empty v-if="list.length == 0"></empty>
  28. <view style="height: 100rpx"></view>
  29. <!-- 添加收货地址 -->
  30. <view class="btn">
  31. <view class="address_push" @click="addAddress">添加收货地址</view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import empty from '@/components/empty.vue'
  37. export default {
  38. components: {
  39. empty
  40. },
  41. data() {
  42. return {
  43. list: [],
  44. checked: false,
  45. page: 1,
  46. limit: 10,
  47. add: 0,
  48. addressType: '',
  49. totalCount: 0,
  50. XCXIsSelect: '是'
  51. }
  52. },
  53. onLoad(option) {
  54. this.XCXIsSelect = this.$queue.getData('XCXIsSelect') ? this.$queue.getData('XCXIsSelect') : '是'
  55. if (this.XCXIsSelect == '否') {
  56. this.getGuize()
  57. uni.setNavigationBarTitle({
  58. title: '隐私政策'
  59. })
  60. } else {
  61. uni.setNavigationBarTitle({
  62. title: '地址管理'
  63. })
  64. }
  65. this.add = option.add ? option.add : 0
  66. if (option.addressType) {
  67. this.addressType = option.addressType
  68. }
  69. },
  70. onShow() {
  71. this.page = 1
  72. this.getAddressList()
  73. },
  74. methods: {
  75. bindOrdersure() {
  76. uni.navigateTo({
  77. url: '/pages/order_sure/order_sure'
  78. })
  79. },
  80. // 添加地址
  81. addAddress() {
  82. uni.navigateTo({
  83. url: '/my/address/add?page=2'
  84. })
  85. },
  86. // 获取地址列表
  87. getAddressList() {
  88. let data = {
  89. page: this.page,
  90. limit: this.limit
  91. }
  92. this.$Request.get('/app/address/selectAddressList', data).then((res) => {
  93. console.log(res)
  94. if (res.code == 0) {
  95. this.totalCount = res.data.totalCount
  96. if (this.page == 1) {
  97. this.list = res.data.list
  98. } else {
  99. this.list = [...this.list, ...res.data.list]
  100. }
  101. }
  102. uni.stopPullDownRefresh()
  103. uni.hideLoading()
  104. })
  105. },
  106. // 设为默认地址
  107. checkboxChange(e) {
  108. console.log(e)
  109. // this.list.forEach(res => {
  110. // if (res.addressId == e.addressId) {
  111. let data = {
  112. addressId: e.addressId,
  113. userName: e.userName,
  114. userPhone: e.userPhone,
  115. address: e.address,
  116. addressDetail: e.addressDetail,
  117. addressDefault: e.addressDefault ? 0 : 1
  118. }
  119. this.$Request.postJson('/app/address/updateAddress', data).then((res) => {
  120. if (res.code == 0) {
  121. this.getAddressList()
  122. }
  123. })
  124. // } else {
  125. // res.addressDefault = 0
  126. // }
  127. // })
  128. },
  129. // 跳转修改
  130. update(e) {
  131. uni.navigateTo({
  132. url: '/my/address/add?id=' + e.addressId
  133. })
  134. },
  135. // 删除地址
  136. del(e) {
  137. let that = this
  138. uni.showModal({
  139. title: '提示',
  140. content: '确认删除吗',
  141. success: function (res) {
  142. if (res.confirm) {
  143. console.log('用户点击确定')
  144. that.$Request
  145. .post('/app/address/deleteAddress', {
  146. addressId: e.addressId
  147. })
  148. .then((res) => {
  149. if (res.code == 0) {
  150. uni.showToast({
  151. title: '删除成功',
  152. icon: 'none'
  153. })
  154. that.page = 1
  155. that.getAddressList()
  156. }
  157. })
  158. } else if (res.cancel) {
  159. console.log('用户点击取消')
  160. }
  161. }
  162. })
  163. },
  164. // 点击地址返回上一页
  165. goBack(e) {
  166. console.log(e)
  167. if (this.add) {
  168. let pages = getCurrentPages()
  169. let prevPage = pages[pages.length - 2]
  170. // 修改上一页面的addressId
  171. // #ifdef MP-WEIXIN
  172. prevPage.$vm._data.addressId = e.addressId
  173. prevPage.$vm._data.addressType = this.addressType
  174. uni.navigateBack()
  175. // #endif
  176. // #ifdef H5
  177. prevPage._data.addressId = e.addressId
  178. prevPage._data.addressType = this.addressType
  179. uni.navigateBack()
  180. // #endif
  181. // #ifdef APP-PLUS
  182. uni.setStorageSync('addressId', e.addressId)
  183. uni.setStorageSync('addressType', this.addressType)
  184. setTimeout(function () {
  185. uni.navigateBack()
  186. }, 10)
  187. // #endif
  188. }
  189. }
  190. },
  191. onReachBottom: function () {
  192. if (this.list.length < this.totalCount) {
  193. this.page = this.page + 1
  194. this.getAddressList()
  195. } else {
  196. uni.showToast({
  197. title: '已经到底了',
  198. icon: 'none'
  199. })
  200. }
  201. },
  202. onPullDownRefresh: function () {
  203. this.page = 1
  204. this.getAddressList()
  205. }
  206. }
  207. </script>
  208. <style>
  209. body {
  210. background-color: #eeeeee;
  211. background-size: cover;
  212. box-sizing: border-box;
  213. }
  214. .address {
  215. width: 100%;
  216. }
  217. .address_content {
  218. width: 100%;
  219. background: #ffffff;
  220. margin-top: 20rpx;
  221. }
  222. .content_top {
  223. width: 90%;
  224. margin: 0 auto;
  225. }
  226. .content_part1 {
  227. font-size: 32rpx;
  228. color: #333333;
  229. display: flex;
  230. align-items: center;
  231. padding-top: 30rpx;
  232. }
  233. .content_name {
  234. font-size: 36rpx;
  235. font-weight: bold;
  236. }
  237. .content_number {
  238. margin-left: 20rpx;
  239. }
  240. .content_btn {
  241. padding: 4rpx 10rpx;
  242. border-radius: 10rpx;
  243. border: 1rpx solid #fcd202;
  244. color: #fcd202;
  245. margin-left: 20rpx;
  246. font-size: 22rpx;
  247. text-align: center;
  248. }
  249. .content_part2 {
  250. color: #999999;
  251. font-size: 28rpx;
  252. margin-top: 20rpx;
  253. margin-bottom: 30rpx;
  254. }
  255. .content_bottom {
  256. display: flex;
  257. width: 90%;
  258. margin: 0 auto;
  259. height: 60rpx;
  260. }
  261. .bottom_left {
  262. flex: 1;
  263. display: flex;
  264. justify-content: left;
  265. align-items: center;
  266. }
  267. .bottom_right {
  268. flex: 1;
  269. position: relative;
  270. display: flex;
  271. justify-content: center;
  272. align-items: center;
  273. }
  274. .write image {
  275. width: 35rpx;
  276. height: 35rpx;
  277. }
  278. .dete image {
  279. width: 35rpx;
  280. height: 35rpx;
  281. }
  282. .write {
  283. position: absolute;
  284. right: 75rpx;
  285. }
  286. .dete {
  287. position: absolute;
  288. right: 0rpx;
  289. }
  290. /* 添加收货地址 */
  291. .btn {
  292. position: fixed;
  293. bottom: 0rpx;
  294. width: 100%;
  295. height: 100rpx;
  296. line-height: 100rpx;
  297. background-color: white;
  298. padding-top: 10rpx;
  299. }
  300. .address_push {
  301. width: 90%;
  302. height: 80rpx;
  303. margin: 0 auto;
  304. background: #fcd202;
  305. border-radius: 20rpx;
  306. color: white;
  307. text-align: center;
  308. line-height: 80rpx;
  309. font-size: 35rpx;
  310. }
  311. </style>