address.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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="manual_btn_bg"
  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 || H5 -->
  34. <app-button :theme="manual_btn_bg" arrangement="row" @click="manual" type="important" round width="700">
  35. <icon class="app-icon app-manual-icon" type></icon>
  36. <text class="app-text">手动添加</text>
  37. </app-button>
  38. <!-- #endif -->
  39. <!-- #ifndef MP-ALIPAY || H5 -->
  40. <app-button :theme="manual_btn_bg" arrangement="row" @click="manual" type="important" round width="346">
  41. <icon class="app-icon app-manual-icon" type></icon>
  42. <text class="app-text">手动添加</text>
  43. </app-button>
  44. <app-button background="#08c303" arrangement="row" @click="getauto" type="important" round width="346">
  45. <icon class="app-icon app-auth-icon" type></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: null,
  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(options) { this.$commonLoad.onload(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. if(options.manual_btn_bg && options.manual_btn_bg == 'admin') {
  94. this.manual_btn_bg = {
  95. background: '#446dfd',
  96. color: '#446dfd',
  97. }
  98. }else {
  99. this.manual_btn_bg = options.manual_btn_bg ? options.manual_btn_bg : this.getTheme;
  100. }
  101. if (this.is_refund_address > 0) {
  102. this.address_url = this.$api.app_admin.refund_address;
  103. this.destroy_url = this.$api.app_admin.address_destroy;
  104. uni.setNavigationBarTitle({
  105. title: '退货地址'
  106. })
  107. } else {
  108. this.address_url = this.$api.user.address;
  109. this.destroy_url = this.$api.user.address_destroy;
  110. }
  111. //#ifdef MP-BAIDU
  112. this.init();
  113. //#endif
  114. },
  115. onShow: function () {
  116. this.init();
  117. },
  118. /**
  119. * 页面上拉触底事件的处理函数
  120. */
  121. onReachBottom: function () {
  122. const self = this;
  123. if (self.args || self.load)
  124. return;
  125. self.load = true;
  126. let page = self.page + 1;
  127. this.$request({
  128. url: self.$api.user.address,
  129. data: {
  130. page: page,
  131. }
  132. }).then(info => {
  133. if (info.code === 0) {
  134. [self.page, self.args, self.allList] = [page, info.data.allList.length === 0, self.allList.concat(info.data.list)];
  135. }
  136. self.load = false;
  137. });
  138. },
  139. methods: {
  140. inputBlur() {
  141. let that = this;
  142. setTimeout(v => {
  143. that.getFocus = false;
  144. if (that.keyword === '') that.search = true;
  145. }, 300)
  146. },
  147. init() {
  148. const self = this;
  149. if (!self.address_url) return;
  150. uni.showLoading({
  151. title: '加载中'
  152. });
  153. self.page = 1;
  154. self.$request({
  155. url: self.address_url,
  156. }).then(info => {
  157. uni.hideLoading();
  158. if (info.code === 0) {
  159. [self.page, self.allList] = [1, info.data.list];
  160. }
  161. }).catch(() => {
  162. uni.hideLoading();
  163. });
  164. },
  165. address() {
  166. this.init();
  167. },
  168. manual() {
  169. uni.navigateTo({
  170. url: '/pages/address/address-edit?is_refund_address=' + this.is_refund_address,
  171. });
  172. },
  173. getauto() {
  174. //#ifndef MP-ALIPAY
  175. const self = this;
  176. uni.chooseAddress({
  177. success: function (e) {
  178. self.$request({
  179. url: self.$api.user.wechat_district,
  180. data: {
  181. national_code: e.nationalCode,
  182. province_name: e.provinceName,
  183. city_name: e.cityName,
  184. county_name: e.countyName,
  185. }
  186. }).then(info => {
  187. if (info.code === 0) {
  188. let province_id = info.data.district['province']['id'];
  189. let city_id = info.data.district['city']['id'];
  190. let district_id = info.data.district['district']['id'];
  191. let newAddress = {
  192. id: '',
  193. name: e.userName,
  194. ids: [province_id, city_id, district_id],
  195. province_id: province_id,
  196. city_id: city_id,
  197. district_id: district_id,
  198. mobile: e.telNumber,
  199. detail: e.detailInfo,
  200. };
  201. uni.navigateTo({
  202. url: '/pages/address/address-edit?form=' + JSON.stringify(newAddress) + '&is_refund_address=' + self.is_refund_address
  203. })
  204. }
  205. });
  206. }
  207. }
  208. );
  209. //#endif
  210. }
  211. },
  212. }
  213. </script>
  214. <style scoped lang="scss">
  215. .head {
  216. margin-top: #{100rpx};
  217. background: $uni-weak-color-two;
  218. }
  219. .search {
  220. width: #{750rpx};
  221. height: #{88rpx};
  222. padding: #{16rpx} #{24rpx};
  223. box-sizing: border-box;
  224. background-color: #efeff4;
  225. top: 0;
  226. position: fixed;
  227. left: 0;
  228. z-index: 23;
  229. .prompt {
  230. width: #{702rpx};
  231. height: #{56rpx};
  232. position: absolute;
  233. border-radius: #{28rpx};
  234. background-color: #ffffff;
  235. > image {
  236. width: #{26rpx};
  237. height: #{26rpx};
  238. }
  239. > text {
  240. color: #b2b2b2;
  241. font-size: #{26rpx};
  242. margin: #{0 10rpx};
  243. }
  244. }
  245. input {
  246. width: #{702rpx};
  247. height: #{56rpx};
  248. border-radius: #{28rpx};
  249. background-color: #ffffff;
  250. padding: #{0 70rpx 0 30rpx};
  251. box-sizing: border-box;
  252. font-size: #{26rpx};
  253. }
  254. .search-clear {
  255. position: absolute;
  256. right: #{15rpx};
  257. top: #{14rpx};
  258. width: #{30rpx};
  259. height: #{30rpx};
  260. z-index: 300;
  261. }
  262. }
  263. .app-buttons {
  264. height: 128upx;
  265. padding: 24upx 24upx;
  266. .app-icon {
  267. width: #{32rpx};
  268. height: #{32rpx};
  269. background-repeat: no-repeat;
  270. background-size: 100% 100%;
  271. margin-right: #{8rpx};
  272. }
  273. .app-manual-icon {
  274. background-image: url("./image/add.png");
  275. }
  276. .app-auth-icon {
  277. background-image: url("./image/auth.png");
  278. }
  279. .app-text {
  280. font-size: #{28rpx};
  281. color: #ffffff;
  282. margin-left: #{8rpx};
  283. }
  284. }
  285. .u-bottom-fixed {
  286. position: fixed;
  287. bottom: 0;
  288. left: 0;
  289. width: 100%;
  290. z-index: 999;
  291. }
  292. .u-bottom-height {
  293. height: 128upx;
  294. }
  295. </style>