index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <!-- 地址管理 -->
  3. <view :style="colorStyle">
  4. <view class='address-management' :class='addressList.length < 1 && page > 1 ? "fff":""'>
  5. <view class='line'>
  6. <image src='../../../static/images/line.jpg' v-if="addressList.length"></image>
  7. </view>
  8. <radio-group class="radio-group" @change="radioChange" v-if="addressList.length">
  9. <view class='item' v-for="(item,index) in addressList" :key="index">
  10. <view class='address' @click='goOrder(item.id)'>
  11. <view class='consignee'>收货人:{{item.real_name}}<text class='phone'>{{item.phone}}</text></view>
  12. <view>收货地址:{{item.province}}{{item.city}}{{item.district}}{{item.street}}{{item.detail}}</view>
  13. </view>
  14. <view class='operation acea-row row-between-wrapper'>
  15. <!-- #ifndef MP -->
  16. <radio class="radio" :value="index.toString()" :checked="item.is_default ? true : false">
  17. <text>设为默认</text>
  18. </radio>
  19. <!-- #endif -->
  20. <!-- #ifdef MP -->
  21. <radio class="radio" :value="index" :checked="item.is_default ? true : false">
  22. <text>设为默认</text>
  23. </radio>
  24. <!-- #endif -->
  25. <view class='acea-row row-middle'>
  26. <view @click='editAddress(item.id)'><text class='iconfont icon-bianji'></text>编辑</view>
  27. <view @click='delAddress(index)'><text class='iconfont icon-shanchu'></text>删除</view>
  28. </view>
  29. </view>
  30. </view>
  31. </radio-group>
  32. <view class='loadingicon acea-row row-center-wrapper' v-if="addressList.length">
  33. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  34. </view>
  35. <view class='noCommodity' v-if="addressList.length < 1 && page > 1">
  36. <view class='pictrue'>
  37. <image :src="imgHost + '/statics/images/noAddress.png'"></image>
  38. </view>
  39. </view>
  40. <view class="height-add"></view>
  41. <view class='footer acea-row row-between-wrapper'>
  42. <view class='addressBnt on' @click='addAddress'><text
  43. class='iconfont icon-tianjiadizhi'></text>添加新地址</view>
  44. <view class=""></view>
  45. </view>
  46. </view>
  47. <home v-if="navigation"></home>
  48. <!-- #ifdef MP -->
  49. <authorize v-if="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize>
  50. <!-- #endif -->
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. getAddressList,
  56. setAddressDefault,
  57. delAddress,
  58. editAddress,
  59. postAddress
  60. } from '@/api/user.js';
  61. import {
  62. toLogin
  63. } from '@/libs/login.js';
  64. import {
  65. mapGetters
  66. } from "vuex";
  67. import home from '@/components/home';
  68. import colors from '@/mixins/color.js';
  69. import {HTTP_REQUEST_URL} from '@/config/app';
  70. export default {
  71. components: {
  72. home
  73. },
  74. mixins:[colors],
  75. data() {
  76. return {
  77. addressList: [],
  78. cartId: '',
  79. pinkId: 0,
  80. couponId: 0,
  81. loading: false,
  82. loadend: false,
  83. loadTitle: '加载更多',
  84. page: 1,
  85. limit: 20,
  86. isAuto: false, //没有授权的不会自动授权
  87. isShowAuth: false, //是否隐藏授权
  88. news: '',
  89. noCoupon: 0,
  90. imgHost:HTTP_REQUEST_URL,
  91. deliveryType:1,//配送方式
  92. store_name:'',//门店名称
  93. storeId:0,//门店id
  94. product_id:0//商品id
  95. };
  96. },
  97. computed: mapGetters(['isLogin']),
  98. onLoad(options) {
  99. this.cartId = options.cartId || '';
  100. this.noCoupon = options.noCoupon || 0;
  101. this.pinkId = options.pinkId || 0;
  102. this.couponId = options.couponId || 0;
  103. this.news = options.news || 0;
  104. this.deliveryType = options.delivery_type || 1;
  105. this.store_name = options.store_name;
  106. this.storeId = options.store_id;
  107. this.product_id = options.product_id;
  108. if (this.isLogin) {
  109. this.getAddressList(true);
  110. } else {
  111. //#ifndef MP
  112. toLogin();
  113. //#endif
  114. //#ifdef MP
  115. this.isShowAuth = true;
  116. //#endif
  117. }
  118. },
  119. onShow: function() {
  120. uni.removeStorageSync('form_type_cart');
  121. },
  122. methods: {
  123. onLoadFun(){
  124. this.getAddressList(true);
  125. this.isShowAuth = false
  126. },
  127. // 授权关闭
  128. authColse: function(e) {
  129. this.isShowAuth = e
  130. },
  131. /*
  132. * 导入微信地址(小程序)
  133. */
  134. getWxAddress: function() {
  135. let that = this;
  136. uni.authorize({
  137. scope: 'scope.address',
  138. success: function(res) {
  139. uni.chooseAddress({
  140. success: function(res) {
  141. let addressP = {};
  142. addressP.province = res.provinceName;
  143. addressP.city = res.cityName;
  144. addressP.district = res.countyName;
  145. editAddress({
  146. address: addressP,
  147. is_default: 1,
  148. real_name: res.userName,
  149. post_code: res.postalCode,
  150. phone: res.telNumber,
  151. detail: res.detailInfo,
  152. id: 0,
  153. type: 1
  154. }).then(res => {
  155. that.$util.Tips({
  156. title: "添加成功",
  157. icon: 'success'
  158. }, function() {
  159. that.getAddressList(true);
  160. });
  161. }).catch(err => {
  162. return that.$util.Tips({
  163. title: err
  164. });
  165. });
  166. },
  167. fail: function(res) {
  168. if (res.errMsg == 'chooseAddress:cancel') return that.$util
  169. .Tips({
  170. title: '取消选择'
  171. });
  172. },
  173. })
  174. },
  175. fail: function(res) {
  176. uni.showModal({
  177. title: '您已拒绝导入微信地址权限',
  178. content: '是否进入权限管理,调整授权?',
  179. success(res) {
  180. if (res.confirm) {
  181. uni.openSetting({
  182. success: function(res) {}
  183. });
  184. } else if (res.cancel) {
  185. return that.$util.Tips({
  186. title: '已取消!'
  187. });
  188. }
  189. }
  190. })
  191. }
  192. })
  193. },
  194. /*
  195. * 导入微信地址(公众号)
  196. */
  197. getAddress() {
  198. let that = this;
  199. that.$wechat.openAddress().then(userInfo => {
  200. // open();
  201. editAddress({
  202. real_name: userInfo.userName,
  203. phone: userInfo.telNumber,
  204. address: {
  205. province: userInfo.provinceName,
  206. city: userInfo.cityName,
  207. district: userInfo.countryName
  208. },
  209. detail: userInfo.detailInfo,
  210. post_code: userInfo.postalCode,
  211. is_default: 1,
  212. type: 1
  213. })
  214. .then(() => {
  215. that.$util.Tips({
  216. title: "添加成功",
  217. icon: 'success'
  218. }, function() {
  219. // close();
  220. that.getAddressList(true);
  221. });
  222. })
  223. .catch(err => {
  224. // close();
  225. return that.$util.Tips({
  226. title: err || "添加失败"
  227. });
  228. });
  229. });
  230. },
  231. /**
  232. * 获取地址列表
  233. *
  234. */
  235. getAddressList: function(isPage) {
  236. let that = this;
  237. if (isPage) {
  238. that.loadend = false;
  239. that.page = 1;
  240. that.$set(that, 'addressList', []);
  241. };
  242. if (that.loading) return;
  243. if (that.loadend) return;
  244. that.loading = true;
  245. that.loadTitle = '';
  246. getAddressList({
  247. page: that.page,
  248. limit: that.limit
  249. }).then(res => {
  250. let list = res.data;
  251. let loadend = list.length < that.limit;
  252. that.addressList = that.$util.SplitArray(list, that.addressList);
  253. that.$set(that, 'addressList', that.addressList);
  254. that.loadend = loadend;
  255. that.loadTitle = loadend ? '没有更多内容啦~' : '加载更多';
  256. that.page = that.page + 1;
  257. that.loading = false;
  258. }).catch(err => {
  259. that.loading = false;
  260. that.loadTitle = '加载更多';
  261. });
  262. },
  263. /**
  264. * 设置默认地址
  265. */
  266. radioChange: function(e) {
  267. let index = parseInt(e.detail.value),
  268. that = this;
  269. let address = this.addressList[index];
  270. if (address == undefined) return that.$util.Tips({
  271. title: '您设置的默认地址不存在!'
  272. });
  273. setAddressDefault(address.id).then(res => {
  274. for (let i = 0, len = that.addressList.length; i < len; i++) {
  275. if (i == index) that.addressList[i].is_default = true;
  276. else that.addressList[i].is_default = false;
  277. }
  278. that.$util.Tips({
  279. title: '设置成功',
  280. icon: 'success'
  281. }, function() {
  282. that.$set(that, 'addressList', that.addressList);
  283. });
  284. }).catch(err => {
  285. return that.$util.Tips({
  286. title: err
  287. });
  288. });
  289. },
  290. /**
  291. * 编辑地址
  292. */
  293. editAddress: function(id) {
  294. let cartId = this.cartId,
  295. pinkId = this.pinkId,
  296. couponId = this.couponId;
  297. this.cartId = '';
  298. this.pinkId = '';
  299. this.couponId = '';
  300. uni.navigateTo({
  301. url: '/pages/users/user_address/index?id=' + id + '&cartId=' + cartId + '&pinkId=' +
  302. pinkId + '&couponId=' +
  303. couponId + '&new=' + this.news +'&delivery_type='+this.deliveryType+'&store_id='+this.storeId+'&store_name='+ this.store_name+'&product_id='+this.product_id
  304. })
  305. },
  306. /**
  307. * 删除地址
  308. */
  309. delAddress: function(index) {
  310. let that = this,
  311. address = this.addressList[index];
  312. if (address == undefined) return that.$util.Tips({
  313. title: '您删除的地址不存在!'
  314. });
  315. delAddress(address.id).then(res => {
  316. that.$util.Tips({
  317. title: '删除成功',
  318. icon: 'success'
  319. }, function() {
  320. that.addressList.splice(index, 1);
  321. that.$set(that, 'addressList', that.addressList);
  322. });
  323. }).catch(err => {
  324. return that.$util.Tips({
  325. title: err
  326. });
  327. });
  328. },
  329. /**
  330. * 新增地址
  331. */
  332. addAddress: function() {
  333. let cartId = this.cartId,
  334. pinkId = this.pinkId,
  335. couponId = this.couponId;
  336. this.cartId = '';
  337. this.pinkId = '';
  338. this.couponId = '';
  339. uni.navigateTo({
  340. url: '/pages/users/user_address/index?cartId=' + cartId + '&pinkId=' + pinkId +
  341. '&couponId=' + couponId + '&new=' + this.news+'&delivery_type='+this.deliveryType+'&store_id='+this.storeId+'&store_name='+ this.store_name+'&product_id='+this.product_id
  342. })
  343. },
  344. goOrder: function(id) {
  345. let cartId = '';
  346. let pinkId = '';
  347. let couponId = '';
  348. if (this.cartId && id) {
  349. cartId = this.cartId;
  350. pinkId = this.pinkId;
  351. couponId = this.couponId;
  352. this.cartId = '';
  353. this.pinkId = '';
  354. this.couponId = '';
  355. uni.redirectTo({
  356. url: '/pages/goods/order_confirm/index?is_address=1&new=' + this.news + '&cartId=' +
  357. cartId + '&addressId=' + id + '&pinkId=' +
  358. pinkId + '&couponId=' + couponId +
  359. '&noCoupon=' + this.noCoupon+'&delivery_type='+this.deliveryType+'&store_id='+this.storeId+'&store_name='+ this.store_name+'&product_id='+this.product_id
  360. })
  361. }
  362. }
  363. },
  364. onReachBottom: function() {
  365. this.getAddressList();
  366. }
  367. }
  368. </script>
  369. <style>
  370. .height-add {
  371. height:120rpx;
  372. }
  373. .noCommodity{
  374. height: calc(100vh - 123rpx);
  375. background-color: #fff;
  376. }
  377. .address-management.fff {
  378. background-color: #fff;
  379. height: 1300rpx
  380. }
  381. .address-management .line {
  382. width: 100%;
  383. height: 3rpx;
  384. }
  385. .address-management .line image {
  386. width: 100%;
  387. height: 100%;
  388. display: block;
  389. }
  390. .address-management .item {
  391. background-color: #fff;
  392. padding: 0 30rpx;
  393. margin-bottom: 12rpx;
  394. }
  395. .address-management .item .address {
  396. padding: 30rpx 0;
  397. border-bottom: 1rpx solid #eee;
  398. font-size: 28rpx;
  399. color: #282828;
  400. }
  401. .address-management .item .address .consignee {
  402. font-size: 28rpx;
  403. font-weight: bold;
  404. margin-bottom: 8rpx;
  405. }
  406. .address-management .item .address .consignee .phone {
  407. margin-left: 25rpx;
  408. }
  409. .address-management .item .operation {
  410. height: 83rpx;
  411. font-size: 28rpx;
  412. color: #282828;
  413. }
  414. .address-management .item .operation .radio text {
  415. margin-left: 13rpx;
  416. }
  417. .address-management .item .operation .iconfont {
  418. color: #2c2c2c;
  419. font-size: 35rpx;
  420. vertical-align: -2rpx;
  421. margin-right: 10rpx;
  422. }
  423. .address-management .item .operation .iconfont.icon-shanchu {
  424. margin-left: 40rpx;
  425. font-size: 38rpx;
  426. }
  427. .address-management .footer {
  428. position: fixed;
  429. width: 100%;
  430. bottom: 0;
  431. height: 106rpx;
  432. padding: 0 30rpx;
  433. box-sizing: border-box;
  434. }
  435. .address-management .footer .addressBnt {
  436. width: 330rpx;
  437. height: 76rpx;
  438. border-radius: 50rpx;
  439. text-align: center;
  440. line-height: 76rpx;
  441. font-size: 30rpx;
  442. color: #fff;
  443. background-color: var(--view-theme);
  444. }
  445. .address-management .footer .addressBnt.on {
  446. width: 690rpx;
  447. margin: 0 auto;
  448. }
  449. .address-management .footer .addressBnt .iconfont {
  450. font-size: 35rpx;
  451. margin-right: 8rpx;
  452. vertical-align: -1rpx;
  453. }
  454. .address-management .footer .addressBnt.wxbnt {
  455. background-color: #FE960F;
  456. }
  457. </style>