From 5c4a5221e7cf9d4c432bebda216dd6a1525a7af5 Mon Sep 17 00:00:00 2001 From: jiazhipeng Date: Fri, 14 Nov 2025 16:03:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=B9=E4=BA=A7=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.private.config.json | 11 ++++- subPackages/postSearch/index.js | 76 ++++++++++++++++++++++++++----- subPackages/postSearch/index.wxml | 36 ++++++++++++--- subPackages/postSearch/index.wxss | 56 ++++++++++++++++++++++- 4 files changed, 157 insertions(+), 22 deletions(-) diff --git a/project.private.config.json b/project.private.config.json index 96a56ce..d731040 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -6,12 +6,19 @@ "condition": { "miniprogram": { "list": [ + { + "name": "subPackages/postSearch/index", + "pathName": "subPackages/postSearch/index", + "query": "type_id=1&ids=", + "scene": null, + "launchMode": "default" + }, { "name": "pages/info/postProductInfo/index", "pathName": "pages/info/postProductInfo/index", "query": "id=462080", - "scene": null, - "launchMode": "default" + "launchMode": "default", + "scene": null }, { "name": "pages/info/postProductInfo/index", diff --git a/subPackages/postSearch/index.js b/subPackages/postSearch/index.js index 2f9224d..9773beb 100644 --- a/subPackages/postSearch/index.js +++ b/subPackages/postSearch/index.js @@ -26,7 +26,9 @@ Page({ totalPrice:0, //获取购物车总价--打开购物车后勾选的产品价格 nowAddListId:[], type:'', //购物车分类1文创,2非遗 - show:false + show:false, + + user_type: null, }, /** @@ -60,6 +62,14 @@ Page({ }, // 添加产品到购物车 addCart: function (e) { + if (![0,1].includes(this.data.user_type)) { + wx.showToast({ + title: "请选择配送方式", + icon:"none" + }) + return + } + let item = e.currentTarget.dataset.item app.globalData.postProduct = [] app.globalData.list = [] @@ -72,7 +82,8 @@ Page({ commonApi.user_post("cart_within/add_sku", { sku_id: this.data.showPopup ? item.sku.id :this.data.info.sku[this.data.skuIndex].id, num: this.data.producNum, - type:this.data.type + type:this.data.type, + delivery_method: this.data.user_type }).then(res => { if (res.code == 1) { let sku_id = this.data.showPopup ? item.sku.id :this.data.info.sku[this.data.skuIndex].id @@ -107,6 +118,9 @@ Page({ if (element.selected == 1) { totalPrice += Number(element.num*element.sku.price) } + if (element.delivery_method === null) { + element.delivery_method = element.sku.sku_model.use_type == 1?1:0 + } }) console.log(res.data); let status = res.data.every(el => el.selected === 1) @@ -173,7 +187,7 @@ Page({ if (item.product.type == 'post') { product.push({ product: item.product, - sku: item.sku, + sku: {...item.sku, use_type: item.delivery_method||0}, productNum: item.num }) } else { @@ -207,6 +221,29 @@ Page({ isCar: 'single' }) } + + let repeatSku = product.find(x=>product.filter(v=>v.sku.id == x.sku.id).length>1) + if(repeatSku) { + let str = `${repeatSku.product.title}-${repeatSku.sku.sku_name}邮寄和自提只能选择一种` + wx.showModal({ + content: str, + showCancel: false, + complete: (res) => {} + }) + return + } + + + let useType = product[0].sku.use_type + let flag = this.data.flag, isCar = "single"; + if (product.some(x=>x.sku.use_type!=useType)) { + flag = "mix" + isCar = "multiple" + } + this.setData({ + flag: flag, + isCar: isCar + }) console.log(product1); app.globalData.postProduct = product; if (app.globalData.list) { @@ -248,10 +285,10 @@ selectedIt(e) { delAll() { let ids = [] this.data.gwcList.forEach(item => { - ids.push(item.sku_id) + ids.push(item.id) }) commonApi.user_post("cart_within/del_sku", { - sku_id: ids+'', + id: ids+'', type:this.data.type }).then(res => { if (res.code == 1) { @@ -270,9 +307,10 @@ delAll() { del(e) { let item = e.currentTarget.dataset.item let gwcList = this.data.gwcList + let valueNum = e.currentTarget.dataset.value commonApi.user_post("cart_within/update_sku", { - num:item.num-1, - sku_id: item.sku_id, + num:item.num + valueNum, + id: item.id, type:this.data.type }).then(res => { if (res.code == 1) { @@ -295,6 +333,9 @@ del(e) { if (item.selected ==1) { totalPrice += item.num*item.sku.price } + if (item.delivery_method === null) { + item.delivery_method = item.sku.sku_model.use_type == 1?1:0 + } }) } let status = res.data.every(el => el.selected === 1) @@ -367,6 +408,9 @@ openPopup() { if (item.selected == 1) { totalPrice += item.num*item.sku.price } + if (item.delivery_method === null) { + item.delivery_method = item.sku.sku_model.use_type == 1?1:0 + } }) // console.log(arr); // debugger @@ -380,7 +424,8 @@ openPopup() { }, search() { this.setData({ - list:[] + list:[], + show:false }) this.getList() }, @@ -390,9 +435,6 @@ openPopup() { }) }, getList() { - this.setData({ - show:false - }) let list= this.data.list; if (this.data.keywords == '' || this.data.keywords.indexOf(' ')!==-1) { return @@ -445,6 +487,9 @@ openPopup() { }, // 添加产品弹窗 1.首先获取到该产品下的规格 addBuyCart(e) { + this.setData({ + user_type: null + }) let item = e.currentTarget.dataset.item console.log(item); commonApi._post("product/get_product_detail", { @@ -501,9 +546,16 @@ openPopup() { selectSku: function (e) { let index = e.currentTarget.dataset.index; this.setData({ - skuIndex: index + skuIndex: index, + user_type: null, }) }, + changeSelectSkuPost: function(e) { + let value = e.currentTarget.dataset.value; + this.setData({ + user_type: value, + }) +}, // 关闭弹窗 hideSku: function () { this.setData({ diff --git a/subPackages/postSearch/index.wxml b/subPackages/postSearch/index.wxml index e6bcff6..88569f7 100644 --- a/subPackages/postSearch/index.wxml +++ b/subPackages/postSearch/index.wxml @@ -1,18 +1,18 @@ - + | - 搜索 + 搜索 - + @@ -83,6 +83,25 @@ {{producNum}} + + 配送方式 + + + + + + + 邮寄 + + + + + + + 自提 + + + - + @@ -114,7 +133,10 @@ - + + + {{item.delivery_method==1?"自提":"邮寄"}} + {{item.product.title}} @@ -123,9 +145,9 @@ {{item.sku.price/100}} - + {{item.num}} - + diff --git a/subPackages/postSearch/index.wxss b/subPackages/postSearch/index.wxss index b6f55f5..4786b53 100644 --- a/subPackages/postSearch/index.wxss +++ b/subPackages/postSearch/index.wxss @@ -318,7 +318,7 @@ display: flex; font-size: 29rpx; color: #333; - margin: 0 40rpx; + margin: 0 30rpx; text-align: center; flex-wrap: wrap; margin-bottom: 20rpx; @@ -472,3 +472,57 @@ font-size: 24rpx; font-weight: 500; } +.delivery-method{ + font-weight: 400; + font-size: 29rpx; + color: #1E1E1E; + display: flex; + justify-content: space-between; + align-items: center; + padding: 0 40rpx 40rpx; +} +.delivery-method .select-cycle{ + width: 32rpx; + height: 32rpx; + border-radius: 50%; + border: 1px solid #999999; + overflow: hidden; + flex-shrink: 0; + +} +.delivery-method .select-cycle image{ + width: 100%; + height: 100%; +} +.delivery-method .select-cycle.selected { + border: none; +} +.delivery-method .select-cycle.selected image{ + width: 32rpx; + height: 32rpx; + border-radius: 50%; +} +.delivery-method .method-str{ + padding-left: 10rpx; + flex-shrink: 0; +} +.delivery-method .flex-center{ + width: 150rpx; + justify-content: flex-end; + display: flex; + align-items: center; +} + .use-type{ + position: absolute; + left: 0; + bottom: 0; + width: 100%; + border-radius: 0rpx 0rpx 7rpx 7rpx; + height: 33rpx; + background: rgba(0,0,0,0.3); + font-weight: 400; + font-size: 24rpx; + color: #FFFFFF; + text-align: center; + line-height: 33rpx; +} \ No newline at end of file