index.vue 7.0 KB

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