index.vue 11 KB

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