1
0

address-pick.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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="../../static/image/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="../../static/image/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)">
  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="/static/image/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="/static/image/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. </view>
  85. </app-layout>
  86. </template>
  87. <script>
  88. import {mapGetters} from 'vuex';
  89. import appShippingAddress from '../../components/page-component/app-shipping-address/app-shipping-address.vue';
  90. export default {
  91. name: 'address-pick',
  92. components: {
  93. appShippingAddress,
  94. },
  95. data() {
  96. return {
  97. mchIndex: null,
  98. allList: [],
  99. notInPointList: null,
  100. sign: '',
  101. page: 1,
  102. noMore: false,
  103. destroy_url: this.$api.user.address_destroy,
  104. keyword: '',
  105. search: true,
  106. getFocus: false,
  107. type: 0,
  108. };
  109. },
  110. computed: {
  111. ...mapGetters('mallConfig', {
  112. getTheme: 'getTheme',
  113. }),
  114. list() {
  115. const allList = this.allList;
  116. const newVal = this.keyword;
  117. return allList.filter(item => {
  118. let regExp = new RegExp(newVal);
  119. return regExp.test(item.mobile) || regExp.test(item.name);
  120. })
  121. },
  122. },
  123. onLoad(options) {
  124. this.type = options.hasCity === `true` ? 1 : 0;
  125. this.sign = options.sign;
  126. },
  127. onShow() {
  128. this.page = 1;
  129. // #ifdef MP-BAIDU
  130. setTimeout(() => {
  131. this.loadData();
  132. }, 50);
  133. // #endif
  134. // #ifndef MP-BAIDU
  135. this.loadData();
  136. // #endif
  137. },
  138. methods: {
  139. inputBlur() {
  140. let that = this;
  141. setTimeout(v => {
  142. that.getFocus = false;
  143. if (that.keyword === '') that.search = true;
  144. }, 300)
  145. },
  146. address(status) {
  147. this.page = 1;
  148. this.loadData();
  149. },
  150. more() {
  151. if (this.noMore) return;
  152. this.page++;
  153. this.loadData('add');
  154. },
  155. loadData(type = 'current') {
  156. uni.showLoading({
  157. mask: true,
  158. title: '加载中',
  159. });
  160. this.$request({
  161. url: this.$api.user.address,
  162. data: {
  163. type: this.type,
  164. page: this.page,
  165. }
  166. }).then(response => {
  167. uni.hideLoading();
  168. if (response.code === 0) {
  169. if (
  170. (!response.data.list || !response.data.list.length)
  171. && (!response.data.notInPointList || !response.data.notInPointList.length)
  172. ) {
  173. this.noMore = true;
  174. }
  175. if (type === 'add') {
  176. this.allList = this.list.concat(response.data.list);
  177. this.notInPointList = this.notInPointList.concat(response.data.notInPointList);
  178. } else {
  179. this.allList = response.data.list;
  180. this.notInPointList = response.data.notInPointList;
  181. }
  182. }
  183. }).catch(() => {
  184. uni.hideLoading();
  185. });
  186. },
  187. setData(data) {
  188. if (this.sign === 'gift') {
  189. let formData = this.$store.state.gift.address_id;
  190. formData = data;
  191. this.$store.commit('gift/addressId', formData);
  192. } else {
  193. const formData = this.$store.state.orderSubmit.formData;
  194. if (this.type === 1) {
  195. formData.list[0].address_id = data;
  196. } else {
  197. formData.address_id = data;
  198. }
  199. this.$store.commit('orderSubmit/mutSetFormData', formData);
  200. }
  201. uni.navigateBack();
  202. },
  203. editAddress(id) {
  204. uni.navigateTo({
  205. url: '/pages/address/address-edit?id=' + id + '&type=' + this.type,
  206. });
  207. },
  208. wechatAddAddress() {
  209. uni.chooseAddress({
  210. success: (e) => {
  211. if (e.errMsg !== 'chooseAddress:ok')
  212. return;
  213. this.$request({
  214. url: this.$api.user.wechat_district,
  215. data: {
  216. national_code: e.nationalCode,
  217. province_name: e.provinceName,
  218. city_name: e.cityName,
  219. county_name: e.countyName,
  220. }
  221. }).then(info => {
  222. if (info.code === 0) {
  223. let province_id = info.data.district['province']['id'];
  224. let city_id = info.data.district['city']['id'];
  225. let district_id = info.data.district['district']['id'];
  226. let newAddress = {
  227. id: '',
  228. name: e.userName,
  229. ids: [province_id, city_id, district_id],
  230. province_id: province_id,
  231. city_id: city_id,
  232. district_id: district_id,
  233. mobile: e.telNumber,
  234. detail: e.detailInfo,
  235. type: 0,
  236. };
  237. uni.navigateTo({
  238. url: '/pages/address/address-edit?form=' + JSON.stringify(newAddress)
  239. })
  240. }
  241. });
  242. },
  243. });
  244. },
  245. },
  246. }
  247. </script>
  248. <style lang="scss">
  249. page {
  250. background: $uni-weak-color-two;
  251. }
  252. </style>
  253. <style scoped lang="scss">
  254. .mb-12 {
  255. margin-bottom: #{12rpx};
  256. }
  257. .mb-24 {
  258. margin-bottom: #{24rpx};
  259. }
  260. .page {
  261. padding: #{24rpx} 0;
  262. .no-data {
  263. padding: #{100rpx};
  264. text-align: center;
  265. color: $uni-general-color-three;
  266. background: #fff;
  267. border-radius: #{16rpx};
  268. }
  269. }
  270. .search {
  271. width: #{750rpx};
  272. height: #{88rpx};
  273. padding: #{16rpx} #{24rpx};
  274. box-sizing: border-box;
  275. background-color: #efeff4;
  276. position: fixed;
  277. top: 0;
  278. left: 0;
  279. z-index: 1000;
  280. .prompt {
  281. width: #{702rpx};
  282. height: #{56rpx};
  283. position: absolute;
  284. border-radius: #{28rpx};
  285. background-color: #ffffff;
  286. > image {
  287. width: #{26rpx};
  288. height: #{26rpx};
  289. }
  290. > text {
  291. color: #b2b2b2;
  292. font-size: #{26rpx};
  293. margin: #{0 10rpx};
  294. }
  295. }
  296. input {
  297. width: #{702rpx};
  298. height: #{56rpx};
  299. border-radius: #{28rpx};
  300. background-color: #ffffff;
  301. padding: #{0 70rpx 0 30rpx};
  302. box-sizing: border-box;
  303. font-size: #{26rpx};
  304. }
  305. .search-clear {
  306. position: absolute;
  307. right: #{15rpx};
  308. top: #{14rpx};
  309. width: #{30rpx};
  310. height: #{30rpx};
  311. z-index: 300;
  312. }
  313. }
  314. .list {
  315. margin-top: #{60rpx};
  316. margin-bottom: #{48rpx};
  317. .item {
  318. font-size: $uni-font-size-general-one;
  319. background: #fff;
  320. border-radius: #{24rpx};
  321. margin-bottom: #{24rpx};
  322. .left {
  323. padding: #{24rpx};
  324. }
  325. .edit-btn-out {
  326. padding: #{39rpx} 0;
  327. }
  328. .edit-btn {
  329. padding: #{4rpx} #{30rpx};
  330. color: $uni-general-color-two;
  331. border-left: $uni-weak-color-one #{1rpx} solid;
  332. }
  333. }
  334. }
  335. .add-address-row {
  336. margin-bottom: 50rpx;
  337. > view {
  338. padding: 0 #{12rpx};
  339. }
  340. .icon {
  341. width: #{32rpx};
  342. height: #{32rpx};
  343. margin-right: #{12rpx};
  344. }
  345. }
  346. .not-list {
  347. color: $uni-general-color-two;
  348. margin-left: #{24rpx};
  349. margin-right: #{24rpx};
  350. }
  351. .tip {
  352. color: $uni-general-color-one;
  353. margin: #{56rpx 24rpx 20rpx 24rpx};
  354. }
  355. .u-bottom-fixed {
  356. position: fixed;
  357. bottom: 0;
  358. left: 0;
  359. width: 100%;
  360. z-index: 1500;
  361. }
  362. .u-bottom-height {
  363. height: 130upx;
  364. }
  365. </style>