Browse Source

购物车定制产品

xiaohaizhao 1 year ago
parent
commit
4214c88917

+ 32 - 3
pages/index/collect/index.js

@@ -22,12 +22,34 @@ Component({
 	methods: {
 		init() {
 			this.getList()
-			this.selectComponent("#ListBox").setHeight(".head", this);
 			this.setData({
-        hidePrice: wx.getStorageSync('hidePrice'),
-      })
+				hidePrice: wx.getStorageSync('hidePrice'),
+			})
+			getApp().globalData.customizedProduct = this.customizedProduct.bind(this);
 			return true;
 		},
+		customizedProduct(item) {
+			return new Promise((resolve) => {
+				console.log(item)
+				_Http.basic({
+					"id": 20220924104302,
+					"content": {
+						"sa_shoppingcartid": item.sa_shoppingcartid,
+						"qty": item.qty,
+						"width": item.width,
+						"length": item.length
+					},
+				}).then(res => {
+					console.log("修改定制", res)
+					wx.showToast({
+						title: res.msg != '成功' ? res.msg : '修改成功',
+						icon: "none"
+					});
+					this.getList()
+					resolve(true)
+				})
+			})
+		},
 		/* 获取列表 */
 		getList() {
 			_Http.basic({
@@ -44,6 +66,7 @@ Component({
 			}).then(res => {
 				console.log('购物车列表', res)
 				this.selectComponent('#ListBox').RefreshToComplete();
+				this.selectComponent("#ListBox").setHeight(".head", this);
 				if (res.msg != '成功') return wx.showToast({
 					title: res.msg,
 					icon: "none"
@@ -178,6 +201,12 @@ Component({
 			})
 			this.computeSum();
 		},
+		customization(e) {
+			const {
+				item
+			} = e.target.dataset;
+			if (item) this.selectComponent("#Custom").onClick(item)
+		},
 		/* 计算总价/产品领域分类 */
 		computeSum() {
 			let results = this.data.results,

+ 2 - 1
pages/index/collect/index.json

@@ -3,6 +3,7 @@
 	"usingComponents": {
 		"van-checkbox": "@vant/weapp/checkbox/index",
 		"van-stepper": "@vant/weapp/stepper/index",
-		"van-swipe-cell": "@vant/weapp/swipe-cell/index"
+		"van-swipe-cell": "@vant/weapp/swipe-cell/index",
+		"custom": "./modules/custom"
 	}
 }

+ 0 - 1
pages/index/collect/index.scss

@@ -67,7 +67,6 @@ page {
 				font-size: 28rpx;
 				font-weight: 600;
 				color: #FF3B30;
-				bottom: 0rpx;
 				right: 10rpx;
 			}
 		}

+ 6 - 3
pages/index/collect/index.wxml

@@ -1,8 +1,9 @@
 <view class="head" />
+<custom id="Custom" />
 <Yl_ListBox id='ListBox' bind:getlist='getList'>
 	<van-swipe-cell wx:for="{{list}}" wx:key="itemid" id="swipe-cell" right-width="{{ 65 }}" async-close data-item="{{item}}" bind:close="deteleItem">
 		<view url="#" class="item-box">
-			<view class="top" bindtap="changeResults" data-item="{{item}}">
+			<view class="top" catch:tap="changeResults" data-item="{{item}}">
 				<view class="image">
 					<van-image width="100%" height="100%" fit="cover" src="{{item.attinfos[0].subfiles[0].url||item.attinfos[0].url||item.cover}}" use-loading-slot use-error-slot lazy-load>
 						<van-loading slot="loading" type="spinner" size="20" vertical />
@@ -19,7 +20,10 @@
 					<view class="exp">型号:{{item.model ||" --"}}</view>
 					<view class="exp">品牌:{{item.brandname ||" --"}}</view>
 					<view class="exp">领域:{{item.tradefield_shoppingcart ||" --"}}</view>
-					<view class="price"> {{handleHide.query(item.showPrice,hidePrice)}}/{{item.unitname}}</view>
+					<view class="exp" wx:if="{{item.iscustomsize}}" data-item="{{item}}" catch:tap="customization" style="color:#085CDF;">
+						长:{{item.length}} / 宽:{{item.width}} <van-icon name="arrow-down" />
+					</view>
+					<view class="price" style="bottom: {{item.iscustomsize?'40rpx':'0rpx'}};">{{handleHide.query(item.showPrice,hidePrice)}}/{{item.unitname}}</view>
 				</view>
 			</view>
 			<view class="bottom">
@@ -62,5 +66,4 @@
 		}
 	}
 </wxs>
-
 <wxs src="/utils/hidePrice.wxs" module="handleHide" />

+ 93 - 0
pages/index/collect/modules/custom.js

@@ -0,0 +1,93 @@
+const _Http = getApp().globalData.http;
+Component({
+  properties: {},
+  data: {
+    item: null,
+    show: false
+  },
+  methods: {
+    onClick(item) {
+      console.log(item)
+      console.log(this.data.product)
+      if (this.data.product != null && item.itemid == this.data.product.itemid) return this.setData({
+        show: true
+      })
+      wx.showLoading({
+        title: '获取定制方案中..',
+      })
+      let arr = [];
+      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 => {
+        console.log("获取定制方案", s)
+        wx.hideLoading();
+        if (s.some(c => c.msg != '成功')) return wx.showToast({
+          title: '定制方案获取失败',
+          icon: "none"
+        })
+        if (item.lengthschemeid) arr.push(s[0].data)
+        if (item.widthschemeid) arr.push(s[1].data)
+
+        this.setData({
+          show: true,
+          arr,
+          product: item
+        });
+        console.log("arr", arr, item)
+      });
+
+      this.selectComponent("#Dialog").data.beforeClose = (action) => new Promise((resolve) => {
+        if (action === 'confirm') {
+          getApp().globalData.customizedProduct(this.data.product).then(res => {
+            resolve(true);
+          })
+        } else {
+          resolve(false);
+          this.setData({
+            show: false
+          })
+        }
+      });
+    },
+    selected(e) {
+      const {
+        name,
+        num
+      } = e.currentTarget.dataset;
+      this.data.product[name] = num;
+      this.setData({
+        product: this.data.product
+      })
+    },
+    /* 定制步进器 */
+    cahngeStepper(e) {
+      const {
+        name,
+        item
+      } = e.currentTarget.dataset,
+        product = this.data.product;
+      if (e.type == 'plus') {
+        product[name] += 1
+      } else if (e.type == 'minus') {
+        product[name] -= 1
+      } else {
+        product[name] = (e.detail.value - 0).toFixed(product.decimalplaces);
+      }
+      if (product[name] > item.max) product[name] = item.max;
+      if (product[name] < item.min) product[name] = item.min;
+      this.setData({
+        product
+      })
+    },
+  }
+})

+ 7 - 0
pages/index/collect/modules/custom.json

@@ -0,0 +1,7 @@
+{
+  "component": true,
+  "usingComponents": {
+    "van-dialog": "@vant/weapp/dialog/index",
+    "van-stepper": "@vant/weapp/stepper/index"
+  }
+}

+ 44 - 0
pages/index/collect/modules/custom.scss

@@ -0,0 +1,44 @@
+.box {
+	width: 100%;
+	padding: 0 30rpx 20rpx;
+	box-sizing: border-box;
+
+	.item {
+		display: flex;
+		margin-top: 20rpx;
+
+		.label {
+			font-weight: 700;
+		}
+
+		.selectable {
+			display: flex;
+			flex-wrap: wrap;
+
+			.num {
+				border: 1px solid #ddd;
+				margin-right: 8rpx;
+				padding: 4rpx 15rpx;
+				border-radius: 8rpx;
+				font-size: 26rpx;
+				margin-bottom: 10rpx;
+			}
+
+			.active {
+				border: 1px solid #085CDF;
+				color: #085CDF;
+				font-weight: 700;
+			}
+		}
+
+		.stepper {
+
+			.explain {
+				font-size: 24rpx;
+				color: #999;
+				margin-top: 6rpx;
+			}
+		}
+
+	}
+}

+ 19 - 0
pages/index/collect/modules/custom.wxml

@@ -0,0 +1,19 @@
+<van-dialog id="Dialog" use-slot title="定制" show="{{ show }}" asyncClose confirm-button-color='#085CDF' show-cancel-button>
+	<view class="box">
+		<view class="item" wx:for="{{arr}}" wx:key="name">
+			<view class="label">
+				{{item.schemename}}:
+			</view>
+			<view class="selectable" wx:if="{{item.type=='可选'}}">
+				<view class="num {{product[item.schemename=='宽'?'width':'length']==it.num?'active':''}}" wx:for="{{item.rowsdetail}}" wx:for-item='it' wx:key="rowno" data-name="{{item.schemename=='宽'?'width':'length'}}" data-num="{{it.num}}" catch:tap='selected'>
+					{{it.num}}
+				</view>
+			</view>
+
+			<view class="stepper" wx:else>
+				<van-stepper value="{{ product[item.schemename=='宽'?'width':'length'] }}" input-width="60px" min="{{item.min}}" max="{{item.max}}" decimal-length="{{ item.decimalplaces }}" data-item="{{item}}" data-name="{{ item.schemename=='宽'?'width':'length' }}" bind:plus='cahngeStepper' bind:blur='cahngeStepper' bind:minus='cahngeStepper' />
+				<view class="explain">{{item.min+' ~ '+ item.max}},<text wx:if="{{item.decimalplaces}}">保留{{item.decimalplaces}}位小数</text><text wx:else>不保留小数</text></view>
+			</view>
+		</view>
+	</view>
+</van-dialog>