address-pick.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <app-layout>
  3. <view class="page">
  4. <template v-if="list !== null">
  5. <view v-if="!list.length" class="no-data mb-24">暂无报名信息</view>
  6. <view v-else class="main-center dir-top-nowrap list">
  7. <view v-for="(item,index) in list"
  8. :key="index"
  9. @click="setData(item.id)">
  10. <app-shipping-address @handleAddress="address"
  11. :item="item"
  12. :is_hide_default_btn="true"
  13. :destroy_url="destroy_url"></app-shipping-address>
  14. </view>
  15. </view>
  16. </template>
  17. <view class="dir-left-nowrap add-address-row">
  18. <view class="box-grow-1">
  19. <app-form-id>
  20. <app-button :theme="theme" type="important" round @click="editAddress(0)">
  21. <view class="cross-center main-center">
  22. <image class="icon" src="/static/image/icon/add.png"></image>
  23. <view>新增</view>
  24. </view>
  25. </app-button>
  26. </app-form-id>
  27. </view>
  28. <!-- #ifdef MP-WEIXIN -->
  29. <!-- <view class="box-grow-1">
  30. <app-form-id>
  31. <app-button :theme="theme" type="important" round background="#08c303"
  32. @click="wechatAddAddress">
  33. <view class="cross-center main-center">
  34. <image class="icon" src="/static/image/icon/wechat-white.png"></image>
  35. <view>自动获取</view>
  36. </view>
  37. </app-button>
  38. </app-form-id>
  39. </view> -->
  40. <!-- #endif -->
  41. </view>
  42. <template v-if="notInPointList !== null && notInPointList.length">
  43. <view class="tip">以下地址不在配送范围内,请编辑地址进行定位</view>
  44. <view class="main-center dir-top-nowrap list not-list">
  45. <view v-for="(item,index) in notInPointList"
  46. :key="index"
  47. class="dir-left-nowrap cross-center item">
  48. <view class="box-grow-1 left">
  49. <view class="dir-left-nowrap mb-12">
  50. <view class="box-grow-1">收货人: {{item.name}}</view>
  51. <view class="box-grow-0">{{item.mobile}}</view>
  52. </view>
  53. <view>收货地址: {{item.address}}</view>
  54. </view>
  55. <view class="box-grow-0">
  56. <view class="edit-btn-out" @click.stop="editAddress(item.id)">
  57. <view class="edit-btn">编辑</view>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. </view>
  64. </app-layout>
  65. </template>
  66. <script>
  67. import {mapState} from 'vuex';
  68. import appShippingAddress from '../../components/page-component/app-shipping-address/app-shipping-address.vue';
  69. export default {
  70. name: 'address-pick',
  71. components: {
  72. appShippingAddress,
  73. },
  74. data() {
  75. return {
  76. mchIndex: null,
  77. list: null,
  78. hasCity: false,
  79. notInPointList: null,
  80. sign: '',
  81. page: 1,
  82. noMore: false,
  83. destroy_url: this.$api.user.address_destroy,
  84. };
  85. },
  86. computed: {
  87. ...mapState({
  88. theme: state => state.mallConfig.theme,
  89. }),
  90. },
  91. onLoad(options) {
  92. this.hasCity = options.hasCity;
  93. this.sign = options.sign;
  94. },
  95. onShow() {
  96. this.page = 1;
  97. // #ifdef MP-BAIDU
  98. setTimeout(() => {
  99. this.loadData();
  100. }, 50);
  101. // #endif
  102. // #ifndef MP-BAIDU
  103. this.loadData();
  104. // #endif
  105. },
  106. onReachBottom() {
  107. this.more();
  108. },
  109. methods: {
  110. address(status) {
  111. this.page = 1;
  112. this.loadData();
  113. },
  114. more() {
  115. if (this.noMore) return;
  116. this.page++;
  117. this.loadData('add');
  118. },
  119. loadData(type = 'current') {
  120. uni.showLoading({
  121. mask: true,
  122. title: '加载中',
  123. });
  124. this.$request({
  125. url: this.$api.user.address,
  126. data: {
  127. hasCity: this.hasCity,
  128. page: this.page,
  129. }
  130. }).then(response => {
  131. uni.hideLoading();
  132. if (response.code === 0) {
  133. if (
  134. (!response.data.list || !response.data.list.length)
  135. && (!response.data.notInPointList || !response.data.notInPointList.length)
  136. ) {
  137. this.noMore = true;
  138. }
  139. if (type === 'add') {
  140. this.list = this.list.concat(response.data.list);
  141. } else {
  142. this.list = response.data.list;
  143. }
  144. if (type === 'add') {
  145. this.notInPointList = this.notInPointList.concat(response.data.notInPointList);
  146. } else {
  147. this.notInPointList = response.data.notInPointList;
  148. }
  149. console.log('this.list-->', this.list);
  150. } else {
  151. }
  152. }).catch(e => {
  153. uni.hideLoading();
  154. });
  155. },
  156. setData(data) {
  157. if (this.sign === 'gift') {
  158. let formData = this.$store.state.gift.address_id;
  159. formData = data;
  160. this.$store.commit('gift/addressId', formData);
  161. } else {
  162. const formData = this.$store.state.orderSubmit.formData;
  163. formData.address_id = data;
  164. this.$store.commit('orderSubmit/mutSetFormData', formData);
  165. }
  166. uni.navigateBack();
  167. },
  168. editAddress(id) {
  169. uni.navigateTo({
  170. url: '/pages/address/address-edit?id=' + id,
  171. });
  172. },
  173. wechatAddAddress() {
  174. uni.chooseAddress({
  175. success: (e) => {
  176. console.log(e);
  177. if (e.errMsg !== 'chooseAddress:ok')
  178. return;
  179. this.$request({
  180. url: this.$api.user.wechat_district,
  181. data: {
  182. national_code: e.nationalCode,
  183. province_name: e.provinceName,
  184. city_name: e.cityName,
  185. county_name: e.countyName,
  186. }
  187. }).then(info => {
  188. if (info.code === 0) {
  189. let province_id = info.data.district['province']['id'];
  190. let city_id = info.data.district['city']['id'];
  191. let district_id = info.data.district['district']['id'];
  192. let newAddress = {
  193. id: '',
  194. name: e.userName,
  195. ids: [province_id, city_id, district_id],
  196. province_id: province_id,
  197. city_id: city_id,
  198. district_id: district_id,
  199. mobile: e.telNumber,
  200. detail: e.detailInfo,
  201. };
  202. uni.navigateTo({
  203. url: '/pages/address/address-edit?form=' + JSON.stringify(newAddress)
  204. })
  205. } else {
  206. console.error(info.msg);
  207. }
  208. });
  209. },
  210. });
  211. },
  212. },
  213. }
  214. </script>
  215. <style lang="scss">
  216. page {
  217. background: $uni-weak-color-two;
  218. }
  219. </style>
  220. <style scoped lang="scss">
  221. .mb-12 {
  222. margin-bottom: #{12rpx};
  223. }
  224. .mb-24 {
  225. margin-bottom: #{24rpx};
  226. }
  227. .page {
  228. padding: #{24rpx} 0;
  229. .no-data {
  230. padding: #{100rpx};
  231. text-align: center;
  232. color: $uni-general-color-three;
  233. background: #fff;
  234. border-radius: #{16rpx};
  235. }
  236. }
  237. .list {
  238. margin-bottom: #{48rpx};
  239. .item {
  240. font-size: $uni-font-size-general-one;
  241. background: #fff;
  242. border-radius: #{24rpx};
  243. margin-bottom: #{24rpx};
  244. .left {
  245. padding: #{24rpx};
  246. }
  247. .edit-btn-out {
  248. padding: #{39rpx} 0;
  249. }
  250. .edit-btn {
  251. padding: #{4rpx} #{30rpx};
  252. color: $uni-general-color-two;
  253. border-left: $uni-weak-color-one #{1rpx} solid;
  254. }
  255. }
  256. }
  257. .add-address-row {
  258. margin: 0 -#{12rpx};
  259. padding: 0 #{24rpx};
  260. > view {
  261. padding: 0 #{12rpx};
  262. }
  263. .icon {
  264. width: #{32rpx};
  265. height: #{32rpx};
  266. margin-right: #{12rpx};
  267. }
  268. }
  269. .not-list {
  270. color: $uni-general-color-two;
  271. margin-left: #{24rpx};
  272. margin-right: #{24rpx};
  273. }
  274. .tip {
  275. color: $uni-general-color-one;
  276. margin: #{56rpx 24rpx 20rpx 24rpx};
  277. }
  278. </style>