From ce389485d6dabd925c1d7f3a475915bc3359fdff Mon Sep 17 00:00:00 2001 From: "@fawn-nine" <1271023382@qq.com> Date: Fri, 22 Sep 2023 13:42:32 +0800 Subject: [PATCH 1/2] 1 --- pages/bookShop/commodityDetail.vue | 705 ++++++++++++++++++----------- pages/listen/home.vue | 59 +-- 2 files changed, 455 insertions(+), 309 deletions(-) diff --git a/pages/bookShop/commodityDetail.vue b/pages/bookShop/commodityDetail.vue index 1e3a270..504a9ea 100644 --- a/pages/bookShop/commodityDetail.vue +++ b/pages/bookShop/commodityDetail.vue @@ -14,16 +14,18 @@ - {{productInfo.activityPrice}} - 原价{{productInfo.price}} + {{productInfo.activityPrice}} + 原价{{productInfo.price}} - {{productInfo.price}} + {{productInfo.price}} {{productInfo.productName}} (无货) - 已售{{productInfo.sumSales}} + 已售{{productInfo.sumSales}} @@ -31,31 +33,30 @@ - + {{item.productName}} - ¥{{item.activityPrice}} + ¥{{item.activityPrice}} ¥{{item.price}} - + - @@ -64,47 +65,54 @@ - + 赠送听书权益 - + {{item.name}} - - + + 商品详情 - + - 书名:{{productInfo.productName}} + 书名:{{productInfo.productName}} 作者:{{productInfo.author}} - 出版社:{{productInfo.publisher}} + 出版社:{{productInfo.publisher}} - 出版时间:{{ productInfo.pubDate | formatDate }} + 出版时间:{{ productInfo.pubDate | formatDate }} - + 开本:{{productInfo.format}} 页数:{{productInfo.pageNum}} - 内文用纸材质:{{productInfo.quality}} + 内文用纸材质:{{productInfo.quality}} - - - + + + @@ -114,11 +122,12 @@ - 评价({{commentsList?commentsList.length:0}}) + 评价({{commentsList?commentsList.length:0}}) + - + @@ -128,28 +137,29 @@ - - + + - +
- - + +
{{item.createdate}} -
+
追评内容:
- + {{item.followUpdate}} - +
@@ -165,29 +175,33 @@ - + - + 查看详情 - + {{item.productName}} - ¥{{item.activityPrice}} + ¥{{item.activityPrice}} ¥{{item.price}} - + - + @@ -205,12 +219,12 @@ export default { data() { return { - linkimg:'', // 选中的关联商品图片 - playData:{}, - contentShow:0, + linkimg: '', // 选中的关联商品图片 + playData: {}, + contentShow: 0, options: [{ icon: 'cart', - text: '购物车' + text: '购物车' }], buttonGroup: [{ text: '加入购物车', @@ -236,17 +250,17 @@ productInfo: {}, productAmount: 1, // 商品数量 cartList: [], // 购物车列表 - commentsList:[], // 评论列表 - productId:null, // 商品评论 - listenList:[], // 关联得听书 - linkProducts:[], // 关联的商品, - upoShow:false, // 显示底部购买选项 - linkCur : 0, // 当前选中的关联项 + commentsList: [], // 评论列表 + productId: null, // 商品评论 + listenList: [], // 关联得听书 + linkProducts: [], // 关联的商品, + upoShow: false, // 显示底部购买选项 + linkCur: 0, // 当前选中的关联项 } }, - onLoad(e) { + onLoad(e) { this.productId = e.id - this.getProDetail(e) + this.getProDetail(e) this.getComments() this.getLinkPros(this.productId) // console.log(emojiList1,'emojiList1') @@ -258,109 +272,113 @@ musicPlay }, methods: { - gotoDetail(item){ - // console.log(item,'gotoDetail') + gotoDetail(item) { + // console.log(item,'gotoDetail') uni.navigateTo({ url: '../bookShop/commodityDetail?id=' + item.productId }); }, - closeUpo(){ + closeUpo() { console.log('关闭弹窗') this.upoShow = false }, // 点击其他套餐 - previewProduct(item,index){ - console.log(item,'item') + previewProduct(item, index) { + console.log(item, 'item') this.linkimg = item.productImages this.upoShow = true this.linkCur = index }, // 获取商品关联商品 - getLinkPros(id){ + getLinkPros(id) { this.$http - .post('book/shopproduct/getGlProductList',{ + .post('book/shopproduct/getGlProductList', { 'productId': id }) - .then(res => { + .then(res => { console.log('关联商品', res) - if(res.code == 0){ - this.linkProducts = res.result - if(this.linkProducts.length > 0){ + if (res.code == 0) { + if (res.result.length > 0) { + this.linkProducts = res.result this.linkimg = this.linkProducts[0].productImages this.linkCur = 0 - } + }else{ + this.linkProducts = [] + } } }) .catch(e => { - console.log(e,'e') + console.log(e, 'e') }) }, - goToListen(id){ + goToListen(id) { // 跳转到听书 uni.navigateTo({ - url: "../listen/listen?bookid="+ id + url: "../listen/listen?bookid=" + id }); }, // 放大图片 - previewImage(url){ + previewImage(url) { console.log(url) uni.previewImage({ urls: [url] }); }, // 获取html格式的评论1 - getHtmlComment(comment){ - // 格式化html + getHtmlComment(comment) { + // 格式化html // console.log(comment,'comment') - // 这里处理 链接 换行符 - let replacedStr = comment.replace(/\[([^(\]|\[)]*)\]/g, (item, index) => { - // console.log(item, index) - var indexss = emojiList1.findIndex(item1 => item1.alt === item) - // console.log(indexss, 'indexss') - return ''; - }); - // console.log(replacedStr,'replacedStr') - return replacedStr.replace(/(\r\n)|(\n)/g, '
'); - - + // 这里处理 链接 换行符 + let replacedStr = comment.replace(/\[([^(\]|\[)]*)\]/g, (item, index) => { + // console.log(item, index) + var indexss = emojiList1.findIndex(item1 => item1.alt === item) + // console.log(indexss, 'indexss') + return ''; + }); + // console.log(replacedStr,'replacedStr') + return replacedStr.replace(/(\r\n)|(\n)/g, '
'); + + }, // 获取评价 - getComments(){ - $http.request({ + getComments() { + $http.request({ url: "buy/record/All", method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档1 data: { - 'bookid': this.productId - }, + 'bookid': this.productId + }, header: { //默认 无 说明:请求头 'Content-Type': 'application/json' }, }) - .then(res => { - if(res.code == 0){ + .then(res => { + if (res.code == 0) { console.log(res.list, 'res.list') this.commentsList = res.list.map(item => { var imgList = [] - if(item.images !== null){ + if (item.images !== null) { imgList = item.images.split(',') item.images = imgList return item - }else { + } else { return item - } + } }) // 评论格式化 var newarr = [] - this.commentsList.forEach((item1)=>{ - var pjstr = '' - var zpstr = '' - pjstr = this.getHtmlComment(item1.content) - item1.followUpcontent == '' ? zpstr = '' : zpstr = this.getHtmlComment(item1.followUpcontent) - //console.log(pjstr,'99999999999----------') - item1.phtml = pjstr - item1.zphtml = zpstr - newarr.push(item1) - + this.commentsList.forEach((item1) => { + var pjstr = '' + var zpstr = '' + pjstr = this.getHtmlComment(item1.content) + item1.followUpcontent == '' ? zpstr = '' : zpstr = this.getHtmlComment(item1 + .followUpcontent) + //console.log(pjstr,'99999999999----------') + item1.phtml = pjstr + item1.zphtml = zpstr + newarr.push(item1) + }) this.commentsList = newarr // console.log(this.commentsList,'评价+++++') @@ -368,16 +386,16 @@ } }) }, - getProDetail(e){ + getProDetail(e) { // 获取商品详情 uni.showLoading({ title: '加载中' - }); - console.log(e.id,'e.id') + }); + console.log(e.id, 'e.id') this.$http .post('/book/shopproduct/info/' + e.id) - .then(res => { - console.log('shopproduct',res) + .then(res => { + console.log('shopproduct', res) this.productInfo = res.shopProduct this.listenList = res.shopProduct.bookidsimages if (this.productInfo.productImageList == null || this.productInfo.productImageList == '') { @@ -394,21 +412,21 @@ } uni.hideLoading(); }).catch(e => { - console.log(e,'e') - uni.hideLoading(); - if(e.msg == '该商品不存在,看看其他商品吧'){ - setTimeout(() => { - uni.navigateBack({ - delta: 1 - }); - },2000) - } - - + console.log(e, 'e') + uni.hideLoading(); + if (e.msg == '该商品不存在,看看其他商品吧') { + setTimeout(() => { + uni.navigateBack({ + delta: 1 + }); + }, 2000) + } + + }) - }, - - contentButtonClick(e){ + }, + + contentButtonClick(e) { this.contentShow = e.index }, // 点击购物车 @@ -416,13 +434,13 @@ console.log(e.content.text) uni.navigateTo({ url: '../peanut/shopping' - }); + }); }, // 关联商品点击按钮组件 - buttonClickLink(e){ + buttonClickLink(e) { console.log('点击的是关联商品的组件') - if(e.index == 0){ - // 点击的是加入购物车 + if (e.index == 0) { + // 点击的是加入购物车 if (this.linkProducts[this.linkCur].productStock == 0) { uni.showToast({ title: '商品库存不足', @@ -437,45 +455,46 @@ 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 - }); - } + } 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){ - // 点击的是加入购物车 - if(this.linkProducts.length > 0){ - this.upoShow = true - }else{ - this.addCart() - } - - }else{ - // 点击的是立即购买 - if(this.linkProducts.length > 0){ - this.upoShow = true - }else{ - this.goPurse() - } + // console.log(e) + if (e.index == 0) { + // 点击的是加入购物车 + console.log('+.........',this.linkProducts,'this.linkProducts') + if (this.linkProducts.length == 0) { + this.addCart() + } else { + this.upoShow = true + } + + } else { + // 点击的是立即购买 + if (this.linkProducts.length == 0) { + this.goPurse() + } else { + this.upoShow = true + } } }, - goToListenNone(){ + goToListenNone() { uni.showToast({ - title:'该书暂未生成音频内容,敬请期待!', - icon:'none' + title: '该书暂未生成音频内容,敬请期待!', + icon: 'none' }) }, // 加入购物车 @@ -503,7 +522,7 @@ "productId": item.productId, "productAmount": this.productAmount, "price": item.price - } + } // 判断列表是否为空 if (this.cartList.length > 0) { let flag = '' @@ -525,7 +544,7 @@ header: { //默认 无 说明:请求头 'Content-Type': 'application/json' }, - }).then(res => { + }).then(res => { if (res.code == 0) { this.upoShow = false uni.showToast({ @@ -543,7 +562,7 @@ header: { //默认 无 说明:请求头 'Content-Type': 'application/json' }, - }).then(res => { + }).then(res => { if (res.code == 0) { this.upoShow = false uni.showToast({ @@ -553,7 +572,7 @@ } }) } - + } else { // 购物车列表为空时直接加入购物车 $http.request({ @@ -580,7 +599,7 @@ "productId": this.productInfo.productId, "productAmount": this.productAmount, "price": this.productInfo.price - } + } // 判断列表是否为空 if (this.cartList.length > 0) { let flag = '' @@ -664,162 +683,303 @@ } }, -formatRichText (html) { //控制小程序中图片大小 - let newContent= html.replace(/]*>/gi,function(match,capture){ - match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); - match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); - match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); - return match; - }); - newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){ - match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;'); - return match; - }); - newContent = newContent.replace(/]*\/>/gi, ''); - newContent = newContent.replace(/\]*>/gi, function(match, capture) { + match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); + match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); + match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); + return match; + }); + newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) { + match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, + 'max-width:100%;'); + return match; + }); + newContent = newContent.replace(/]*\/>/gi, ''); + newContent = newContent.replace(/\标签 - * @param html - * @returns {void|string|*} - */ - formatRichText (html) { //控制小程序中图片大小 - let newContent= html.replace(/]*>/gi,function(match,capture){ - match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); - match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); - match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); - return match; - }); - newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){ - match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;'); - return match; - }); - newContent = newContent.replace(/]*\/>/gi, ''); - newContent = newContent.replace(/\标签 + * @param html + * @returns {void|string|*} + */ + formatRichText(html) { //控制小程序中图片大小 + let newContent = html.replace(/]*>/gi, function(match, capture) { + match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); + match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); + match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); + return match; + }); + newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) { + match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, + 'max-width:100%;'); + return match; + }); + newContent = newContent.replace(/]*\/>/gi, ''); + newContent = newContent.replace(/\ + \ No newline at end of file diff --git a/pages/listen/home.vue b/pages/listen/home.vue index ab87def..a447b0f 100644 --- a/pages/listen/home.vue +++ b/pages/listen/home.vue @@ -33,27 +33,14 @@
- - - 接口正在调试 - - + + - {{item.name}} - + {{item.name}} @@ -94,6 +81,7 @@ ygtotalPage: 1, tjPage: 1, tjTotalPage: 1, + tjPageSize:9, tjBookLIst: [], contentButtonList: [{ name: '已购图书' @@ -112,16 +100,11 @@ }, onPullDownRefresh() { console.log('下拉刷新了') + this.tjBookLIst = [] + this.getListDate() + this.bookList = [] + this.getfreeBook() uni.stopPullDownRefresh(); - if (this.contentShow == 0) { - // this.page=1, // 页码 - this.bookList = [] - this.getfreeBook() - } else if (this.contentShow == 1) { - // this.tjPage=1, // 页码 - this.tjBookLIst = [] - this.getListDate() - } }, onReachBottom() { this.loadingNow = true @@ -144,7 +127,7 @@ // } if (this.contentShow == 1) { - if (this.tjPage < this.tjTotalPage) { + if (this.tjPage+1 < this.tjTotalPage) { this.tjPage++ console.log('加载', this.tjPage) this.status = 0 @@ -233,21 +216,23 @@ .post('book/book/getUserNobuyBooks', { // 磊哥新写 // .post('book/shopproduct/booklist', { // 原接口 'userId': this.userInfo.id, - 'limit': 9, + 'limit': this.tjPageSize, 'page': this.tjPage }) - .then(res => { - console.log(res) - if (res.code == 0 && res.books.length > 0) { - console.log(res,'推荐听书列表') - this.tjBookLIst = res.books - var yu = res.count % 9 - if(yu != 0){ - this.tjTotalPage = parseInt(res.count / 9) + 1 + .then(res => { + console.log(res,'推荐听书列表') + if (res.code == 0 && res.page.records.length > 0) { + this.tjBookLIst = this.tjBookLIst.concat(res.page.records) + // 计算总页数 + var yu = res.page.total % this.tjPageSize + console.log(yu,'yu') + if(yu > 0){ + this.tjTotalPage = parseInt(res.page.total / this.tjPageSize) +1 + // console.log(this.tjTotalPage,'总页数:this.tjTotalPage') }else{ - this.tjTotalPage = parseInt(res.count / 9) + this.tjTotalPage = parseInt(res.page.total / this.tjPageSize) + // console.log(this.tjTotalPage,'总页数:this.tjTotalPage') } - console.log(this.tjTotalPage,'tjTotalPage') this.status = 3 }else{ this.tjTotalPage = 0 From 3d7e759f78e1974727860f57d1e3a7f9d492ba7c Mon Sep 17 00:00:00 2001 From: "@fawn-nine" <1271023382@qq.com> Date: Fri, 22 Sep 2023 13:48:00 +0800 Subject: [PATCH 2/2] 2 --- pages/bookShop/commodityDetail.vue | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pages/bookShop/commodityDetail.vue b/pages/bookShop/commodityDetail.vue index 504a9ea..93f7257 100644 --- a/pages/bookShop/commodityDetail.vue +++ b/pages/bookShop/commodityDetail.vue @@ -122,8 +122,7 @@ - 评价({{commentsList?commentsList.length:0}}) - + 评价({{commentsList?commentsList.length:0}}) @@ -475,7 +474,7 @@ // console.log(e) if (e.index == 0) { // 点击的是加入购物车 - console.log('+.........',this.linkProducts,'this.linkProducts') + // console.log('+.........',this.linkProducts,'this.linkProducts') if (this.linkProducts.length == 0) { this.addCart() } else {