ソースを参照

商品组添加定制产品逻辑

xiaohaizhao 1 年間 前
コミット
81bbb91569

+ 101 - 11
packageA/market/detail.js

@@ -8,7 +8,7 @@ import currency from "../../utils/currency";
 
 Page({
 	data: {
-    hidePrice: wx.getStorageSync('hidePrice'),
+		hidePrice: wx.getStorageSync('hidePrice'),
 		badge: getApp().globalData.collectCount,
 		loading: true,
 		content: {
@@ -17,7 +17,14 @@ Page({
 			color: "", //颜色
 			material: "", //材质
 			cheek: "", //边框
-		}
+			dwidth: 0,
+			dlength: 0,
+		},
+		detail: {
+			spec: ""
+		},
+		cWidth: null, //宽定制方案
+		cLength: null, //长定制方案
 	},
 	onLoad(options) {
 		let data = JSON.parse(options.params);
@@ -48,22 +55,63 @@ Page({
 				icon: "none",
 				mask: true
 			})
-			this.handleFiles(res.data.item[0].attinfos)
+			const item = res.data.item[0];
+			this.handleFiles(item.attinfos)
 			const CNY = sum => currency(sum, {
 				symbol: "¥",
 				precision: 2
 			}).format();
-			res.data.item[0].gradeprice = CNY(res.data.item[0].gradeprice);
-			res.data.item[0].marketprice = CNY(res.data.item[0].marketprice);
+			item.gradeprice = CNY(item.gradeprice);
+			item.marketprice = CNY(item.marketprice);
 			this.setData({
 				content,
-				detail: res.data.item[0],
+				detail: item,
 				specRows: res.data.specRows,
 				cheekRows: res.data.cheekRows,
 				materialRows: res.data.materialRows,
 				colorRows: res.data.colorRows,
 				loading: false
 			});
+			//是否定制
+			if (init) {
+				if (item.iscustomsize == 1) {
+					let cWidth = null,
+						cLength = null;
+					Promise.all([{
+						"id": "20230707091603",
+						"version": 1,
+						"content": {
+							"sa_sizecustomizedschemeid": item.lengthschemeid
+						}
+					}, {
+						"id": "20230707091603",
+						"version": 1,
+						"content": {
+							"sa_sizecustomizedschemeid": item.widthschemeid
+						}
+					}].map(v => _Http.basic(v))).then(s => {
+						if (s.some(c => c.msg != '成功')) return wx.showToast({
+							title: '定制方案获取失败',
+							icon: "none"
+						})
+						if (item.lengthschemeid) cLength = s[0].data;
+						if (item.widthschemeid) cWidth = s[1].data;
+						this.setData({
+							cWidth,
+							cLength,
+							"content.dwidth": cWidth.min || 0,
+							"content.dlength": cLength.min || 0,
+						});
+					})
+				} else {
+					this.setData({
+						cWidth: null,
+						cLength: null,
+						"content.dwidth": 0,
+						"content.dlength": 0,
+					});
+				}
+			}
 		})
 	},
 	/* 预览媒体 */
@@ -115,7 +163,6 @@ Page({
 	},
 	/* 切换产品 */
 	changeItemno(e) {
-		console.log("切换产品", e.currentTarget.dataset)
 		const {
 			value,
 			valuename
@@ -127,7 +174,35 @@ Page({
 			mask: true
 		})
 		content[valuename] = (content[valuename] == value.parm) ? "" : value.parm;
-		this.getDetail()
+		this.getDetail(valuename == "spec")
+	},
+	/* 定制选项 */
+	customParameter(e) {
+		let {
+			value,
+			valuename
+		} = e.currentTarget.dataset;
+		this.data.content[valuename] = value;
+		this.setData({
+			content: this.data.content
+		})
+	},
+	/* 定制步进器 */
+	cahngeStepper(e) {
+		const name = e.currentTarget.dataset.name,
+			name2 = name == 'cWidth' ? "dwidth" : "dlength",
+			content = this.data.content;
+		if (e.type == 'plus') {
+			content[name2] += 1
+		} else if (e.type == 'minus') {
+			content[name2] -= 1
+		} else {
+			const data = this.data[name];
+			content[name2] = (e.detail.value - 0).toFixed(data.decimalplaces);
+		}
+		this.setData({
+			content
+		})
 	},
 	clickBut() {
 		this.data.detail.tradefield.length >= 2 ? wx.showToast({
@@ -183,7 +258,18 @@ Page({
 		this.handleStorage(e.detail.value)
 	},
 	handleStorage(index) {
-		let detail = this.data.detail;
+		let detail = this.data.detail,
+			content = this.data.content;
+		if (detail.iscustomsize == 1) {
+			if (detail.widthschemeid != 0 && content.dwidth == 0) return wx.showToast({
+				title: '请完成定制宽选项',
+				icon: "none"
+			})
+			if (detail.lengthschemeid != 0 && content.dlength == 0) return wx.showToast({
+				title: '请完成定制长选项',
+				icon: "none"
+			})
+		}
 		_Http.basic({
 			"id": 20220924095102,
 			"content": {
@@ -191,7 +277,9 @@ Page({
 				"itemid": detail.itemid, //货品id
 				"qty": detail.orderminqty, //数量
 				itemno: detail.itemno, //货品编号
-				tradefield: detail.tradefield[index].tradefield
+				tradefield: detail.tradefield[index].tradefield,
+				width: content.dwidth,
+				length: content.dlength
 			},
 		}).then(res => {
 			console.log("加入购物车", res)
@@ -206,7 +294,9 @@ Page({
 	},
 	/* 前往购物车 */
 	toCollect(e) {
-		getApp().globalData.changeBar({detail:"Collect"})
+		getApp().globalData.changeBar({
+			detail: "Collect"
+		})
 		wx.navigateBack();
 	}
 })

+ 2 - 1
packageA/market/detail.json

@@ -1,5 +1,6 @@
 {
   "usingComponents": {
-    "van-tag": "@vant/weapp/tag/index"
+    "van-tag": "@vant/weapp/tag/index",
+    "van-stepper": "@vant/weapp/stepper/index"
   }
 }

+ 24 - 2
packageA/market/detail.scss

@@ -7,8 +7,15 @@ swiper {
   background-color: #fff;
 
   swiper-item {
+    position: relative;
     width: 100%;
     height: 100%;
+
+    .tag {
+      position: absolute;
+      top: 20rpx;
+      left: 30rpx;
+    }
   }
 }
 
@@ -92,13 +99,28 @@ swiper {
   margin-top: 20rpx;
 
   .label {
-    height: 70rpx;
-    line-height: 70rpx;
+    padding: 20rpx 0;
     font-size: 28rpx;
     font-weight: 600;
     color: #333333;
     width: 100%;
     border-bottom: 1rpx solid #ddd;
+
+    .product-box {
+      font-weight: 400;
+    }
+
+    .explain {
+      font-size: 24rpx;
+      color: #666;
+      font-weight: normal;
+      margin-left: 10rpx;
+    }
+  }
+
+  .custom {
+    border-bottom: 0 !important;
+    padding: 0 !important;
   }
 
   .product-box {

+ 44 - 1
packageA/market/detail.wxml

@@ -16,6 +16,7 @@
 		{{detail.itemname}} <van-tag type="warning">{{detail.delistingstatus}}</van-tag>
 	</view>
 	<view class="tags">
+		<text wx:if="{{detail.iscustomsize==1}}" style="background-color: #EE0A24;color: #fff;">定制</text>
 		<text wx:for="{{detail.brand}}" wx:key="sa_brandid">{{item.brandname}}</text>
 		<text wx:for="{{detail.tradefield}}" wx:key="index">{{item.tradefield}}</text>
 	</view>
@@ -42,6 +43,7 @@
 		</view>
 	</block>
 
+
 	<block wx:if="{{colorRows.length}}">
 		<view class="label">
 			颜色
@@ -68,6 +70,48 @@
 			<navigator url="#" class="product {{content.cheek===item.parm?'active':''}}  {{item.flag?'':'disabled'}}" wx:for="{{cheekRows}}" wx:key="index" bindtap="changeItemno" data-valuename="cheek" data-value="{{item}}">{{item.parm}}</navigator>
 		</view>
 	</block>
+
+	<!-- 定制项 -->
+	<view wx:if="{{detail.iscustomsize==1}}" style="padding-bottom: 20rpx;">
+		<view class="label">
+			定制
+		</view>
+		<block wx:if="{{cLength}}">
+			<view class="label custom" wx:if="{{cLength.type == '自定义'}}">
+				<view style="display: flex; align-items: center;">
+					<view style="margin-right: 20rpx;">长:</view>
+					<van-stepper plus-class='plus-class' value="{{ content.dlength  }}" input-width="60px" min="{{cLength.min}}" max="{{cLength.max}}" decimal-length="{{ cLength.decimalplaces }}" data-name="cLength" bind:plus='cahngeStepper' bind:blur='cahngeStepper' bind:minus='cahngeStepper' />
+					<view class="explain">{{cLength.min+' ~ '+ cLength.max}},<text wx:if="{{cLength.decimalplaces}}">保留{{cLength.decimalplaces}}位小数</text><text wx:else>不保留小数</text></view>
+				</view>
+			</view>
+			<view class="label custom" wx:else>
+				<view style="display: flex;">
+					<view style="margin-right: 20rpx;margin-top: 30rpx;">长:</view>
+					<view class="product-box">
+						<navigator url="#" class="product {{content.dlength===item.num?'active':''}}" wx:for="{{cLength.rowsdetail}}" wx:key="rowindex" bindtap="customParameter" data-valuename="dlength" data-value="{{item.num}}">{{item.num}}</navigator>
+					</view>
+				</view>
+			</view>
+		</block>
+		<block wx:if="{{cWidth}}">
+			<view class="label custom" wx:if="{{cWidth.type == '自定义'}}">
+				<view style="display: flex; align-items: center;">
+					<view style="margin-right: 10rpx;">宽:</view>
+					<van-stepper plus-class='plus-class' value="{{ content.dwidth }}" input-width="60px" min="{{cWidth.min}}" max="{{cWidth.max}}" decimal-length="{{ cWidth.decimalplaces }}" data-name="cWidth" bind:plus='cahngeStepper' bind:blur='cahngeStepper' bind:minus='cahngeStepper' />
+					<view class="explain">{{cWidth.min+' ~ '+ cWidth.max}},<text wx:if="{{cWidth.decimalplaces}}">保留{{cWidth.decimalplaces}}位小数</text><text wx:else>不保留小数</text></view>
+				</view>
+			</view>
+			<view class="label custom" wx:else>
+				<view style="display: flex;">
+					<view style="margin-right: 20rpx;margin-top: 30rpx;">宽:</view>
+					<view class="product-box">
+						<navigator url="#" class="product {{content.dwidth===item.num?'active':''}}" wx:for="{{cWidth.rowsdetail}}" wx:key="rowindex" bindtap="customParameter" data-valuename="dwidth" data-value="{{item.num}}">{{item.num}}</navigator>
+					</view>
+				</view>
+			</view>
+		</block>
+	</view>
+
 </view>
 <van-tabs custom-class='tabs' title-active-color='var(--assist)' color='var(--assist)'>
 	<van-tab title="商品简介">
@@ -95,7 +139,6 @@
 		</view>
 		购物车
 	</navigator>
-
 	<picker wx:if="{{detail.tradefield.length>=2}}" range='{{detail.tradefield}}' range-key='tradefield' bindchange='storage'>
 		<view class="bg-orange submit" bindtap="clickBut">加入购物车</view>
 	</picker>

+ 1 - 1
packageA/market/selected/index.wxml

@@ -20,7 +20,7 @@
             </view>
         </view>
     </navigator>
-    <My_empty wx:if="{{!list.length}}" />
+    <Yl_Empty wx:if="{{!list.length}}" />
 </Yl_ListBox>
 <wxs module="handle">
     module.exports = {