1
0

address.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <app-layout>
  3. <view class="search">
  4. <view class="prompt dir-left-nowrap main-center cross-center" v-if="search" @click="search = false">
  5. <image src="../../static/image/icon/icon-search.png"></image>
  6. <text>请输入收货人或联系电话搜索</text>
  7. </view>
  8. <view v-else style="position: relative">
  9. <input placeholder="请输入收货人或联系电话搜索" type="text" v-model="keyword" @focus="getFocus=true" focus
  10. @blur="inputBlur"/>
  11. <image v-if="getFocus && keyword.length" @click.stop="keyword = ''" class="search-clear"
  12. src="../../static/image/icon/delete-yuan.png"></image>
  13. </view>
  14. </view>
  15. <view class="head">
  16. <view v-for="(item, index) in list" :key="index">
  17. <app-shipping-address
  18. @handleAddress="address"
  19. :item="item"
  20. :is_refund_address="is_refund_address"
  21. :is_hide_default_btn="is_hide_default_btn == 0"
  22. :destroy_url="destroy_url"
  23. :theme="getTheme"
  24. ></app-shipping-address>
  25. </view>
  26. </view>
  27. <!--空格区域-->
  28. <view class="safe-area-inset-bottom">
  29. <view class="u-bottom-height"></view>
  30. </view>
  31. <view class="safe-area-inset-bottom u-bottom-fixed">
  32. <view class="app-buttons main-between">
  33. <!-- #ifdef MP-ALIPAY -->
  34. <app-button :theme="manual_btn_bg" arrangement="row" @click="manual" type="important" round width="700">
  35. <icon class="app-icon app-manual-icon"></icon>
  36. <text class="app-text">手动添加</text>
  37. </app-button>
  38. <!-- #endif -->
  39. <!-- #ifndef MP-ALIPAY -->
  40. <app-button :theme="manual_btn_bg" arrangement="row" @click="manual" type="important" round width="346">
  41. <icon class="app-icon app-manual-icon"></icon>
  42. <text class="app-text">手动添加</text>
  43. </app-button>
  44. <app-button background="#9999ff" arrangement="row" @click="getauto" type="important" round width="346">
  45. <icon class="app-icon app-auth-icon"></icon>
  46. <text class="app-text">自动获取</text>
  47. </app-button>
  48. <!-- #endif -->
  49. </view>
  50. </view>
  51. </app-layout>
  52. </template>
  53. <script>
  54. import appShippingAddress from '../../components/page-component/app-shipping-address/app-shipping-address.vue';
  55. import {mapGetters} from "vuex";
  56. export default {
  57. name: "address",
  58. components: {
  59. 'app-shipping-address': appShippingAddress,
  60. },
  61. data() {
  62. return {
  63. page: 1,
  64. args: '',
  65. load: '',
  66. allList: [],
  67. manual_btn_bg: '',
  68. is_refund_address: 0,
  69. is_hide_default_btn: 0,
  70. address_url: '',
  71. destroy_url: '',
  72. keyword: '',
  73. search: true,
  74. getFocus: false,
  75. }
  76. },
  77. computed: {
  78. ...mapGetters('mallConfig', {
  79. getTheme: 'getTheme',
  80. }),
  81. list() {
  82. const allList = this.allList;
  83. const newVal = this.keyword;
  84. return allList.filter(item => {
  85. let regExp = new RegExp(newVal);
  86. return regExp.test(item.mobile) || regExp.test(item.name);
  87. })
  88. },
  89. },
  90. onLoad: function (options) {
  91. this.is_hide_default_btn = options.is_hide_default_btn ? options.is_hide_default_btn : 0;
  92. this.is_refund_address = options.is_refund_address ? options.is_refund_address : 0;
  93. this.manual_btn_bg = options.manual_btn_bg ? options.manual_btn_bg : this.getTheme;
  94. if (this.is_refund_address > 0) {
  95. this.address_url = this.$api.app_admin.refund_address;
  96. this.destroy_url = this.$api.app_admin.address_destroy;
  97. uni.setNavigationBarTitle({
  98. title: '退货地址'
  99. })
  100. } else {
  101. this.address_url = this.$api.user.address;
  102. this.destroy_url = this.$api.user.address_destroy;
  103. }
  104. //#ifdef MP-BAIDU
  105. this.init();
  106. //#endif
  107. },
  108. onShow: function () {
  109. this.init();
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. const self = this;
  116. if (self.args || self.load)
  117. return;
  118. self.load = true;
  119. let page = self.page + 1;
  120. this.$request({
  121. url: self.$api.user.address,
  122. data: {
  123. page: page,
  124. }
  125. }).then(info => {
  126. if (info.code === 0) {
  127. [self.page, self.args, self.allList] = [page, info.data.allList.length === 0, self.allList.concat(info.data.list)];
  128. }
  129. self.load = false;
  130. });
  131. },
  132. methods: {
  133. inputBlur() {
  134. let that = this;
  135. setTimeout(v => {
  136. that.getFocus = false;
  137. if (that.keyword === '') that.search = true;
  138. }, 300)
  139. },
  140. init() {
  141. const self = this;
  142. if (!self.address_url) return;
  143. uni.showLoading({
  144. title: '加载中'
  145. });
  146. self.page = 1;
  147. self.$request({
  148. url: self.address_url,
  149. }).then(info => {
  150. uni.hideLoading();
  151. if (info.code === 0) {
  152. [self.page, self.allList] = [1, info.data.list];
  153. }
  154. }).catch(() => {
  155. uni.hideLoading();
  156. });
  157. },
  158. address() {
  159. this.init();
  160. },
  161. manual() {
  162. uni.navigateTo({
  163. url: '/pages/address/address-edit?is_refund_address=' + this.is_refund_address,
  164. });
  165. },
  166. getauto() {
  167. //#ifndef MP-ALIPAY
  168. const self = this;
  169. uni.chooseAddress({
  170. success: function (e) {
  171. self.$request({
  172. url: self.$api.user.wechat_district,
  173. data: {
  174. national_code: e.nationalCode,
  175. province_name: e.provinceName,
  176. city_name: e.cityName,
  177. county_name: e.countyName,
  178. }
  179. }).then(info => {
  180. if (info.code === 0) {
  181. let province_id = info.data.district['province']['id'];
  182. let city_id = info.data.district['city']['id'];
  183. let district_id = info.data.district['district']['id'];
  184. let newAddress = {
  185. id: '',
  186. name: e.userName,
  187. ids: [province_id, city_id, district_id],
  188. province_id: province_id,
  189. city_id: city_id,
  190. district_id: district_id,
  191. mobile: e.telNumber,
  192. detail: e.detailInfo,
  193. };
  194. uni.navigateTo({
  195. url: '/pages/address/address-edit?form=' + JSON.stringify(newAddress) + '&is_refund_address=' + self.is_refund_address
  196. })
  197. }
  198. });
  199. }
  200. }
  201. );
  202. //#endif
  203. }
  204. },
  205. }
  206. </script>
  207. <style scoped lang="scss">
  208. .head {
  209. margin-top: #{100rpx};
  210. background: $uni-weak-color-two;
  211. }
  212. .search {
  213. width: #{750rpx};
  214. height: #{88rpx};
  215. padding: #{16rpx} #{24rpx};
  216. box-sizing: border-box;
  217. background-color: #efeff4;
  218. top: var(--window-top);
  219. position: fixed;
  220. left: 0;
  221. z-index: 23;
  222. .prompt {
  223. width: #{702rpx};
  224. height: #{56rpx};
  225. position: absolute;
  226. border-radius: #{28rpx};
  227. background-color: #ffffff;
  228. > image {
  229. width: #{26rpx};
  230. height: #{26rpx};
  231. }
  232. > text {
  233. color: #b2b2b2;
  234. font-size: #{26rpx};
  235. margin: #{0 10rpx};
  236. }
  237. }
  238. input {
  239. width: #{702rpx};
  240. height: #{56rpx};
  241. border-radius: #{28rpx};
  242. background-color: #ffffff;
  243. padding: #{0 70rpx 0 30rpx};
  244. box-sizing: border-box;
  245. font-size: #{26rpx};
  246. }
  247. .search-clear {
  248. position: absolute;
  249. right: #{15rpx};
  250. top: #{14rpx};
  251. width: #{30rpx};
  252. height: #{30rpx};
  253. z-index: 300;
  254. }
  255. }
  256. .app-buttons {
  257. height: 128upx;
  258. padding: 24upx 24upx;
  259. .app-icon {
  260. width: #{32rpx};
  261. height: #{32rpx};
  262. background-repeat: no-repeat;
  263. background-size: 100% 100%;
  264. margin-right: #{8rpx};
  265. }
  266. .app-manual-icon {
  267. background-image: url("./image/add.png");
  268. }
  269. .app-auth-icon {
  270. background-image: url("./image/auth.png");
  271. }
  272. .app-text {
  273. font-size: #{28rpx};
  274. color: #ffffff;
  275. margin-left: #{8rpx};
  276. }
  277. }
  278. .u-bottom-fixed {
  279. position: fixed;
  280. bottom: 0;
  281. left: 0;
  282. width: 100%;
  283. z-index: 1500;
  284. }
  285. .u-bottom-height {
  286. height: 128upx;
  287. }
  288. </style>