From 8787e14e68788e1459336dc459de97fe5fa70b95 Mon Sep 17 00:00:00 2001 From: "@fawn-nine" <1271023382@qq.com> Date: Tue, 19 Sep 2023 12:01:14 +0800 Subject: [PATCH] 0919 --- pages/bookShop/commodityDetail.vue | 251 ++++++++++++++++++++++++++--- 1 file changed, 232 insertions(+), 19 deletions(-) diff --git a/pages/bookShop/commodityDetail.vue b/pages/bookShop/commodityDetail.vue index ca45d29..074e921 100644 --- a/pages/bookShop/commodityDetail.vue +++ b/pages/bookShop/commodityDetail.vue @@ -13,34 +13,39 @@ - - {{productInfo.price}} - 原价{{productInfo.activityPrice}} + + {{productInfo.activityPrice}} + 原价{{productInfo.price}} + + + {{productInfo.price}} {{productInfo.productName}} (无货) 已售{{productInfo.sumSales}} - + - 商品包含 + 其他购买套餐 - - - + + + - + - {{item.name}} + {{item.productName}} + ¥{{item.activityPrice}} + ¥{{item.price}} - - - 暂无评价~ - + + @@ -155,6 +160,34 @@ + + + + + + + + + 查看详情 + + + + + + + + {{item.productName}} + ¥{{item.activityPrice}} + ¥{{item.price}} + + + + + + + + @@ -172,6 +205,7 @@ export default { data() { return { + linkimg:'', // 选中的关联商品图片 playData:{}, contentShow:0, options: [{ @@ -204,13 +238,17 @@ cartList: [], // 购物车列表 commentsList:[], // 评论列表 productId:null, // 商品评论 - listenList:[] // 关联得听书 + listenList:[], // 关联得听书 + linkProducts:[], // 关联的商品, + upoShow:false, // 显示底部购买选项 + linkCur : 0, // 当前选中的关联项 } }, onLoad(e) { this.productId = e.id this.getProDetail(e) this.getComments() + this.getLinkPros(this.productId) // console.log(emojiList1,'emojiList1') }, computed: { @@ -220,6 +258,41 @@ musicPlay }, methods: { + gotoDetail(item){ + console.log(item,'gotoDetail') + uni.navigateTo({ + url: '../bookShop/commodityDetail?id=' + item.productId + }); + }, + closeUpo(){ + console.log('关闭弹窗') + this.upoShow = false + }, + // 点击其他套餐 + previewProduct(item,index){ + console.log(item,'item') + this.linkimg = item.productImages + this.upoShow = true + this.linkCur = index + }, + // 获取商品关联商品 + getLinkPros(id){ + this.$http + .post('book/shopproduct/bookinfolists/'+id) + .then(res => { + console.log('关联商品', res) + if(res.code == 0){ + this.linkProducts = res.result + if(this.linkProducts.length > 0){ + this.linkimg = this.linkProducts[0].productImages + this.linkCur = 0 + } + } + }) + .catch(e => { + console.log(e,'e') + }) + }, goToListen(id){ // 跳转到听书 uni.navigateTo({ @@ -331,15 +404,50 @@ url: '../peanut/shopping' }); }, + // 关联商品点击按钮组件 + buttonClickLink(e){ + console.log('点击的是关联商品的组件') + if(e.index == 0){ + // 点击的是加入购物车 + if (this.linkProducts[this.linkCur].productStock == 0) { + uni.showToast({ + title: '商品库存不足', + icon: "none", + duration: 1000, + }); + } else { + this.$http + .post(`book/ordercart/getCartList?userId=${this.userInfo.id}`) + .then(res => { + this.cartList = res.cartList + this.isAddLink(this.linkProducts[this.linkCur]) + }) + } + }else{ + // 点击的是立即购买 + if (this.linkProducts[this.linkCur].productStock == 0) { + uni.showToast({ + title: '商品库存不足', + icon: "none", + duration: 1000, + }); + } else { + uni.navigateTo({ + url: '../bookShop/settlement?type=2&list=' + this.linkProducts[this.linkCur].productId + }); + } + } + }, // 点击按钮组间 buttonClick(e) { console.log(e) if(e.index == 0){ - // 点击的是加入购物车 + // 点击的是加入购物车 this.addCart() }else{ // 点击的是立即购买 - this.goPurse() + this.upoShow = true + // this.goPurse() } }, goToListenNone(){ @@ -366,6 +474,83 @@ } }, + isAddLink(item) { + // 统计商品信息 + let data = { + "userId": this.userInfo.id, + "productId": item.productId, + "productAmount": this.productAmount, + "price": item.price + } + // 判断列表是否为空 + if (this.cartList.length > 0) { + let flag = '' + let shagnpin = {} + // 循环购物车列表 + flag = this.cartList.some((item, index) => { + if (item.productId == data.productId) { + shagnpin = item + shagnpin.productAmount = item.productAmount + 1 + return true + } + }) + if (flag) { + // 已在购物车中添加 + $http.request({ + url: "book/ordercart/update", + method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档 + data: shagnpin, + header: { //默认 无 说明:请求头 + 'Content-Type': 'application/json' + }, + }).then(res => { + if (res.code == 0) { + this.upoShow = false + uni.showToast({ + title: '加入购物车成功', + duration: 1000, + }); + } + }) + } else { + // 加入购物车 + $http.request({ + url: "book/ordercart/save", + method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档 + data, + header: { //默认 无 说明:请求头 + 'Content-Type': 'application/json' + }, + }).then(res => { + if (res.code == 0) { + this.upoShow = false + uni.showToast({ + title: '加入购物车成功', + duration: 1000, + }); + } + }) + } + + } else { + // 购物车列表为空时直接加入购物车 + $http.request({ + url: "book/ordercart/save", + method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档 + data, + header: { //默认 无 说明:请求头 + 'Content-Type': 'application/json' + }, + }).then(res => { + if (res.code == 0) { + uni.showToast({ + title: '加入购物车成功', + duration: 1000, + }); + } + }) + } + }, isAdd() { // 统计商品信息 let data = { @@ -517,6 +702,30 @@ formatRichText (html) { //控制小程序中图片大小 }