Преглед изворни кода

促销购物车取消控制领域

xiaohaizhao пре 1 година
родитељ
комит
7df36fc3a7

+ 36 - 26
packageA/activity/selectProduct/cart/index.js

@@ -15,6 +15,7 @@ Page({
 	data: {
 		list: [],
 		results: [], //选中结果
+		resultsList: [],
 		sa_brandid: null, //当前选中品牌id
 		classList: [], //生成订单时所选
 		sum: 0, //价格合
@@ -77,11 +78,13 @@ Page({
 				let obj = allBrandList.find(s => s.sa_brandid == v.sa_brandid);
 				if (obj) {
 					obj.results.push(v.sa_shoppingcartid)
+					obj.resultsList.push(v)
 				} else {
 					allBrandList.push({
 						brandname: v.brandname,
 						sa_brandid: v.sa_brandid,
 						results: [v.sa_shoppingcartid],
+						resultsList: [v]
 					})
 				}
 				if (v.iscustomsize) v.customText = getCustomText(v);
@@ -101,19 +104,33 @@ Page({
 		})
 	},
 	clickBut(e) {
-		this.data.classList.length >= 2 ? wx.showToast({
+		this.handleSubmit();
+		/* 	this.data.classList.length >= 2 ? wx.showToast({
 			title: '请选择订单领域(订单只允许同品牌/同领域的商品)',
 			icon: "none",
 			duration: 3000
 		}) : this.handleSubmit(0);
+ */
 	},
 	/* 提交 */
 	submit(e) {
-		this.handleSubmit(e.detail.value)
+		this.handleSubmit()
 	},
-	handleSubmit(index) {
-		let data = this.data.classList[index],
-			that = this;
+	handleSubmit() {
+		let that = this;
+		let items = that.data.resultsList.map(v => {
+			return {
+				"sa_orderitemsid": 0,
+				"itemid": v.itemid,
+				"sa_brandid": v.sa_brandid,
+				"qty": v.qty,
+				width: v.width || 0,
+				length: v.length || 0,
+				sa_shoppingcartid: v.sa_shoppingcartid || 0,
+				sa_promotion_itemsid: v.sa_promotion_itemsid
+			}
+		})
+		console.log("items", items)
 		wx.showModal({
 			title: '提示',
 			content: '是否确定生成促销订单',
@@ -129,20 +146,9 @@ Page({
 						"content": {
 							istool: 0,
 							type: "促销订单",
-							"tradefield": data.type, //必选
+							//"tradefield": data.type, 必选
 							...ids,
-							"items": data.list.map(v => {
-								return {
-									"sa_orderitemsid": 0,
-									"itemid": v.itemid,
-									"sa_brandid": v.sa_brandid,
-									"qty": v.qty,
-									width: v.width || 0,
-									length: v.length || 0,
-									sa_shoppingcartid: v.sa_shoppingcartid || 0,
-									sa_promotion_itemsid: v.sa_promotion_itemsid
-								}
-							})
+							items
 						}
 					}).then(res => {
 						console.log("转化订单", res)
@@ -154,6 +160,7 @@ Page({
 							icon: "none"
 						});
 						getApp().globalData.getCollectCount()
+						that.getList();
 						wx.showModal({
 							title: '提示',
 							content: '生成成功!是否立即前往',
@@ -165,10 +172,7 @@ Page({
 								}
 							}
 						});
-						that.getList();
 					})
-
-
 				}
 			}
 		})
@@ -181,20 +185,23 @@ Page({
 		if (isAll) {
 			this.setData({
 				sa_brandid: null,
-				results: []
+				results: [],
+				resultsList: []
 			})
 		} else {
 			//已选品牌产品情况下
 			if (this.data.sa_brandid) {
 				let obj = this.data.allBrandList.find(v => v.sa_brandid == this.data.sa_brandid)
 				this.setData({
-					results: obj.results
+					results: obj.results,
+					resultsList: obj.resultsList
 				})
 			} else {
 				if (this.data.allBrandList.length == 0) return;
 				this.setData({
 					sa_brandid: this.data.allBrandList[0].sa_brandid,
-					results: this.data.allBrandList[0].results
+					results: this.data.allBrandList[0].results,
+					resultsList: this.data.allBrandList[0].resultsList,
 				})
 			}
 		};
@@ -206,6 +213,7 @@ Page({
 			item
 		} = my ? e : e.currentTarget.dataset;
 		let results = this.data.results,
+			resultsList = this.data.resultsList,
 			sa_brandid = this.data.sa_brandid;
 		if (sa_brandid && sa_brandid != item.sa_brandid) return;
 		if (results.length == 0) {
@@ -215,8 +223,10 @@ Page({
 			let index = results.findIndex(v => v == item.sa_shoppingcartid)
 			if (index == -1) {
 				results.push(item.sa_shoppingcartid);
+				resultsList.push(item)
 			} else {
 				results.splice(index, 1);
+				resultsList.splice(index, 1);
 				if (results.length == 0) sa_brandid = null;
 			}
 		};
@@ -235,12 +245,12 @@ Page({
 	/* 计算总价/产品领域分类 */
 	computeSum() {
 		let results = this.data.results,
+			resultsList = this.data.resultsList,
 			sum = 0,
 			classList = [];
 		if (results.length) results = results.filter(v => {
 			let item = this.data.list.find(va => va.sa_shoppingcartid == v);
 			if (item) {
-				console.log(item.gradeprice)
 				sum = currency(sum).add(currency(item.qty).multiply(item.gradeprice)).value;
 				/* 领域分类 */
 				let index = classList.findIndex(value => value.type == item.tradefield_shoppingcart);
@@ -260,6 +270,7 @@ Page({
 		let sa_brandid = results.length ? this.data.sa_brandid : null;
 		wx.setStorageSync('shopping1', {
 			results,
+			resultsList,
 			sa_brandid
 		})
 		let isAll = false;
@@ -267,7 +278,6 @@ Page({
 			let brand = this.data.allBrandList.find(v => v.sa_brandid == sa_brandid)
 			isAll = brand.results.length == results.length
 		}
-		console.log(sum)
 		this.setData({
 			sum: CNY(sum),
 			isAll,

+ 5 - 4
packageA/activity/selectProduct/cart/index.wxml

@@ -21,7 +21,8 @@
 					<view class="exp">品牌:{{item.brandname ||" --"}}</view>
 					<view class="exp">领域:{{item.tradefield_shoppingcart ||" --"}}</view>
 					<view class="exp" wx:if="{{item.iscustomsize}}" data-item="{{item}}" catch:tap="customization" style="color:#085CDF;">
-						{{item.customText}}<van-icon name="arrow-down" />
+						{{item.customText}}
+						<van-icon name="arrow-down" />
 					</view>
 					<view class="price" style="bottom: {{item.iscustomsize?'40rpx':'0rpx'}};">{{handleHide.query(item.showPrice,hidePrice)}}/{{item.unitname}}</view>
 				</view>
@@ -53,10 +54,10 @@
 				{{logistics}}
 			</view>
 		</view>
-		<picker wx:if="{{classList.length>=2}}" range='{{classList}}' range-key='name' disabled='{{!results.length}}' bindchange="submit">
+		<!-- 	<picker wx:if="{{classList.length>=2}}" range='{{classList}}' range-key='name' disabled='{{!results.length}}' bindchange="submit">
 			<van-button custom-class='but' disabled='{{!results.length}}' loading='{{loading}}' loading-text="生成中..." bind:click="clickBut">生成订单</van-button>
-		</picker>
-		<van-button wx:else custom-class='but' disabled='{{!results.length}}' loading='{{loading}}' loading-text="生成中..." bind:click="clickBut">生成订单</van-button>
+		</picker> wx:else -->
+		<van-button custom-class='but' disabled='{{!results.length}}' loading='{{loading}}' loading-text="生成中..." bind:click="clickBut">生成订单</van-button>
 	</view>
 </view>