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 1/2] 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) { //控制小程序中图片大小 } diff --git a/pages/listen/home.vue b/pages/listen/home.vue index bb7709d..ae645a1 100644 --- a/pages/listen/home.vue +++ b/pages/listen/home.vue @@ -54,6 +54,7 @@ + diff --git a/pages/listen/listen.vue b/pages/listen/listen.vue index 040073c..52f5f31 100644 --- a/pages/listen/listen.vue +++ b/pages/listen/listen.vue @@ -30,6 +30,11 @@ {{item.title}} >

+ + + + + @@ -69,7 +74,7 @@ sort:0 可以听 sort:1 不可以听 --> - + + @@ -185,6 +191,19 @@ }, methods: { ...mapMutations(['setUserInfo']), + // 查看本书更多书评 + toMore(val){ + console.log(val,'val') + uni.navigateTo({ + url: '../comments/comments?bookid='+ this.bookid, + }); + }, + // 去打卡 + gotoclock(){ + uni.navigateTo({ + url: '../clock/clock?bookid='+ this.bookid, + }); + }, getBookInfo(){ // 获取书本基本信息 this.$http @@ -315,17 +334,6 @@ uni.navigateTo({ url: '../bookShop/settlementBook?type=2&list=' + this.bookid }); - // uni.showModal({ - // title: '提示', - // cancelText: '暂不购买', - // confirmText:'立即购买', - // content: '确定花费¥95元购买本书电子版吗?', - // success: function (res) { - // if (res.confirm) { - // console.log('用户点击确定'); - // } - // } - // }); }, @@ -335,42 +343,8 @@ url: '../eBook/bookMessage?Id=' + id + '&typ=' + e }); }, - - // 第一次加载音乐播放器 - firstListen(){ - this.forceRefresh = false - this.$http - .post('book/bookchaptercontent/appBooksChapterContent', { - 'userId': this.userInfo.id, - 'bookid': this.bookid, - 'id': this.playid - }) - .then(res => { - //this.tmpChapter.text = res.bookCatalogue - if(res.code == 0){ - if(res.bookCatalogue.voices[0] != null){ - // console.log('走这') - this.videoList = [] - this.boardRemark = res.bookCatalogue.chapter[0] - this.fengImg = res.image - this.videoList.push({'recorPath':res.bookCatalogue.voices[0]}) - // console.log(res.bookCatalogue.voices[0],'path') - this.forceRefresh = true - }else{ - uni.showToast({ - title:'暂无可播放音频~', - icon:'none', - duration:2000 - }) - setTimeout(()=>{ - uni.navigateBack({ // 返回上一页 - delta: 1 - }); - },2000) - } - } - }).catch((e)=>{}) - }, + + // 存储播放进度 saveRate(val){ this.$http @@ -430,16 +404,17 @@ if(res.BookCatalogue.length > 0){ this.libLIst = res.BookCatalogue // this.fengImg = res.images - }else{ - uni.showToast({ - title:'暂无可听章节哦~', - icon:'none' - }) - setTimeout(()=>{ - uni.navigateBack({ // 返回上一页 - delta: 1 - }); - },2000) + }else{ + this.libLIst = [] + // uni.showToast({ + // title:'暂无可听章节哦~', + // icon:'none' + // }) + // setTimeout(()=>{ + // uni.navigateBack({ // 返回上一页 + // delta: 1 + // }); + // },2000) } } }).catch((e)=>{ @@ -541,6 +516,11 @@ .price{ margin-top: 160rpx; overflow: hidden; .light{font-size: 50rpx; font-weight: bold; color: #f05654;} } + .tags{ + .tag{ + margin-left: 0; margin-right: 10rpx; + } + } .charType{display: inline; width:20px !important;} .graytitle{color: #999;} .yigoumai{background-color: #ffc773;} diff --git a/pages/peanut/home.vue b/pages/peanut/home.vue index 2d00839..6d373af 100644 --- a/pages/peanut/home.vue +++ b/pages/peanut/home.vue @@ -2,62 +2,65 @@ - + - + + + + 请输入想要搜索的书名 - + - + + - - - - 读书打卡 - - - + + + + 读书打卡 + + + 听书 - - - + + + 书评 - + 图书馆 - + - + - + + - + - + 新书上市 - - + + - - - - + + + + + + {{item.productName}} - {{item.productName}} - - - + + + + + + + + + 精选商品 查看更多 > - + + 精选图书 + 折扣图书 + - - - - - {{item.productName}} - - - ¥{{item.price}} - 已售:{{item.sumSales}} 件 + + + + + + + + {{item.productName}} + + + ¥{{item.activityPrice}} + ¥{{item.price}} + 已售:{{item.sumSales}} 件 + - -
-
- - - 努力加载中 - - - +
+
+ +
+ + + + + + + + {{item.productName}} + + + + + {{item.activityPrice}} + + + 原价:¥{{item.price}} + 已售:{{item.sumSales}} 件 + + + + +
+
+ +
+ - +
@@ -165,26 +260,23 @@ import repciptData from '@/static/json/repcipt.json' import $http from '@/config/requestConfig.js'; import { - mapState, - mapMutations + mapState,mapMutations } from 'vuex'; export default { data() { return { - myList: [], - showEbook: false, // 显示电子书相关 + myList:[], + showEbook:false, // 显示电子书相关 transaction: { // 成功回调 - + }, - status: 3, - jPage: 1, - jTotal: 0, - scrollLeft: 0, - maxTimes: 1, // 轮询最大次数 - ComplateRequestInterval: null, // 轮询定时器 - checking: false, // 正在检测 - ComplateRequestArr: [], - iapChannel: null, + tabsNumber : 0, + scrollLeft:0, + maxTimes:1, // 轮询最大次数 + ComplateRequestInterval:null, // 轮询定时器 + checking:false, // 正在检测 + ComplateRequestArr:[], + iapChannel:null, scrollTop: 0, list3: [ // '../../static/icon/home_ban_1.jpg', @@ -195,11 +287,12 @@ limiTist: [], jingList: [], seckillList: [], + offSaleList:[], // 折扣列表 goodsList: [], bgiStyle: { background: '#fff' }, - newBookList: [], + newBookList:[], iconStyle: { fontSize: '40rpx', fontWeight: 'bold', @@ -214,16 +307,15 @@ onLoad(e) { // 隐藏原生的tabbar uni.hideTabBar(); - // this.requestIapOrder() + // this.requestIapOrder() }, //页面显示 onShow() { // 隐藏原生的tabbar uni.hideTabBar(); - this.goodsList = [] - this.getData(); - - + this.getData(); + + }, // 页面加载完毕 onReady() { @@ -231,27 +323,12 @@ }, // 下拉刷新 onPullDownRefresh() { - console.log('下拉刷新') - this.jPage = 1 - this.goodsList = [] this.getData() uni.stopPullDownRefresh() - this.requestIapOrder() + this.requestIapOrder() }, - onHide() { - this.jPage = 1 - this.goodsList = [] - }, - onReachBottom() { - console.log('到底了') - // if (this.jPage + 1 <= this.jTotal) { - // this.jPage++ - // this.getJBook() - // } else { - // this.status = 1 - // } - }, + filters: { // 控制字数 ellipsis(value) { @@ -268,72 +345,78 @@ computed: { ...mapState(['userInfo']), }, - components: { + components:{ musicPlay }, //方法 methods: { ...mapMutations(['setUserInfo']), - gotopingshu(val) { - uni.navigateTo({ - url: '../comments/comments?bookid=' + val.id, - }); + tabsChange(num){ + if(num != this.tabsNumber){ + this.tabsNumber = num + } }, - // 去打卡 - gotoclock(item) { - this.onPageJump('../clock/clock?bookid=' + item.id) - }, - // 去听书 - gotoListen(item) { - uni.navigateTo({ - url: "../listen/listen?bookid=" + item.id - }); + // 获取折扣图书 + getOffSale(){ + this.$http + .post('book/shopproduct/listactivityprice?limit=10&page=1') + .then(res => { + console.log(res,'折扣') + if(res.code == 0 && res.page.list.length > 0){ + this.offSaleList = res.page.list + this.tabsNumber = 0 + } + + + }).catch(e => { + console.log(e,'e') + }); }, // 新书上市 - getNewBook() { + getNewBook(){ this.$http - .post('book/shopproduct/getNewBook', { + .post('book/shopproduct/getNewBook',{ 'limit': 10, - 'page': 1 + 'page':1 }) .then(res => { - console.log(res, 'xinshu') - this.newBookList = res.page.list + console.log(res,'xinshu') + this.newBookList = res.page.list }); }, // 检测未完成订单 - requestIapOrder() { + requestIapOrder(){ console.log('检测支付环境...') plus.payment.getChannels((channels) => { console.log(channels, 'channels') //this.setUserInfo({channelList:channels}); // 将支付通道保存到本地 - for (var i in channels) { + for (var i in channels) { // 判断是否苹果支付1 if (channels[i].id === 'appleiap') { - this.iapChannel = channels[i] + this.iapChannel = channels[i] // console.log(this.userInfo.restoreFlag,'this.userInfo.restoreFlag') - if (this.userInfo.restoreFlag) { // 如果存在异常回调订单 + if(this.userInfo.restoreFlag){ // 如果存在异常回调订单 this.restoreComplateRequest() } } - } + } }) }, - // 查询未关闭订单 - restoreComplateRequest() { + // 查询未关闭订单 + restoreComplateRequest(){ let that = this console.log('检测未完成订单') - console.log(this.iapChannel, 'this.iapChannel') + console.log(this.iapChannel,'this.iapChannel') this.iapChannel.restoreComplateRequest({ manualFinishTransaction: true - }, function(results) { - if (!that.checking) { - that.checking = true - // console.log(that.checking) - // results 格式为数组存放恢复的IAP商品交易信息对象 IAPTransaction,通用需将返回的支付凭证传给后端进行二次认证 + }, function(results) { + if(!that.checking){ + that.checking = true + // console.log(that.checking) + // results 格式为数组存放恢复的IAP商品交易信息对象 IAPTransaction,通用需将返回的支付凭证传给后端进行二次认证 that.ComplateRequestArr = results - console.log(that.ComplateRequestArr, '未完成订单数组') - if (results && results.length > 0) { + console.log(that.ComplateRequestArr,'未完成订单数组') + if(results && results.length>0){ // for(var j = 0; j { - // "0"为正在支付;"1"为支付成功;"2"为支付失败;"3"为支付已恢复。 - if (item.transactionState == '1') { - // 已经支付,但是没有走逻辑的内购订单 - that.iapCheck(item, index) - } else { - // 其他状态的内购订单 - that.finishTransaction(item) - - } - }) + results.map((item,index)=>{ + // "0"为正在支付;"1"为支付成功;"2"为支付失败;"3"为支付已恢复。 + if(item.transactionState == '1'){ + // 已经支付,但是没有走逻辑的内购订单 + that.iapCheck(item,index) + }else{ + // 其他状态的内购订单 + that.finishTransaction(item) + + } + }) } - } - }); - - + } + }); + + }, // 关闭交易订单 - finishTransaction(trans, index) { + finishTransaction(trans,index){ this.iapChannel.finishTransaction(trans, (success) => { - console.log('关闭订单成功', index); - - if (index == this.ComplateRequestArr.length - 1) { // 最后一个支付订单 - this.setUserInfo({ - restoreFlag: false - }); + console.log('关闭订单成功',index); + + if(index == this.ComplateRequestArr.length-1){ // 最后一个支付订单 + this.setUserInfo({restoreFlag:false}); // console.log(this.userInfo.restoreFlag,'this.ComplateRequestArr.length+++') } - - }, (fail) => { - console.log('关闭订单失败'); - }); + + }, (fail) => { + console.log('关闭订单失败'); + }); }, - iapCheck(result, index) { - const that = this + iapCheck(result,index) { + const that = this console.log('进入后台验证') let data = { transactionId: result.transactionIdentifier, // 支付交易id - customerOid: that.userInfo.id, + customerOid: that.userInfo.id, productId: result.payment.productid, // 产品id orderId: result.payment.username, // 系统订单号 - receiptData: result.transactionReceipt, // 苹果返回收据 - loadAnimate: 'none', // 请求加载动画 - } - console.log(data, 'data') + receiptData: result.transactionReceipt ,// 苹果返回收据 + loadAnimate:'none', // 请求加载动画 + } + console.log(data,'data') $http.request({ url: "/Ipa/veri", method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档 @@ -398,54 +479,54 @@ 'Content-Type': 'application/json' }, }).then(res => { - console.log(JSON.stringify(res)) + console.log(JSON.stringify(res)) console.log(res.code) - if (res.code == 0) { + if(res.code == 0){ // uni.hideLoading() - console.log('充值订单已处理,请留意账户金额变动....') - // 服务器验证票据有效后在客户端关闭订单 - that.finishTransaction(result, index) - } else if (res.code == 200) { // 重复验证订单 + console.log('充值订单已处理,请留意账户金额变动....') + // 服务器验证票据有效后在客户端关闭订单 + that.finishTransaction(result,index) + }else if(res.code == 200){ // 重复验证订单 console.log('重复验证....') - that.finishTransaction(result, index) + that.finishTransaction(result,index) } - }).catch(e => { + }).catch(e => { console.log('支付验证失败,进入轮询程序...') - that.getIapPayResult(result, index) - }) + that.getIapPayResult(result,index) + }) console.log('--------------') }, - + // 轮询验证支付结果 - getIapPayResult(result, index) { + getIapPayResult(result,index){ // let interval = null - this.ComplateRequestInterval = setTimeout(() => { - if (this.maxTimes <= 3) { - this.iapCheck(result, index) - console.log('执行1', this.maxTimes, this.ComplateRequestInterval) - this.maxTimes += 1 - } else { + this.ComplateRequestInterval = setTimeout(() => { + if(this.maxTimes <= 3){ + this.iapCheck(result,index) + console.log('执行1', this.maxTimes,this.ComplateRequestInterval) + this.maxTimes += 1 + }else{ this.maxTimes = 0 - console.log('停止轮询', this.maxTimes, this.ComplateRequestInterval, this.maxTimes) + console.log('停止轮询', this.maxTimes,this.ComplateRequestInterval, this.maxTimes) this.checking = false - this.saveErrorIapOrder(result, index) + this.saveErrorIapOrder(result,index) clearTimeout(this.ComplateRequestInterval) - + } - }, 10000) - + },10000) + }, // 轮询失败接口 - saveErrorIapOrder(result, index) { + saveErrorIapOrder(result,index){ console.log('提交到充值问题单里面...') let data = { - transactionId: result.transactionIdentifier, + transactionId : result.transactionIdentifier, failureflag: 1, - orderId: result.payment.username, - receiptData: result.transactionReceipt, - productId: result.payment.productid, - customerOid: this.userInfo.id - } + orderId:result.payment.username, + receiptData:result.transactionReceipt, + productId:result.payment.productid, + customerOid:this.userInfo.id + } $http.request({ url: "Ipa/failure", method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档 @@ -454,50 +535,47 @@ 'Content-Type': 'application/json' }, }).then(res => { - console.log(JSON.stringify(res)) - if (res.code == 200) { + console.log(JSON.stringify(res)) + if(res.code == 200){ console.log('提交成功,关闭订单') - this.finishTransaction(result, index) + this.finishTransaction(result,index) } - }).catch(e => { - console.log(e) - if (e.statusCode == 0) { // 重复提交,直接关闭订单 - this.finishTransaction(result, index) + }).catch(e => { + console.log(e) + if(e.statusCode == 0){ // 重复提交,直接关闭订单 + this.finishTransaction(result,index) } - }) + }) }, // 获取列表数据 getData() { - this.$http - .post('book/book/bookIndex') - .then(res => { - this.xinsList = res.bookIndex.newBookList - this.limiTist = res.bookIndex.saleList - this.jingList = res.bookIndex.topBookList - }); + // this.$http + // .post('book/book/bookIndex') + // .then(res => { + // // this.xinsList = res.bookIndex.newBookList + // // this.limiTist = res.bookIndex.saleList + // // this.jingList = res.bookIndex.topBookList + // }); // 获取限时秒杀 - this.$http - .get(`book/shopseckill/getSeckillProd`) - .then(res => { - this.seckillList = res.list - // this.seckillList = null - }) + // this.$http + // .get(`book/shopseckill/getSeckillProd`) + // .then(res => { + // this.seckillList = res.list + // // this.seckillList = null + // }) - // 获取精选图书 - this.getJBook() - - this.getNewBook() - }, - // 获取精选图书 - getJBook() { + // 获取精选商品 this.$http .post('book/shopproduct/appGetList?limit=30&page=1&istop=1') .then(res => { - console.log(res.page.list, '首页商品') + console.log(res.page.list,'首页商品') this.goodsList = res.page.list }) + this.getOffSale() + this.getNewBook() }, + // 跳转 onPageJump(url) { uni.navigateTo({ @@ -527,7 +605,7 @@ // 电子书内容跳转 onBookJump(e) { uni.navigateTo({ - url: '../eBook/bookContent?Id=' + e.id + url: '../eBook/bookContent?Id=' + e.bookid }); }, // 商品详情页 @@ -536,7 +614,7 @@ url: '../bookShop/commodityDetail?id=' + id }); }, - + // 列表跳页 onShopMore(e) { uni.navigateTo({ @@ -559,62 +637,37 @@ \ No newline at end of file +