Browse Source

地址优化

yuxingxing 2 years ago
parent
commit
f20a4d82d0
4 changed files with 90 additions and 44 deletions
  1. 50 26
      pages/goods_details/index.vue
  2. 35 18
      pages/users/user_address_list/index.vue
  3. 1 0
      store/getters.js
  4. 4 0
      store/modules/app.js

+ 50 - 26
pages/goods_details/index.vue

@@ -74,7 +74,9 @@
 							<view class='coupon acea-row row-between-wrapper'>
 								<view class='hide line1 acea-row'>
 									赠积分:
-									<view class='activity' v-if="storeInfo.obtainIntegral>0">赠送 {{ storeInfo.obtainIntegral }} 红积分</view>
+									<view class='activity' v-if="storeInfo.obtainIntegral > 0">赠送 {{
+											storeInfo.obtainIntegral
+									}} 红积分</view>
 								</view>
 							</view>
 							<view v-if="couponList.length" class="coupon acea-row row-between-wrapper skeleton-rect"
@@ -198,15 +200,14 @@
 								</button>
 							</form>
 						</view>
-						<view class="bnt acea-row" :class="!storeInfo.cart_button ? 'virbnt' : ''"
-							v-else>
+						<view class="bnt acea-row" :class="!storeInfo.cart_button ? 'virbnt' : ''" v-else>
 							<form v-if="storeInfo.cart_button" @submit="joinCart" class="joinCart bnts"
 								:class="!storeInfo.cart_button ? 'virbnt' : ''">
 								<button class="joinCart bnts" form-type="submit">
 									{{ $t(`加入购物车`) }}
 								</button>
 							</form>
-							<form class="buy bnts bg-color-hui" @submit="goBuy"> 
+							<form class="buy bnts bg-color-hui" @submit="goBuy">
 								<button class="buy bnts " form-type="submit"
 									:class="!storeInfo.cart_button ? 'virbnt' : ''">
 									{{ $t(`立即购买`) }}
@@ -292,7 +293,7 @@
 <script>
 let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
 import {
-	getGoodsDetail, getUserAddressByUserId, postBeforeCheck ,getAvailableCheck
+	getGoodsDetail, getUserAddressByUserId, postBeforeCheck, getAvailableCheck
 } from "@/api/home.js";
 import {
 	getProductDetail,
@@ -412,7 +413,6 @@ export default {
 			sharePacket: {
 				isState: true, //默认不显示
 			}, //分销商详细
-			uid: 0, //用户uid
 			circular: false,
 			autoplay: false,
 			interval: 3000,
@@ -466,7 +466,7 @@ export default {
 			svip_price_open: 1
 		};
 	},
-	computed: mapGetters(["isLogin", "uid", "userInfo"]),
+	computed: mapGetters(["isLogin", "uid", "userInfo","selectAddr"]),
 	watch: {
 		isLogin: {
 			handler: function (newV, oldV) {
@@ -478,6 +478,12 @@ export default {
 			},
 			deep: true,
 		},
+		selectAddr: {
+			handler: function (newV, oldV) {
+				this.attrAddrValue = newV
+			},
+			deep: true,
+		},
 		storeInfo: {
 			handler: function () {
 				this.$nextTick(() => { });
@@ -487,8 +493,10 @@ export default {
 	},
 	onLoad(options) {
 		// 判断是否登录
-		if(!this.isLogin){
-			this.$Cache.set('INVITE_CODE', options.inviteCode);
+		if (!this.isLogin) {
+			if (options.inviteCode != "undefined") {
+				this.$Cache.set('INVITE_CODE', options.inviteCode);
+			}
 			uni.showToast({
 				title: "您暂未登录,即将跳登录界面",
 				icon: 'none',
@@ -503,13 +511,15 @@ export default {
 		}
 		let userInfo = this.$Cache.get("USER_INFO", true)
 		console.log("用户自己的推荐码:" + userInfo.code);
-		console.log("受邀的推荐码:"+ options.inviteCode);
+		console.log("受邀的推荐码:" + options.inviteCode);
 		//1580 进入时
-		if(options.zoneType == 8){
+		if (options.zoneType == 8) {
 			//判断是否为自己的要求码进入
-		if(options.inviteCode !== userInfo.code){
-			this.$Cache.set('INVITE_CODE', options.inviteCode);
-		}
+			if (options.inviteCode !== userInfo.code) {
+				if (options.inviteCode != "undefined") {
+					this.$Cache.set('INVITE_CODE', options.inviteCode);
+				}
+			}
 		}
 		let that = this;
 		var pages = getCurrentPages();
@@ -854,9 +864,9 @@ export default {
 				this.storeInfo.salePrice = item.salePrice - 0
 				this.attr.productSelect.totalStock = item.stock - 0
 				this.attr.attrValueId = item.id
-				if(!item.canSale){
+				if (!item.canSale) {
 					this.availableCheck = false
-				}else{
+				} else {
 					this.availableCheck = true
 				}
 			}
@@ -973,7 +983,7 @@ export default {
 				success: function () { },
 			});
 		},
-		getUserAddressByUserId(){
+		getUserAddressByUserId() {
 			getUserAddressByUserId({
 				userId: this.$store.state.app.uid,
 				type: 1
@@ -988,9 +998,9 @@ export default {
 		 */
 		DefaultSelect: function () {
 			//找到第一个可销售的规格
-			if(this.skuArr.length >= 0){
+			if (this.skuArr.length >= 0) {
 				this.skuArr.every(value => {
-					if(value.canSale){
+					if (value.canSale) {
 						this.attrValue = value.spceName
 						this.storeInfo.obtainIntegral = value.obtainIntegral - 0
 						this.storeInfo.salePrice = value.salePrice - 0
@@ -1004,16 +1014,16 @@ export default {
 			uni.hideLoading();
 		},
 		// 可销售检测
-		getAvailableCheck(){
+		getAvailableCheck() {
 			getAvailableCheck({
 				goodsInfoId: this.id,
 				userAddressId: this.attrAddrValue.id
 			}).then(res => {
 				//处理缺货的规格
 				let ban = res.data.ban
-				if (ban !== undefined){
-					this.storeInfo.goodsSpecList.forEach((value,key) =>{
-						if(ban.includes(value.id-0) || ban.includes(value.optionId-0)){
+				if (ban !== undefined) {
+					this.storeInfo.goodsSpecList.forEach((value, key) => {
+						if (ban.includes(value.id - 0) || ban.includes(value.optionId - 0)) {
 							this.storeInfo.goodsSpecList[key].canSale = false
 						}
 					})
@@ -1152,7 +1162,14 @@ export default {
 			if (this.isLogin === false) {
 				toLogin();
 			} else {
-				this.goCat();
+				//判断是否有地址
+				if(!this.attrAddrValue && !this.attrAddrValue.id){
+					this.goCat();
+				}else{
+					this.$util.Tips({
+						title: this.$t(`请先至个人中心设置默认地址`),
+					});
+				}
 			}
 		},
 		goCart() {
@@ -1206,7 +1223,7 @@ export default {
 					uni.navigateTo({
 						url: "/pages/goods/order_confirm/index?num=" + that.attr.productSelect.totalSales + "&productId=" +
 							that.attr.productSelect.id + "&addressId=" + that.attrAddrValue.id +
-							"&goodsSpecId=" + that.attr.attrValueId+"&obtainIntegral="+that.storeInfo.obtainIntegral,
+							"&goodsSpecId=" + that.attr.attrValueId + "&obtainIntegral=" + that.storeInfo.obtainIntegral,
 					});
 				} else {
 					that.$util.Tips({
@@ -1259,7 +1276,14 @@ export default {
 			if (this.isLogin === false) {
 				toLogin();
 			} else {
-				this.goCat(true);
+				//判断是否有地址
+				if(this.attrAddrValue && this.attrAddrValue.id){
+					this.goCat(true);
+				}else{
+					this.$util.Tips({
+						title: this.$t(`请先配置送至地址`),
+					});
+				}
 			}
 		},
 		open(data) {

+ 35 - 18
pages/users/user_address_list/index.vue

@@ -14,7 +14,7 @@
 					<view class='operation acea-row row-between-wrapper'>
 						<!-- #ifdef MP -->
 						<radio class="radio" :value="index" :checked="item.defaultState == '2' ? true : false">
-							<text>{{ $t(`默认地址`) }}</text>
+							<text>{{ $t(typeTitle) }}</text>
 						</radio>
 						<!-- #endif -->
 						<view class='acea-row row-middle'>
@@ -109,6 +109,7 @@ export default {
 			loadend: false,
 			loadTitle: this.$t(`加载更多`),
 			page: 1,
+			typeTitle: `默认地址`,
 			limit: 20,
 			isAuto: false, //没有授权的不会自动授权
 			isShowAuth: false, //是否隐藏授权
@@ -116,10 +117,11 @@ export default {
 			noCoupon: 0
 		};
 	},
-	computed: mapGetters(['isLogin']),
+	computed: mapGetters(['isLogin',"selectAddr"]),
 	onLoad(options) {
 		if (options.type) {
 			this.type = options.type
+			this.typeTitle = '选择地址'
 			uni.setNavigationBarTitle({
 				title: "选择地址"
 			});
@@ -270,6 +272,16 @@ export default {
 				let list = res.data;
 				let loadend = list.length < that.limit;
 				that.addressList = that.$util.SplitArray(list, that.addressList);
+				if (that.type && that.selectAddr.id != undefined) {
+					//找出已经的地址
+					that.addressList.forEach((value,index) => {
+						if(that.selectAddr.id == value.id) {
+							that.addressList[index].defaultState = '2'
+						}else{
+							that.addressList[index].defaultState = '1'
+						}
+					})
+				}
 				that.$set(that, 'addressList', that.addressList);
 				that.loadend = loadend;
 				that.loadTitle = loadend ? that.$t(`我也是有底线的`) : that.$t(`加载更多`);
@@ -290,23 +302,28 @@ export default {
 			if (address == undefined) return that.$util.Tips({
 				title: that.$t(`您设置的默认地址不存在!`)
 			});
-			address.defaultState = 2
-			postUserAddressUpdate(address).then(res => {
-				for (let i = 0, len = that.addressList.length; i < len; i++) {
-					if (i == index) that.addressList[i].is_default = true;
-					else that.addressList[i].is_default = false;
-				}
-				that.$util.Tips({
-					title: that.$t(`设置成功`),
-					icon: 'success'
-				}, function () {
-					that.$set(that, 'addressList', that.addressList);
-				});
-			}).catch(err => {
-				return that.$util.Tips({
-					title: err
+			// 判断是否选择地址
+			if (this.type) {
+				this.$store.commit('SETSELECTADDR', address);
+			}else {
+				address.defaultState = 2
+				postUserAddressUpdate(address).then(res => {
+					for (let i = 0, len = that.addressList.length; i < len; i++) {
+						if (i == index) that.addressList[i].is_default = true;
+						else that.addressList[i].is_default = false;
+					}
+					that.$util.Tips({
+						title: that.$t(`设置成功`),
+						icon: 'success'
+					}, function () {
+						that.$set(that, 'addressList', that.addressList);
+					});
+				}).catch(err => {
+					return that.$util.Tips({
+						title: err
+					});
 				});
-			});
+			}
 		},
 		/**
 		 * 编辑地址

+ 1 - 0
store/getters.js

@@ -3,6 +3,7 @@
 export default {
   token: state => state.app.token,
   isLogin: state => !!state.app.token,
+  selectAddr: state => state.app.selectAddr,
   backgroundColor: state => state.app.backgroundColor,
   userInfo: state => state.app.userInfo || {},
 	uid:state => state.app.uid,

+ 4 - 0
store/modules/app.js

@@ -17,6 +17,7 @@ const state = {
 	token: Cache.get(LOGIN_STATUS) || false,
 	backgroundColor: "#fff",
 	userInfo: {},
+	selectAddr: {},
 	uid: Cache.get(UID) || 0,
 	open_id: Cache.get(OPENID),
 	homeActive: false,
@@ -25,6 +26,9 @@ const state = {
 };
 
 const mutations = {
+	SETSELECTADDR(state,val){
+		state.selectAddr = val;
+	},
 	SETPHONESTATUS(state,val){
 		state.phoneStatus = val;
 	},