address.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <app-layout>
  3. <view class="head">
  4. <view v-for="(item, index) in list" :key="index">
  5. <app-shipping-address
  6. @handleAddress="address"
  7. :item="item"
  8. :is_refund_address="is_refund_address"
  9. :is_hide_default_btn="is_hide_default_btn == 0"
  10. :destroy_url="destroy_url"
  11. ></app-shipping-address>
  12. </view>
  13. </view>
  14. <view class="app-buttons main-between">
  15. <!-- #ifdef MP-ALIPAY -->
  16. <app-button :background="manual_btn_bg" arrangement="row" @click="manual" type="important" round width="700">
  17. <icon class="app-icon app-manual-icon"></icon>
  18. <text class="app-text">手动添加</text>
  19. </app-button>
  20. <!-- #endif -->
  21. <!-- #ifndef MP-ALIPAY -->
  22. <app-button :background="manual_btn_bg" arrangement="row" @click="manual" type="important" round width="700">
  23. <icon class="app-icon app-manual-icon"></icon>
  24. <text class="app-text">新增</text>
  25. </app-button>
  26. <!-- <app-button :background="manual_btn_bg" arrangement="row" @click="manual" type="important" round width="346">
  27. <icon class="app-icon app-manual-icon"></icon>
  28. <text class="app-text">手动添加</text>
  29. </app-button> -->
  30. <!-- <app-button background="#08c303" arrangement="row" @click="getauto" type="important" round width="346">
  31. <icon class="app-icon app-auth-icon"></icon>
  32. <text class="app-text">自动获取</text>
  33. </app-button> -->
  34. <!-- #endif -->
  35. </view>
  36. </app-layout>
  37. </template>
  38. <script>
  39. import appShippingAddress from '../../components/page-component/app-shipping-address/app-shipping-address.vue';
  40. export default {
  41. name: "address",
  42. components: {
  43. 'app-shipping-address': appShippingAddress,
  44. },
  45. data() {
  46. return {
  47. page: 1,
  48. args: '',
  49. load: '',
  50. list: null,
  51. manual_btn_bg: '',
  52. is_refund_address: 0,
  53. is_hide_default_btn: 0,
  54. address_url: '',
  55. destroy_url: '',
  56. }
  57. },
  58. onLoad: function(options) {
  59. this.is_hide_default_btn = options.is_hide_default_btn ? options.is_hide_default_btn : 0;
  60. this.is_refund_address = options.is_refund_address ? options.is_refund_address : 0;
  61. this.manual_btn_bg = options.manual_btn_bg ? options.manual_btn_bg:`#ff4544`;
  62. if (this.is_refund_address > 0) {
  63. this.address_url = this.$api.app_admin.refund_address;
  64. this.destroy_url = this.$api.app_admin.address_destroy;
  65. uni.setNavigationBarTitle({
  66. title: '退货地址'
  67. })
  68. } else {
  69. this.address_url = this.$api.user.address;
  70. this.destroy_url = this.$api.user.address_destroy;
  71. }
  72. //#ifdef MP-BAIDU
  73. this.init();
  74. //#endif
  75. },
  76. onShow: function () {
  77. this.init();
  78. },
  79. /**
  80. * 页面上拉触底事件的处理函数
  81. */
  82. onReachBottom: function () {
  83. const self = this;
  84. if (self.args || self.load)
  85. return;
  86. self.load = true;
  87. let page = self.page + 1;
  88. this.$request({
  89. url: self.$api.user.address,
  90. data: {
  91. page: page,
  92. }
  93. }).then(info => {
  94. if (info.code === 0) {
  95. [self.page, self.args, self.list] = [page, info.data.list.length === 0, self.list.concat(info.data.list)];
  96. }
  97. self.load = false;
  98. });
  99. },
  100. methods: {
  101. init() {
  102. const self = this;
  103. if (!self.address_url) return;
  104. uni.showLoading({
  105. title: '加载中'
  106. });
  107. self.page = 1;
  108. self.$request({
  109. url: self.address_url,
  110. }).then(info => {
  111. uni.hideLoading();
  112. if (info.code === 0) {
  113. [self.page, self.list] = [1, info.data.list];
  114. }
  115. }).catch(info => {
  116. uni.hideLoading();
  117. console.error(info);
  118. });
  119. },
  120. address(status) {
  121. console.log(status);
  122. this.init();
  123. },
  124. manual() {
  125. uni.navigateTo({
  126. url: '/pages/address/address-edit?is_refund_address=' + this.is_refund_address,
  127. });
  128. },
  129. getauto() {
  130. //#ifndef MP-ALIPAY
  131. const self = this;
  132. uni.chooseAddress({
  133. success: function (e) {
  134. self.$request({
  135. url: self.$api.user.wechat_district,
  136. data: {
  137. national_code: e.nationalCode,
  138. province_name: e.provinceName,
  139. city_name: e.cityName,
  140. county_name: e.countyName,
  141. }
  142. }).then(info => {
  143. if (info.code === 0) {
  144. let province_id = info.data.district['province']['id'];
  145. let city_id = info.data.district['city']['id'];
  146. let district_id = info.data.district['district']['id'];
  147. let newAddress = {
  148. id: '',
  149. name: e.userName,
  150. ids: [province_id, city_id, district_id],
  151. province_id: province_id,
  152. city_id: city_id,
  153. district_id: district_id,
  154. mobile: e.telNumber,
  155. detail: e.detailInfo,
  156. };
  157. uni.navigateTo({
  158. url: '/pages/address/address-edit?form=' + JSON.stringify(newAddress) + '&is_refund_address=' + self.is_refund_address
  159. })
  160. } else {
  161. console.error(info.msg);
  162. }
  163. });
  164. },
  165. fail: function (e) {
  166. console.error(e);
  167. },
  168. }
  169. );
  170. //#endif
  171. }
  172. }
  173. }
  174. </script>
  175. <style scoped lang="scss">
  176. .head {
  177. background: $uni-weak-color-two;
  178. }
  179. .app-buttons {
  180. width: #{750-24-24rpx};
  181. height: #{80rpx};
  182. margin: #{40rpx} #{24rpx} 0;
  183. .app-icon {
  184. width: #{32rpx};
  185. height: #{32rpx};
  186. background-repeat: no-repeat;
  187. background-size: 100% 100%;
  188. margin-right: #{8rpx};
  189. }
  190. .app-manual-icon{
  191. background-image: url("./image/add.png");
  192. }
  193. .app-auth-icon {
  194. background-image: url("./image/auth.png");
  195. }
  196. .app-text {
  197. font-size: #{28rpx};
  198. color: #ffffff;
  199. margin-left: #{8rpx};
  200. }
  201. }
  202. </style>