소스 검색

添加定制产品逻辑

xiaohaizhao 1 년 전
부모
커밋
624beea34e
3개의 변경된 파일48개의 추가작업 그리고 5개의 파일을 삭제
  1. 40 3
      select/product/index.js
  2. 2 1
      select/product/index.json
  3. 6 1
      select/product/index.wxml

+ 40 - 3
select/product/index.js

@@ -28,7 +28,20 @@ Page({
 			showName: options.showName || this.data.showName,
 			newPrice: options.newprice || "price", //红色价格
 		});
-		this.getList()
+		this.getList();
+		getApp().globalData.customizedProduct = this.customizedProduct.bind(this);
+	},
+	customizedProduct(item) {
+		return new Promise((resolve) => {
+			let index = this.data.list.findIndex(v => v[this.data.idname] == item[this.data.idname]);
+			if (index != -1) this.data.list[index] = item;
+			if (item.pitchOn) this.data.result.push(item[this.data.idname])
+			this.setData({
+				list: this.data.list,
+				result: this.data.result
+			})
+			resolve(true)
+		})
 	},
 	getList(init = false) {
 		//init 用于初始化分页
@@ -59,6 +72,8 @@ Page({
 				value.brandName = value.brand.map(name => name.brandname)
 				value.tradefields = value.tradefield.map(name => name.tradefield)
 				value.qty = value.orderminqty;
+				value.width = 0;
+				value.length = 0;
 				return value;
 			})
 			this.setData({
@@ -70,15 +85,37 @@ Page({
 			})
 		})
 	},
+	customization(e) {
+		let {
+			item
+		} = e.target.dataset;
+		item.pitchOn = false;
+		if (item) this.selectComponent("#Custom").onClick(item)
+	},
 	/* 选中 */
 	changeResult(e) {
 		let {
-			id
+			id,
+			item
 		} = e.currentTarget.dataset, result = this.data.result;
 		if (this.data.radio) {
 			result = [id];
 		} else {
-			result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
+			let isAdd = result.some(v => v == id);
+			if (!isAdd) {
+				if (item.iscustomsize == 1) {
+					if ((item.widthschemeid && item.width == 0) || (item.lengthschemeid && item.length == 0)) {
+						item.pitchOn = true;
+						if (item) this.selectComponent("#Custom").onClick(item)
+					} else {
+						result.push(id)
+					}
+				} else {
+					result.push(id)
+				}
+			} else {
+				result = result.filter(v => v != id)
+			}
 		}
 		this.setData({
 			result

+ 2 - 1
select/product/index.json

@@ -1,5 +1,6 @@
 {
 	"usingComponents": {
-		"van-stepper": "@vant/weapp/stepper/index"
+		"van-stepper": "@vant/weapp/stepper/index",
+		"custom": "../../pages/index/collect/modules/custom"
 	}
 }

+ 6 - 1
select/product/index.wxml

@@ -1,12 +1,13 @@
 <import src="index.skeleton.wxml" />
 <template is="skeleton" wx:if="{{loading}}" />
+<custom id="Custom" />
 
 <van-search class="search" value="{{ params.content.where.condition }}" shape="round" placeholder="请输入搜索关键词" bind:search='startSearch' bind:clear='onClear' />
 <view class="total">共{{params.content.total}}个</view>
 
 <Yl_ListBox id='ListBox' bind:getlist='getList'>
     <view class="setclient-list-item" wx:for="{{list}}" wx:key="itemno">
-        <navigator url="#" class="mian" data-id="{{item[idname]}}" bindtap="changeResult">
+        <navigator url="#" class="mian" data-id="{{item[idname]}}" data-item="{{item}}" bindtap="changeResult">
             <van-checkbox wx:if="{{!radio}}" value="{{ handle.isCheck(item[idname],result) }}" shape="square" icon-size='28rpx' />
             <view class="img" data-file="{{item.attinfos}}" catchtap="viewImage">
                 <van-image width="100%" height="100%" wx:if="{{item.cover}}" src="{{item.cover}}" use-loading-slot use-error-slot lazy-load>
@@ -32,6 +33,10 @@
                 <view class="subfield line-1">
                     规格:{{item.spec||' --'}}
                 </view>
+                <view wx:if="{{item.iscustomsize}}" class="subfield line-1" data-item="{{item}}" catch:tap="customization" style="color:#085CDF;">
+                    长:{{item.length}} / 宽:{{item.width}}
+                    <van-icon name="arrow-down" />
+                </view>
                 <view class="price line-1">
                     价格:<text class="num">{{handleHide.query(item.newPrice,hidePrice)}}元</text>
                 </view>