From 47462dc6c323cc4ac7b32b93051947d351799c1f Mon Sep 17 00:00:00 2001 From: yiming <m13691596795@163.com> Date: 星期四, 21 三月 2024 18:53:20 +0800 Subject: [PATCH] 检索页修改 --- packageBookService/pages/bookServices/detail/index.js | 149 +++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 135 insertions(+), 14 deletions(-) diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js index 0bc5d6c..7addb7f 100644 --- a/packageBookService/pages/bookServices/detail/index.js +++ b/packageBookService/pages/bookServices/detail/index.js @@ -1,6 +1,7 @@ // pages/bookServices/detail/index.js import Message from 'tdesign-miniprogram/message/index.js'; import Toast from 'tdesign-miniprogram/toast'; +import tool from '../../../../assets/js/toolClass' const app = getApp(); Page({ /** @@ -49,7 +50,10 @@ useCount: 0, // 缁勪欢宸蹭娇鐢ㄦ鏁� residue: 0, // 缁勫嵎鍓╀綑娆℃暟 mockList: [] // 鐢ㄦ埛缁勫嵎鎻愪氦淇℃伅 - } + }, + flag: true, + applyResourceLoading: false, + noResources: false }, @@ -260,7 +264,6 @@ }) } } - console.log('缁勫嵎淇℃伅', this.data.mockData); this.setData({ 'bookDetail.publicationDate': this.formatDate(this.data.bookDetail.publicationDate), 'bookDetail.class': className, @@ -268,6 +271,7 @@ 'bookDetail.oldPrice': this.numFormat(this.data.bookDetail.oldPrice), 'bookDetail.paperPrice': this.numFormat(this.data.bookDetail.paperPrice), }); + console.log('鍥句功淇℃伅', this.data.bookDetail); }); }, @@ -341,7 +345,8 @@ }, onTabsChange(e) { this.setData({ - tabValue: e.detail.value + tabValue: e.detail.value, + noResources: false }) if (e.detail.label == '鏁欏璧勬簮' || e.detail.label == '浜戝涔�' || e.detail.label == '浜戞祴璇�') { const checkData = this.data.cmsDatas.find(item => item.refCode == e.detail.value) @@ -351,7 +356,10 @@ || (e.detail.value == 'questionBank' && !this.data.test.length)) { this.getResourceData(checkData) } - + } else { + this.setData({ + noResources: true + }) } } else if (e.detail.label == '浜戠瑪璁�') { const token = wx.getStorageSync('jsek-token') @@ -378,7 +386,8 @@ // 鑾峰彇鏁欏璧勬簮 浜戝涔� 浜戞祴璇� getResourceData(type) { this.setData({ - loading: true + loading: true, + noResources: false }) let query = { path: '*', @@ -405,6 +414,12 @@ app.MG.store .getProductDetail(query) .then(async (res) => { + if (!res.datas.cmsDatas[0].datas.length) { + return this.setData({ + noResources: true, + loading: false + }) + } // 浜戞祴璇曪紝閫掑綊璇锋眰閲屽眰鏁版嵁 if (type.refCode == 'questionBank') { const data = res.datas.cmsDatas[0].datas.filter( @@ -415,19 +430,20 @@ //鏁欏璧勬簮 浜戝涔� if (type.refCode == 'jsek_teachingResources' || type.refCode == 'jsek_cloudLearning') { if (res.datas.cmsDatas[0].datas.length > 0) { + res.datas.cmsDatas[0].datas.forEach(item => { + item.checked = false + }) + const list = await this.getAllResource(res.datas.cmsDatas[0].datas) if (type.refCode == 'jsek_teachingResources') { - res.datas.cmsDatas[0].datas.forEach(item => { - item.checked = false - }) - const list = await this.getAllResource(res.datas.cmsDatas[0].datas) - - console.log(list, 'list'); this.setData({ teach: list, loading: false }) this.findChildIds(this.data.teach, this.data.openTeachids = []) } else if (type.refCode == 'jsek_cloudLearning') { + res.datas.cmsDatas[0].datas.forEach(item => { + item.checked = false + }) const list = await this.getAllResource(res.datas.cmsDatas[0].datas) this.setData({ learn: list, @@ -513,6 +529,7 @@ if (this.data.tabValue == 'jsek_teachingResources') { item.checked = false } else if (this.data.tabValue == 'jsek_cloudLearning') { + item.checked = false item.isbuy = this.resourceIsBuy(item) item.isShopCar = this.isShoppingCart(item) } @@ -550,6 +567,17 @@ // 鍥句功娣诲姞璐墿杞� async addBookShopcCar() { + + const token = wx.getStorageSync('jsek-token') + if (!token) { + return wx.getUserProfile({ + desc: '鐢ㄦ埛鐧诲綍', + success: (res) => { + console.log(res); + } + }) + } + const shoppingCartGetId = [] let query = { @@ -701,10 +729,15 @@ }) } }) - console.log('鏈夋晥鏃ユ湡', this.data.deadline); + this.setData({ + applyResourceLoading: false + }) }, // 鐢宠鏁欏璧勬簮 applyResource() { + this.setData({ + applyResourceLoading: true + }) // let role = userStore.userInfo ? userStore.userInfo.role : null // if (role) { // if (role == 'Teacher') { @@ -727,7 +760,9 @@ } app.MG.ugc.newTopicMessage(query).then((res) => { if (res) { - Message.success('鐢宠宸叉彁浜わ紝璇峰緟瀹℃牳閫氳繃鍚庝笅杞�') + wx.showToast({ + title: '鐢宠宸叉彁浜わ紝璇峰緟瀹℃牳閫氳繃鍚庝笅杞�', + }) } this.getApplyInfo(this.data.bookDetail.id) }) @@ -1115,6 +1150,92 @@ }) } }) - } + }, + // 璐拱缁勫嵎 + async buyMock() { + let res + if (!this.data.mockData.id) return wx.showToast({ + icon: "error", + title: '鏆傛棤缁勫嵎', + mask: true + }) + // 鏋勫缓璁㈠崟鏌ヨ瀵硅薄 + try { + let query = { + remarks: '缁勫嵎', + requests: [ + { + saleMethodId: this.data.mockData.id, + count: 1 + } + ] + } + if (this.data.flag) { + this.setData({ + flag: false + }) + res = await app.MG.store.initOrder(query) + } + if (res.orderNumber && this.data.mockData.price) { + wx.navigateTo({ + url: `/pages/cart/paymentPage/index?orderNumber=${res.orderNumber}`, + }) + } else { + // 0鍏冪洿鎺ラ鍙� + // 纭璁㈠崟 + const confirmOrderRes = await app.MG.store.confirmOrder({ orderNum: res.orderNumber }) + if (confirmOrderRes) { + wx.showToast({ + icon: "success", + title: '棰嗗彇鎴愬姛', + }) + this.setData({ + flag: true + }) + await this.recordBuyMock() // 璁板綍璐拱鏃堕棿 + } + } + } catch (error) { + console.log(error) + } + }, + // 璁板綍璐拱缁勫嵎鏃堕棿 + recordBuyMock() { + const num = this.data.mockData.mockList.length + const id = tool.uuid(8) + const createDate = new Date().getTime() + const mockList = this.data.mockData.mockList + mockList.push({ id, createDate, name: `绗�${num + 1}濂楄瘯鍗穈, state: '0' }) + this.setData({ + 'mockData.mockList': mockList + }) + // 璁板綍璐拱鏃堕棿锛屽苟璁剧姸鎬乻tate涓�1锛岃〃绀哄垰璐拱瀹屾垚缁勫嵎 + app.MG.identity.setUserKey({ + setKeyRequests: [ + { + domain: 'mockData', + key: this.data.bookDetail.id + '', + value: JSON.stringify(this.data.mockData.mockList) + } + ] + }) + }, + // 搴曢儴璐拱鎸夐挳 + buyBtn() { + if (this.data.tabValue == 'brief') { + this.buyBook() + } + else if (this.data.tabValue == 'jsek_cloudLearning') { + const tree = this.selectComponent('#tree') + + tree.onCloudShoppingCart() + + + } else if (this.data.tabValue == 'questionBank') { + this.buyMock() + } else { + console.log(this.data.tabValue); + } + }, }) -- Gitblit v1.9.1