index.vue 12 KB

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