address-pick.vue 14 KB

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