address-pick.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <app-layout>
  3. <view class="page">
  4. <view class="search">
  5. <view class="prompt dir-left-nowrap main-center cross-center" v-if="search" @click="search = false">
  6. <image src="https://shop.9026.com/web/statics/image/mall/static/icon/icon-search.png"></image>
  7. <text>请输入收货人或联系电话搜索</text>
  8. </view>
  9. <view v-else style="position: relative">
  10. <input placeholder="请输入收货人或联系电话搜索" type="text" v-model="keyword" @focus="getFocus=true" focus
  11. @blur="inputBlur"/>
  12. <image v-if="getFocus && keyword.length" @click.stop="keyword = ''" class="search-clear"
  13. src="https://shop.9026.com/web/statics/image/mall/static/icon/delete-yuan.png"></image>
  14. </view>
  15. </view>
  16. <template v-if="list !== null">
  17. <view v-if="!list.length" class="no-data mb-24">暂无有效地址信息</view>
  18. <view v-else class="main-center dir-top-nowrap list">
  19. <view v-for="(item,index) in list"
  20. :key="index"
  21. @click="setData(item.id,item.address)">
  22. <app-shipping-address @handleAddress="address"
  23. :item="item"
  24. :theme="getTheme"
  25. :is_hide_default_btn="true"
  26. :destroy_url="destroy_url"
  27. :type="type"
  28. ></app-shipping-address>
  29. </view>
  30. </view>
  31. </template>
  32. <!--空格区域-->
  33. <view class="safe-area-inset-bottom">
  34. <view class="u-bottom-height"></view>
  35. </view>
  36. <view class="safe-area-inset-bottom u-bottom-fixed">
  37. <view class="dir-left-nowrap add-address-row" v-if="list !== null">
  38. <view class="box-grow-1">
  39. <app-form-id>
  40. <app-button :theme="getTheme" type="important" round @click="editAddress(0)">
  41. <view class="cross-center main-center">
  42. <image class="icon" src="https://shop.9026.com/web/statics/image/mall/static/icon/add.png"></image>
  43. <view>手动添加</view>
  44. </view>
  45. </app-button>
  46. </app-form-id>
  47. </view>
  48. <!-- #ifdef MP-WEIXIN -->
  49. <view class="box-grow-1" v-if="type === 0">
  50. <app-form-id>
  51. <app-button type="important" round background="#08c303"
  52. @click="wechatAddAddress">
  53. <view class="cross-center main-center">
  54. <image class="icon" src="https://shop.9026.com/web/statics/image/mall/static/icon/wechat-white.png"></image>
  55. <view>自动获取</view>
  56. </view>
  57. </app-button>
  58. </app-form-id>
  59. </view>
  60. <!-- #endif -->
  61. </view>
  62. </view>
  63. <template v-if="notInPointList !== null && notInPointList.length">
  64. <view class="tip">以下地址不在配送范围内,请编辑地址进行定位</view>
  65. <view class="main-center dir-top-nowrap list not-list">
  66. <view v-for="(item,index) in notInPointList"
  67. :key="index"
  68. class="dir-left-nowrap cross-center item">
  69. <view class="box-grow-1 left">
  70. <view class="dir-left-nowrap mb-12">
  71. <view class="box-grow-1">收货人: {{item.name}}</view>
  72. <view class="box-grow-0">{{item.mobile}}</view>
  73. </view>
  74. <view>收货地址: {{item.address}}</view>
  75. </view>
  76. <view class="box-grow-0">
  77. <view class="edit-btn-out" @click.stop="editAddress(item.id)">
  78. <view class="edit-btn">编辑</view>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. </template>
  84. <!--手动添加区域-->
  85. <view style="height: 130rpx"></view>
  86. </view>
  87. </app-layout>
  88. </template>
  89. <script>
  90. import {mapGetters} from 'vuex';
  91. import appShippingAddress from '../../components/page-component/app-shipping-address/app-shipping-address.vue';
  92. export default {
  93. name: 'address-pick',
  94. components: {
  95. appShippingAddress,
  96. },
  97. data() {
  98. return {
  99. mchIndex: null,
  100. allList: [],
  101. notInPointList: null,
  102. sign: '',
  103. page: 1,
  104. noMore: false,
  105. destroy_url: this.$api.user.address_destroy,
  106. keyword: '',
  107. search: true,
  108. getFocus: false,
  109. type: 0,
  110. };
  111. },
  112. computed: {
  113. ...mapGetters('mallConfig', {
  114. getTheme: 'getTheme',
  115. }),
  116. ...mapGetters('user', {
  117. getIsEnterSales: 'getIsEnterSales'
  118. }),
  119. list() {
  120. const allList = this.allList;
  121. const newVal = this.keyword;
  122. return allList.filter(item => {
  123. let regExp = new RegExp(newVal);
  124. return regExp.test(item.mobile) || regExp.test(item.name);
  125. })
  126. },
  127. },
  128. onLoad(options) { this.$commonLoad.onload(options);
  129. this.type = options.hasCity === `true` ? 1 : 0;
  130. this.sign = options.sign;
  131. },
  132. onShow() {
  133. if(this.getIsEnterSales){
  134. this.$store.commit('user/isOrderBehalfBustomers', true)
  135. }
  136. this.page = 1;
  137. // #ifdef MP-BAIDU
  138. setTimeout(() => {
  139. this.loadData();
  140. }, 50);
  141. // #endif
  142. // #ifndef MP-BAIDU
  143. this.loadData();
  144. // #endif
  145. },
  146. methods: {
  147. inputBlur() {
  148. let that = this;
  149. setTimeout(v => {
  150. that.getFocus = false;
  151. if (that.keyword === '') that.search = true;
  152. }, 300)
  153. },
  154. address(status) {
  155. this.page = 1;
  156. this.loadData();
  157. },
  158. more() {
  159. if (this.noMore) return;
  160. this.page++;
  161. this.loadData('add');
  162. },
  163. loadData(type = 'current') {
  164. uni.showLoading({
  165. mask: true,
  166. title: '加载中',
  167. });
  168. this.$request({
  169. url: this.$api.user.address,
  170. data: {
  171. type: this.type,
  172. page: this.page,
  173. }
  174. }).then(response => {
  175. uni.hideLoading();
  176. if (response.code === 0) {
  177. if (
  178. (!response.data.list || !response.data.list.length)
  179. && (!response.data.notInPointList || !response.data.notInPointList.length)
  180. ) {
  181. this.noMore = true;
  182. }
  183. if (type === 'add') {
  184. this.allList = this.list.concat(response.data.list);
  185. this.notInPointList = this.notInPointList.concat(response.data.notInPointList);
  186. } else {
  187. this.allList = response.data.list;
  188. this.notInPointList = response.data.notInPointList;
  189. }
  190. }
  191. }).catch(() => {
  192. uni.hideLoading();
  193. });
  194. },
  195. setData(data,address) {
  196. if (this.sign === 'gift') {
  197. let formData = this.$store.state.gift.address_id;
  198. formData = data;
  199. this.$store.commit('gift/addressId', formData);
  200. }else if(this.sign === 'invoice'){//选择发票地址
  201. let invoice_info={}
  202. if(this.$storage.getStorageSync('invoice_info')){
  203. invoice_info=this.$storage.getStorageSync('invoice_info')
  204. }
  205. invoice_info.user_address_id=data
  206. invoice_info.delivery_address=address
  207. this.$storage.setStorageSync('invoice_info', invoice_info);
  208. } else {
  209. const formData = this.$store.state.orderSubmit.formData;
  210. if (this.type === 1) {
  211. formData.list[0].address_id = data;
  212. } else {
  213. formData.address_id = data;
  214. }
  215. this.$store.commit('orderSubmit/mutSetFormData', formData);
  216. }
  217. uni.navigateBack();
  218. },
  219. editAddress(id) {
  220. uni.navigateTo({
  221. url: '/pages/address/address-edit?id=' + id + '&type=' + this.type,
  222. });
  223. },
  224. wechatAddAddress() {
  225. uni.chooseAddress({
  226. success: (e) => {
  227. if (e.errMsg !== 'chooseAddress:ok')
  228. return;
  229. this.$request({
  230. url: this.$api.user.wechat_district,
  231. data: {
  232. national_code: e.nationalCode,
  233. province_name: e.provinceName,
  234. city_name: e.cityName,
  235. county_name: e.countyName,
  236. }
  237. }).then(info => {
  238. if (info.code === 0) {
  239. let province_id = info.data.district['province']['id'];
  240. let city_id = info.data.district['city']['id'];
  241. let district_id = info.data.district['district']['id'];
  242. let newAddress = {
  243. id: '',
  244. name: e.userName,
  245. ids: [province_id, city_id, district_id],
  246. province_id: province_id,
  247. city_id: city_id,
  248. district_id: district_id,
  249. mobile: e.telNumber,
  250. detail: e.detailInfo,
  251. type: 0,
  252. };
  253. uni.navigateTo({
  254. url: '/pages/address/address-edit?form=' + JSON.stringify(newAddress)
  255. })
  256. }
  257. });
  258. },
  259. });
  260. },
  261. },
  262. }
  263. </script>
  264. <style lang="scss">
  265. page {
  266. background: $uni-weak-color-two;
  267. }
  268. </style>
  269. <style scoped lang="scss">
  270. .mb-12 {
  271. margin-bottom: #{12rpx};
  272. }
  273. .mb-24 {
  274. margin-bottom: #{24rpx};
  275. }
  276. .page {
  277. //padding: #{24rpx} 0;
  278. .no-data {
  279. padding: #{100rpx};
  280. text-align: center;
  281. margin-top: 88upx;
  282. color: $uni-general-color-three;
  283. background: #fff;
  284. border-radius: #{16rpx};
  285. }
  286. }
  287. .search {
  288. width: #{750rpx};
  289. height: #{88rpx};
  290. padding: #{16rpx} #{24rpx};
  291. box-sizing: border-box;
  292. background-color: #efeff4;
  293. position: fixed;
  294. top: 0;
  295. left: 0;
  296. z-index: 1000;
  297. .prompt {
  298. width: #{702rpx};
  299. height: #{56rpx};
  300. position: absolute;
  301. border-radius: #{28rpx};
  302. background-color: #ffffff;
  303. > image {
  304. width: #{26rpx};
  305. height: #{26rpx};
  306. }
  307. > text {
  308. color: #b2b2b2;
  309. font-size: #{26rpx};
  310. margin: #{0 10rpx};
  311. }
  312. }
  313. input {
  314. width: #{702rpx};
  315. height: #{56rpx};
  316. border-radius: #{28rpx};
  317. background-color: #ffffff;
  318. padding: #{0 70rpx 0 30rpx};
  319. box-sizing: border-box;
  320. font-size: #{26rpx};
  321. }
  322. .search-clear {
  323. position: absolute;
  324. right: #{15rpx};
  325. top: #{14rpx};
  326. width: #{30rpx};
  327. height: #{30rpx};
  328. z-index: 300;
  329. }
  330. }
  331. .list {
  332. margin-top: #{60rpx};
  333. //margin-bottom: #{48rpx};
  334. .item {
  335. font-size: $uni-font-size-general-one;
  336. background: #fff;
  337. border-radius: #{24rpx};
  338. margin-bottom: #{24rpx};
  339. .left {
  340. padding: #{24rpx};
  341. }
  342. .edit-btn-out {
  343. padding: #{39rpx} 0;
  344. }
  345. .edit-btn {
  346. padding: #{4rpx} #{30rpx};
  347. color: $uni-general-color-two;
  348. border-left: $uni-weak-color-one #{1rpx} solid;
  349. }
  350. }
  351. }
  352. .add-address-row {
  353. margin-bottom: 50rpx;
  354. > view {
  355. padding: 0 #{12rpx};
  356. }
  357. .icon {
  358. width: #{32rpx};
  359. height: #{32rpx};
  360. margin-right: #{12rpx};
  361. }
  362. }
  363. .not-list {
  364. color: $uni-general-color-two;
  365. margin-left: #{24rpx};
  366. margin-right: #{24rpx};
  367. }
  368. .tip {
  369. color: $uni-general-color-one;
  370. margin: #{0 24rpx 20rpx 24rpx};
  371. }
  372. .u-bottom-fixed {
  373. position: fixed;
  374. bottom: 0;
  375. left: 0;
  376. width: 100%;
  377. z-index: 1500;
  378. }
  379. .u-bottom-height {
  380. height: 120upx;
  381. }
  382. </style>