From 04c7b0163caeae4ab1c5da62e301fa993101cfad Mon Sep 17 00:00:00 2001 From: 闫增涛 <1829501689@qq.com> Date: 星期一, 31 三月 2025 10:40:45 +0800 Subject: [PATCH] bug修改 --- packageBookService/pages/bookServices/detail/index.js | 1537 ++++++++++++++++++++++++++++++++++------------------------ 1 files changed, 894 insertions(+), 643 deletions(-) diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js index 8e0ddd0..4a1ea38 100644 --- a/packageBookService/pages/bookServices/detail/index.js +++ b/packageBookService/pages/bookServices/detail/index.js @@ -1,19 +1,18 @@ // pages/bookServices/detail/index.js import Toast from "tdesign-miniprogram/toast"; import tool from "../../../../assets/js/toolClass"; +import moment from 'moment' import { loginInfo } from "../../../../assets/js/login"; import FormData from '../../../../utils/formdata/index.js'; const app = getApp(); +var pastData = require('../../psychologyAnswer/testdata/index') Page({ /** * 椤甸潰鐨勫垵濮嬫暟鎹� */ data: { - // 杩涢〉闈㈤粯璁ゅ垏鎹� 灞曞紑鐨刬d - // defaultactiveTeachid 鏁欏璧勬簮 - // defaultactiveLearnid 浜戝涔� bookId: "", barHeight: "", navBarHeight: "", @@ -47,9 +46,14 @@ learnPath: '', applyResourceState: false, // 鐢宠鏁欏璧勬簮鎸夐挳闃叉姈 resourceClassList: [], // 璧勬簮鎵�灞炲垎绫� - applyState: "", // 鏁欏璧勬簮鐢宠鐘舵�� + applyState: "1", // 鏁欏璧勬簮鐢宠鐘舵�� deadline: "", // 鏁欏璧勬簮鐢宠鏈夋晥鏃ユ湡, + isShowBuyCloundBtn: false, isshowDrawBtn: true, // 浜戝涔犻鍙栨煡鐪嬫寜閽槸鍚︽樉绀� + isShowBuyCloundMenu: false, // 浜戝涔犲叏閮ㄨ喘涔版寜閽槸鍚︽樉绀� + isCloundHaveSaleMethod: false, // 浜戝涔犳槸鍚︽湁閿�鍞柟寮� + cloundMenuIsBuy: false, + learnTaskData: {}, rejectCause: "", // 涓嬭浇鎷掔粷鍘熷洜 buyIdList: [], shoppingCartGetId: [], // 宸茶喘涔癷d鍒楄〃 @@ -68,6 +72,9 @@ residue: 0, // 缁勫嵎鍓╀綑娆℃暟 mockList: [], // 鐢ㄦ埛缁勫嵎鎻愪氦淇℃伅 }, + isBuyBank: false, // 棰樺簱鏄惁璐拱 + isShoppingBank: false, // 棰樺簱鏄惁鍔犲叆璐墿杞� + bankSaleData: null, relatedBookLoading: false, noRelatedBookData: false, relatedBookPath: "", // 鐩稿叧鍥句功path @@ -168,10 +175,44 @@ description: '', agree: false }, + resourceVisible: false, + resourceValue: [], + fileTypeList: [{ + label: '闊抽', + value: '闊抽' + }, + { + label: '瑙嗛', + value: '瑙嗛' + }, + { + label: '鍥剧墖', + value: '鍥剧墖' + }, + { + label: 'PDF', + value: 'PDF' + }, + { + label: '璧勬簮鍖�', + value: '璧勬簮鍖�' + }, + { + label: '鏂囨。', + value: '鏂囨。' + }, + { + label: '鍏朵粬', + value: '鍏朵粬' + } + ], fileList: [], isShowUp: true, protocolShow: false, - protocolTxt: '' + protocolTxt: '', + learnMenu: null, + md5List: [], + editDialog: false }, resetTree: function (e) { @@ -179,6 +220,26 @@ currentCheck: e.detail.checkedItem, list: e.detail.changeList, }); + }, + + logInFun(callback) { + loginInfo(app, (data) => { + if (data) { + this.getShoppingCartProductGet(); + this.getApplyInfo(this.data.options.id); + this.getAlreadyPBookList(); + this.getAlreadyEBookList(); + if (wx.getStorageSync(app.config.userInfoKey)) { + this.setData({ + userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey)), + }); + // 鑾峰彇鐢宠娆℃暟 + this.getSelectPaperBookCount(); + this.getSelectBookCount(); + } + callback() + } + }) }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 @@ -192,45 +253,42 @@ bookId: options.id + "", barHeight: systInfo.statusBarHeight, navBarHeight: navBarHeight, - }); - this.setData({ options: { id: options.id, - name: options.name, + name: decodeURI(options.name), storeInfo: options.storeInfo, }, }); wx.setNavigationBarTitle({ - title: options.name, + title: decodeURI(options.name), }) this.getBookInfo(options.id); - // this.getResourceClass(); // 鑾峰彇璧勬簮鎵�灞炲垎绫� + if (options.tabValue) { + this.setData({ + tabValue: options.tabValue, + }); + } const token = wx.getStorageSync(app.config.tokenKey); if (token) { this.getShoppingCartProductGet(); - this.getApplyInfo(options.id); + this.getApplyInfo(this.data.options.id); this.getAlreadyPBookList(); this.getAlreadyEBookList(); - } - if (wx.getStorageSync(app.config.userInfoKey)) { - this.setData({ - userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey)), - }); - // 鑾峰彇鐢宠娆℃暟 - this.getSelectPaperBookCount(); - this.getSelectBookCount(); + if (wx.getStorageSync(app.config.userInfoKey)) { + this.setData({ + userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey)), + }); + // 鑾峰彇鐢宠娆℃暟 + this.getSelectPaperBookCount(); + this.getSelectBookCount(); + } } }, /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 - */ - onReady() {}, - - /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ - onShow() { + onShow(options) { if (wx.getStorageSync("paperBookList")) { this.setData({ paperBookList: JSON.parse(wx.getStorageSync("paperBookList")), @@ -243,23 +301,12 @@ } this.setData({ num: Number(this.data.paperBookList.length) + Number(this.data.electronicBookList.length), + editDialog: false }); + if (this.data.bookDetail.id) { + this.getBookInfo(this.data.bookDetail.id) + } }, - - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌 - */ - onHide() {}, - - /** - * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇 - */ - onUnload() {}, - - /** - * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 - */ - onPullDownRefresh() {}, /** * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� @@ -271,10 +318,6 @@ } }, - /** - * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� - */ - onShareAppMessage() {}, // 鏍煎紡鍖栨棩鏈� formatDate(dateString) { if (!dateString) { @@ -400,10 +443,14 @@ protectedEpub: [], probationPage: [], //pdf璇曡椤垫暟 freeEpubPage: [], //epub璇曡鐧惧垎姣� + bookEditor: [], //鍥句功缂栬緫 + contactInformation: [], //鑱旂郴鏂瑰紡 }, }; app.MG.store.getProductDetail(query).then(async (res) => { this.getResourceCode(id, res.datas.rootCmsItemId) + res.datas.bookEditor = res.datas.bookEditor ? res.datas.bookEditor : '-' + res.datas.contactInformation = res.datas.contactInformation ? res.datas.contactInformation : '-' this.setData({ bookDetail: res.datas, buyIdList: res.datas.purchasedSaleMethodIdList, @@ -438,6 +485,26 @@ await this.getBookClass(classData); } } + // 鎵爜浠庨搴撹烦杞洖鍥句功璇︽儏 + const localData = wx.getStorageSync('tabValue') + if (localData) { + this.setData({ + tabValue: localData + }) + wx.removeStorage({ + key: 'tabValue', + }) + } + if (this.data.tabValue == 'questionBank' || this.data.tabValue == 'jsek_cloudLearning' || this.data.tabValue == 'jsek_teachingResources') { + const checkData = this.data.cmsDatas.find( + (item) => item.refCode == this.data.tabValue + ); + if (this.data.tabValue == "questionBank") { + this.getResourceData(checkData) + } else { + this.getResourceDataList(checkData) + } + } // 鑾峰彇缁勫嵎閿�鍞甶d if (res.datas.saleMethod && res.datas.saleMethod.length) { @@ -465,15 +532,12 @@ } } this.setData({ - "bookDetail.publicationDate": this.formatDate( - this.data.bookDetail.publicationDate - ), + "bookDetail.publicationDate": this.data.bookDetail.publicationDate ? moment(this.data.bookDetail.publicationDate).format("YYYY骞碝M鏈�") : '', "bookDetail.price": this.numFormat(this.data.bookDetail.price), "bookDetail.oldPrice": this.numFormat(this.data.bookDetail.oldPrice), "bookDetail.paperPrice": this.numFormat( this.data.bookDetail.paperPrice ), - }); }); }, @@ -492,10 +556,30 @@ } } app.MG.store.getProductDetail(query).then((res) => { + let isBuyBank = true + let isShoppingBank = true + let bankSaleData = null + // 鍒ゆ柇棰樺簱鏄惁鏁翠綋璐拱 + const bank = res.datas.cmsDatas[0].datas.find((item) => item.refCode == 'questionBank') + if (bank) { + if (bank.saleMethod.length) { + bankSaleData = bank.saleMethod.find((item) => item.SaleType == 'Normal') + if (bankSaleData) { + isBuyBank = this.data.buyIdList.includes(bankSaleData.Id) + isShoppingBank = this.data.buyIdList.includes(bankSaleData.Id) ? true : this.data.shoppingCartGetId.includes(bankSaleData.Id) + } + } + } this.setData({ - resourceCodeList: res.datas.cmsDatas[0].datas + resourceCodeList: res.datas.cmsDatas[0].datas, + learnTaskData: res.datas.cmsDatas[0].datas.filter((item) => item.refCode == 'jsek_learningTasks')[0], + isBuyBank, + isShoppingBank, + bankSaleData }) - // console.log('鍥句功璧勬簮', res.datas.cmsDatas[0].datas) + if (res.datas.cmsDatas[0].datas.length) this.setData({ + learnMenu: res.datas.cmsDatas[0].datas.find(item => item.refCode == 'jsek_cloudLearning') + }) }) }, //璇锋眰瀛愬晢鍝佺殑鏂囦欢 @@ -651,51 +735,64 @@ setCollect() { const token = wx.getStorageSync(app.config.tokenKey); if (!token) { - // 妫�鏌ョ櫥褰曠姸鎬� - loginInfo(app, (data) => { - // 濡傛灉涓嶆槸绗竴娆$櫥褰曪紝浼氭墽琛屽洖璋� - if (data) { - // 鐧诲綍鎴愬姛锛岃嚜鍔ㄨ褰晅oken鍜岀敤鎴蜂俊鎭紝骞惰繑鍥瀟rue - this.getBookInfo(this.data.bookId); - } else { - // 鍑虹幇閿欒锛岃繑鍥瀎alse - } - }); + this.logInFun(() => { + this.getBookInfo(this.data.bookId); + }) } else { - if (this.data.bookDetail.isFavourite) { - app.MG.store - .delProductLink({ - productIds: [this.data.bookDetail.id], - linkType: "FavoriteBookCity", - }) - .then(() => { - this.setData({ - "bookDetail.isFavourite": false, - }); - }); - } else { - const params = { + this.collectFun() + } + }, + collectFun() { + if (this.data.bookDetail.isFavourite) { + app.MG.store + .delProductLink({ productIds: [this.data.bookDetail.id], linkType: "FavoriteBookCity", - }; - app.MG.store.addProductLink(params).then((res) => { + }) + .then(() => { this.setData({ - "bookDetail.isFavourite": true, + "bookDetail.isFavourite": false, }); }); - } + } else { + const params = { + productIds: [this.data.bookDetail.id], + linkType: "FavoriteBookCity", + }; + app.MG.store.addProductLink(params).then((res) => { + this.setData({ + "bookDetail.isFavourite": true, + }); + }); } + }, + // 鑱旂郴 + editPhone() { + this.setData({ + editDialog: true + }) + }, + closeEditDialog() { + this.setData({ + editDialog: false + }) }, // 鎴戣寤鸿 suggestBtn() { // 妫�鏌ョ櫥褰曠姸鎬� const token = wx.getStorageSync(app.config.tokenKey); - const child = this.selectComponent("#suggest-component"); - if (token) - // child.showDialog(); + if (token) { this.setData({ showIndex: '1' }) + } else { + this.logInFun(() => { + this.setData({ + showIndex: '1' + }) + }) + } + }, // 璺宠浆缃戝簵 goShop(e) { @@ -703,7 +800,7 @@ link } = e.currentTarget.dataset; wx.navigateTo({ - url: `/packageBookService/pages/bookServices/webpage/index?url=${link}`, + url: `/packageBookService/pages/bookServices/linkPage/index?path=${link}`, }); }, // tag鍒囨崲 @@ -719,7 +816,7 @@ e.detail.label == "浜戞祴璇�" ) { const checkData = this.data.cmsDatas.find( - (item) => item.refCode == e.detail.value + (item) => item.refCode == this.data.tabValue ); if (!this.data.resourceClassList.length) this.getResourceClass() if (checkData) { @@ -729,17 +826,6 @@ "buyResourceData.refCode": checkData.refCode, }); } - // if ( - // (e.detail.value == "jsek_teachingResources" && - // !this.data.teach.length) || - // (e.detail.value == "jsek_cloudLearning" && !this.data.learn.length) || - // (e.detail.value == "questionBank" && !this.data.test.length) - // ) { - // if (e.detail.value == "jsek_teachingResources") { - // wx.setStorageSync('teachResourcesPath', checkData.productLinkPath) - // } - // this.getResourceData(checkData); - // } if ((e.detail.value == "jsek_teachingResources" && !this.data.teach.length) || (e.detail.value == "jsek_cloudLearning" && !this.data.learn.length)) { wx.setStorageSync('teachResourcesPath', checkData.productLinkPath) this.getResourceDataList(checkData) @@ -822,10 +908,9 @@ }, // 鎵佸钩鍖栨暟鎹浆鎹ree - getTreeList(rootList, pathLength, newArr, path) { + getTreeList(rootList, newArr, path) { for (const item of rootList) { - // 姝ゅ鍘熸湰 item.productLinkPath.length == pathLength 浣� productLinkPath 闀垮害涓埆涔﹀瓨鍦�4銆�5浣嶄氦閿� - if ((pathLength - item.productLinkPath.length >= 0 && pathLength - item.productLinkPath.length <= 3) && item.productLinkPath.includes(path)) { + if (path == item.productLinkPath.replace('\\' + item.id, '')) { if (item.sysType == 'CmsItem') { if (item.selectType == 'webpage') { item.disabled = true @@ -840,17 +925,15 @@ } // newArr.push(item) // 鍦ㄦ彃鍏ヨ繃绋嬩腑瀵规暟鎹繘琛屾帓搴� - newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item) + newArr = this.insertAndSortObjectsById(newArr, item) // 鎻掕繘鏁扮粍鍚� 浠庡師鏁版嵁涓垹闄� rootList = rootList.filter(nitem => nitem.id != item.id) } } //缁欐暟缁勯噷闈㈠啀娣诲姞涓�涓猚hildren鐨勭┖鏁扮粍 - // let addnum1 = pathLength - path.length == 6 ? 6 : 7 for (const i of newArr) { i.children = [] - let addnum1 = i.productLinkPath.length - path.length == 6 ? 6 : 7 - this.getTreeList(rootList, pathLength + addnum1, i.children, i.productLinkPath) + this.getTreeList(rootList, i.children, i.productLinkPath) if (i.children.length == 0) { delete i.children } @@ -874,31 +957,44 @@ return tree }, - // 鎺掑簭鏁扮粍 鎸夌収productLinkPath - insertAndSortObjectsByProductLinkPath(array, newObj) { + // 鎺掑簭鏁扮粍 鎸夌収id + insertAndSortObjectsById(array, newObj) { // 鏌ユ壘鏂板璞″簲璇ユ彃鍏ョ殑浣嶇疆 - let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.lastIndexOf('\\') + 1, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.lastIndexOf('\\') + 1, obj.productLinkPath.length))); + let insertIndex = array.findIndex(obj => newObj.id < obj.id); // 濡傛灉娌℃湁鎵惧埌鍚堥�傜殑浣嶇疆锛屽垯鏀惧湪鏁扮粍鏈熬 if (insertIndex === -1) { insertIndex = array.length; } // 鎻掑叆鏂板璞″埌鏁扮粍 array.splice(insertIndex, 0, newObj); - // 娴嬭瘯6 姝e紡5 // 瀵规暟缁勮繘琛屾帓搴� array.sort((a, b) => { - if (Number(a.productLinkPath.substring(a.productLinkPath.lastIndexOf('\\') + 1, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.lastIndexOf('\\') + 1, b.productLinkPath.length))) { - return -1; - } - if (Number(a.productLinkPath.substring(a.productLinkPath.lastIndexOf('\\') + 1, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.lastIndexOf('\\') + 1, b.productLinkPath.length))) { - return 1; - } - // a must be equal to b + if (a.id < b.id) return -1; + if (a.id > b.id) return 1; return 0; }); - // 杩斿洖鏇存柊鍚庣殑鏁扮粍 return array; + }, + // 閫掑綊鏍戠粨鏋勶紝濡傛灉鐖剁骇鏈夐攢鍞柟寮�(鏈夋晥鏈�)锛屽幓鎺夋墍鏈夊瓙闆嗙殑閿�鍞柟寮� + clearTreeSealmethod(clearSaleMethod, tree) { + for (let item of tree) { + const saleData = item.saleMethod && + item.saleMethod.length ? + item.saleMethod.find((citem) => citem.SaleType == 'Normal') : null + if ( + ((saleData && new Date(saleData.EndDate).getTime() >= new Date().getTime() && new Date(saleData.BeginDate).getTime() <= new Date().getTime()) || + clearSaleMethod) && item.children && item.children.length + ) { + item.children.forEach((ditem) => (ditem.saleMethod = [])) + } + if (item.children && item.children.length) + this.clearTreeSealmethod( + saleData && new Date(saleData.EndDate).getTime() >= new Date().getTime() && new Date(saleData.BeginDate).getTime() <= new Date().getTime(), + item.children + ) + } + return tree }, // 鏁欏璧勬簮 浜戝涔� 鑾峰彇 getResourceDataList(type) { @@ -909,7 +1005,6 @@ let query = { path: '*', queryType: '*', - storeInfo: this.data.options.storeInfo, productId: this.data.bookDetail.id, cmsPath: type.productLinkPath, cmsType: '*', @@ -922,10 +1017,9 @@ file: [], protectedFile: [], resourcesClassification: [], - isDownload: [], + // isDownload: [], jsek_resourceBrief: [], jsek_link: [], - jsek_questionBank: [] }, pading: { start: 0, @@ -933,96 +1027,104 @@ }, } app.MG.store.getProductDetailNoChildren(query).then((res) => { - if (!res.datas.cmsDatas[0].datas.length) { + if (!res.datas.cmsDatas[0].datas.length || res.datas.cmsDatas[0].datas.length == 0) { return this.setData({ noResources: true, loading: false, }); } let list = [] - // 娴嬭瘯 6浣�// 姝e紡 5浣�// 娴嬭瘯璋冪敤浼�20锛屽唴閮�7 姝e紡璋冪敤浼�17 鍐呴儴浼�6 - //鏁欏璧勬簮 浜戝涔� - if ( - type.refCode == "jsek_teachingResources" || - type.refCode == "jsek_cloudLearning" - ) { - res.datas.cmsDatas[0].datas.forEach((item) => { - item.checked = false; - if (item.sysType == 'CmsItem') { - // 鏁欏璧勬簮 绫诲瀷鍚嶇О璧嬪�� - this.data.resourceClassList.forEach((type) => { - if (type.value == item.resourcesClassification) - item.resourceClass = type.name; - }); - if (this.data.tabValue == "jsek_teachingResources") {} else if (this.data.tabValue == "jsek_cloudLearning") { - item.isbuy = this.isShowNeedBuy(item); - item.isShopCar = this.isShoppingCart(item); - } + // 鍒ゆ柇浜戝涔犳湁鏃犻攢鍞柟寮忓拰鏈夋晥鏈� + const cloundSaleMethod = + type.saleMethod && type.saleMethod.length ? + type.saleMethod.find((citem) => citem.SaleType == 'Normal') : + null + let flags = + type.refCode == 'jsek_cloudLearning' && + cloundSaleMethod && + new Date().getTime() <= new Date(cloundSaleMethod.EndDate).getTime() && + new Date().getTime() >= new Date(cloundSaleMethod.BeginDate).getTime() + let md5s = [] + res.datas.cmsDatas[0].datas.forEach((item) => { + // 浜戝涔犱笂鏈夐攢鍞柟寮忥紝鍘绘帀浜戝涔犱笅鎵�鏈夐攢鍞柟寮� + if (this.data.tabValue == "jsek_teachingResources") { + if (item.file || item.freeFile) { + let md5 = item.file ? item.file : item.freeFile + md5s.push(md5) } - }); - if (type.refCode == "jsek_cloudLearning") { this.setData({ - learnPath: type.productLinkPath - }) - const dataList = res.datas.cmsDatas[0].datas - // 鍏堝垽鏂槸鍚﹀惁涔颁簯瀛︿範鏁翠釜鐩綍 - let couldId = null - let codeData = null - if (this.data.resourceCodeList.length) { - codeData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning') - if (codeData && codeData.saleMethod && codeData.saleMethod.length) - couldId = codeData.saleMethod[0].Id - } - if (couldId) { - this.setData({ - isGoBuyResource: this.data.buyIdList.indexOf(couldId) > -1 ? false : true - }) - } else if (dataList.length) { - const tag = dataList.findIndex(item => item.saleMethod.length && item.saleMethod[0].Price > 0) - this.setData({ - isGoBuyResource: tag > -1 ? true : false - }) - } else { - this.setData({ - isGoBuyResource: false - }) - } - } - const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 13 ? 8 : 6 - const num = query.cmsPath.length + addNum - this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\') - list = this.ensureTreeConsistency(list) - list = this.changeResourceChildren(list) - let result = []; - if (type.refCode == "jsek_teachingResources") { - this.findChildIds(list, result); - // const newUSeList = this.deleteTreeData(list, result) - // console.log('鏍戝墧闄�', result, newUSeList); - // console.log('鏍戝姞涓�', this.increaseTreeData(list, newUSeList, 16094)); - this.setData({ - openTeachids: result, - loading: false, - teach: list, - }); - } else if (type.refCode == "jsek_cloudLearning") { - let arr = this.handleTreeData(list).filter( - (item) => item.saleMethod[0] - ); - let freeIds = arr.filter((item) => { - return item.saleMethod[0].Price == 0; - }); - if (!freeIds.length) - this.setData({ - isshowDrawBtn: false, - }); - this.findChildIds(list, result); - this.setData({ - learn: list, - loading: false, - openLearnids: result, + md5List: md5s, }); } + if (flags && cloundSaleMethod.Price > 0) item.saleMethod = [] + item.checked = false; + if (item.sysType == 'CmsItem') { + // 鏁欏璧勬簮 绫诲瀷鍚嶇О璧嬪�� + this.data.resourceClassList.forEach((type) => { + if (type.value == item.resourcesClassification) + item.resourceClass = type.name; + }); + // if (this.data.tabValue == "jsek_teachingResources") {} else if (this.data.tabValue == "jsek_cloudLearning") { + // item.isbuy = this.isShowNeedBuy(item); + // item.isShopCar = this.isShoppingCart(item); + // } + } + }); + // 鍒ゆ柇澶勭悊璧勬簮 + if (res.datas.cmsDatas[0].datas.some((item) => item.sysType == 'CmsFolder')) { + if (!res.datas.cmsDatas[0].datas.some((item) => item.sysType == 'CmsItem')) { + // 1.鍙湁鐩綍锛屾病鏈夎祫婧� + list = res.datas.cmsDatas[0].datas + } else { + this.getTreeList(res.datas.cmsDatas[0].datas, list, query.cmsPath) + list = this.ensureTreeConsistency(list) + list = this.changeResourceChildren(list) + } + } else { + // 3.鍙湁璧勬簮锛屾病鏈夌洰褰� + list = res.datas.cmsDatas[0].datas } + let result = []; + if (type.refCode == "jsek_teachingResources") { + this.findChildIds(list, result); + this.setData({ + openTeachids: result, + loading: false, + teach: list, + }); + } else if (type.refCode == "jsek_cloudLearning") { + // 浜戝涔犱笂鏃犻攢鍞柟寮忥紝璧扮洰褰� 璧勬簮 閿�鍞柟寮忓幓闄ゆ柟娉� + if (!flags) list = this.clearTreeSealmethod(false, list) + // 鍒ゆ柇棰嗗彇鏌ョ湅鏄惁鏄剧ず(浜戝涔狅紝鎴栬祫婧愮洰褰曪紝鏈夊敭浠蜂负0) + let isshowDrawBtn = res.datas.cmsDatas[0].datas.some( + (item) => + item.saleMethod.length && + item.saleMethod.find((citem) => citem.SaleType == 'Normal').Price == 0 && + new Date(item.saleMethod.find((citem) => citem.SaleType == 'Normal').EndDate).getTime() >= new Date().getTime() && + new Date(item.saleMethod.find((citem) => citem.SaleType == 'Normal').BeginDate).getTime() <= new Date().getTime() + ) || (flags && cloundSaleMethod.Price == 0) + // 鍒ゆ柇浜戝涔犲叏閮ㄨ喘涔版寜閽槸鍚︽樉绀� + let isShowBuyCloundMenu = flags && cloundSaleMethod.Price > 0 && !this.data.buyIdList.includes(cloundSaleMethod.Id) + // 鍒ゆ柇璧勬簮璐拱鎸夐挳鏄惁鏄剧ず + let isShowBuyCloundBtn = !flags && res.datas.cmsDatas[0].datas.some(citem => citem.saleMethod.length != 0) + // 鍒ゆ柇璐墿杞︽寜閽拰閿佹寜閽槸鍚︽樉绀� + this.handleTreeData(list).forEach(item => { + item.isbuy = this.resourceIsBuy(item); + item.isShopCar = this.isShoppingCart(item); + }) + this.findChildIds(list, result); + this.setData({ + isshowDrawBtn, + isShowBuyCloundMenu, + isShowBuyCloundBtn, + isCloundHaveSaleMethod: flags && cloundSaleMethod.Price > 0, + learn: list, + loading: false, + openLearnids: result, + learnPath: type.productLinkPath + }); + } + console.log('1', this.data.teach); }) }, // 鑾峰彇 浜戞祴璇� @@ -1088,23 +1190,24 @@ } } else { if (isTSFW.length > 0) { - data = res.datas.cmsDatas[0].datas.filter((item) => item.type == 'questionBankFolder' && item.childrenFolderCount > 0) + data = res.datas.cmsDatas[0].datas.filter((item) => item.type == 'questionBankFolder' && item.refCode != 'jsek_interaction' && (item.childrenFolderCount > 0 || item.childrenCount > 0) && (item.name !== '濉┖棰�' && + item.name !== '鍒ゆ柇棰�' && + item.name !== '澶氶�夐' && + item.name !== '绠�绛旈') && item.name !== '鍗曢�夐') that.setData({ jslx: false, }); } else { data = res.datas.cmsDatas[0].datas.filter((item) => item.type == 'questionBankFolder') + // && item.refCode != 'jsek_interaction' that.setData({ jslx: true, }); } if (data.length > 0) { + console.log('data', data); let list = [] - // 娴嬭瘯 6浣�// 姝e紡 5浣�// 娴嬭瘯璋冪敤浼�20锛屽唴閮�7 姝e紡璋冪敤浼�17 鍐呴儴浼�6 - - const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 13 ? 8 : 6 - const num = query.cmsPath.length + addNum - that.getTreeList(data, num, list, '\\') + that.getTreeList(data, list, query.cmsPath) list = that.ensureTreeConsistency(list) that.findChildIds(list[0].children, result); that.setData({ @@ -1112,6 +1215,20 @@ loading: false, openTeachids: result, }); + //Json璧嬪�� + // const bookId = that.data.bookId + // if (bookId == 6619) { + // const jsonData = {} + // jsonData.name = "蹇冪悊娴嬭瘎" + // jsonData.children = [...pastData.postData.list] + // var test = that.data.test; + // test.push(jsonData); + // that.setData({ + // test: test, + // }); + // console.log(that.data.test, "鏁欏浜掑姩"); + // } + } else { that.setData({ noResources: true, @@ -1125,91 +1242,7 @@ console.log(e); }); }, - // 鑾峰彇tag涓嬫墍鏈夎祫婧� - async getAllResource(data) { - if (!data.length) return false; - for (let i = 0; i < data.length; i++) { - let item = data[i]; - if (item.sysType == "CmsFolder" && item.childrenCount > 0) { - item.children = []; - item.children = await this.getFolderItem(item.productLinkPath); - await this.getAllResource(item.children); - } - } - return data; - }, - // 鑾峰彇璧勬簮鎺ュ彛 - async getFolderItem(path) { - let query = { - path: "*", - queryType: "*", - storeInfo: this.data.options.storeInfo, - productId: this.data.bookDetail.id, - cmsPath: path, - itemFields: { - SysType: "CmsFolder", - // 璧勬簮绫诲瀷锛岃瘯璇绘枃浠讹紝鏄惁鍏佽涓嬭浇绛夊弬鏁� - selectType: [], - freeFile: [], - file: [], - protectedFile: [], - resourcesClassification: [], - isDownload: [], - jsek_resourceBrief: [], - jsek_link: [], - accessType: [], - learnSelectType: [], - }, - pading: { - start: 0, - size: 999, - }, - }; - let data = await app.MG.store.getProductDetail(query); - // 濡傛灉item灞傜骇閲屾湁floder锛屽垹闄loder - const flag = data.datas.cmsDatas[0].datas.findIndex( - (item) => item.sysType == "CmsItem" - ); - if (flag > -1) - data.datas.cmsDatas[0].datas = data.datas.cmsDatas[0].datas.filter( - (item) => item.sysType == "CmsItem" - ); - data.datas.cmsDatas[0].datas.forEach((item) => { - // if (item.sysType == "CmsFolder" && flag > -1) { - // item.isShow = false; - // } else { - // item.isShow = true; - // } - this.data.resourceClassList.forEach((type) => { - if (type.value == item.resourcesClassification) - item.resourceClass = type.name; - }); - // 缃戦〉 涓嶈兘涓嬭浇 绉佹湁鏂囦欢 - if (item.sysType == "CmsItem") { - if (item.selectType == "webpage") { - item.disabled = true; - } else { - if (item.isDownload != 1) { - item.disabled = true; - } - } - if (item.file && item.fileMap && item.fileMap[item.file]) { - if (item.fileMap[item.file].protectType == "Private") - item.disabled = true; - } - } - }); - data.datas.cmsDatas[0].datas.forEach((item) => { - if (this.data.tabValue == "jsek_teachingResources") { - item.checked = false; - } else if (this.data.tabValue == "jsek_cloudLearning") { - item.checked = false; - item.isbuy = this.isShowNeedBuy(item); - item.isShopCar = this.isShoppingCart(item); - } - }); - return data.datas.cmsDatas[0].datas; - }, + // 鑾峰彇灞曞紑椤� findChildIds(data, result) { let index = 0 @@ -1243,48 +1276,57 @@ }, // 鍥句功娣诲姞璐墿杞� - async addBookShopcCar() { - if (!this.data.expire) { - const shoppingCartGetId = []; - let query = { - start: 0, - size: 9999, - filterList: [], - searchList: [], - }; - const res = await app.MG.store.getShoppingCartProductList(query); - res.datas.forEach((item) => { - shoppingCartGetId.push(item.saleMethod.id); - }); - const determine = shoppingCartGetId.some( - (item) => item == this.data.selectedIds - ); - if (!determine) { + addBookShopcCar() { + const addFun = async () => { + if (!this.data.expire) { + const shoppingCartGetId = []; let query = { - requests: [{ - saleMethodId: this.data.selectedIds, - storeEventId: null, - agentCode: "鐢靛瓙涔�", - }, ], + start: 0, + size: 9999, + filterList: [], + searchList: [], }; - const addRes = app.MG.store.addShoppingCart(query); - this.showSuccessToast(); + const res = await app.MG.store.getShoppingCartProductList(query); + res.datas.forEach((item) => { + shoppingCartGetId.push(item.saleMethod.id); + }); + const determine = shoppingCartGetId.some( + (item) => item == this.data.selectedIds + ); + if (!determine) { + let query = { + requests: [{ + saleMethodId: this.data.selectedIds, + storeEventId: null, + agentCode: "鐢靛瓙涔�", + }, ], + }; + const addRes = app.MG.store.addShoppingCart(query); + this.showSuccessToast(); + } else { + Toast({ + context: this, + selector: "#t-toast", + message: "璇ヤ功宸插湪璐墿杞︼紝璇峰嬁閲嶅娣诲姞", + theme: "warning", + direction: "column", + }); + } } else { - Toast({ - context: this, - selector: "#t-toast", - message: "璇ヤ功宸插湪璐墿杞︼紝璇峰嬁閲嶅娣诲姞", - theme: "warning", - direction: "column", + wx.showToast({ + title: "鍟嗗搧涓嶅湪鏈夋晥鏈�", + icon: "none", + duration: 1000, }); } - } else { - wx.showToast({ - title: "鍟嗗搧涓嶅湪鏈夋晥鏈�", - icon: "none", - duration: 1000, - }); } + const token = wx.getStorageSync(app.config.tokenKey); + if (token) { + addFun() + } else { + this.logInFun(() => {}) + } + }, showSuccessToast() { @@ -1386,7 +1428,6 @@ applyState: "Normal", deadline: "姘镐箙", }); - console.log("鏈夋晥鏃ユ湡", this.data.deadline); } else { let endTime = new Date(endDate + " 23:59:59").getTime(); this.setData({ @@ -1638,20 +1679,26 @@ }, // 鍒ゆ柇璧勬簮鏄惁璐拱 resourceIsBuy(data) { - let couldId = null - let codeData = null - if (this.data.resourceCodeList.length) { - codeData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning') - if (codeData && codeData.saleMethod && codeData.saleMethod.length) - couldId = codeData.saleMethod[0].Id - } - if (couldId) { - return this.data.buyIdList.indexOf(couldId) > -1 ? false : true - } else if (data.saleMethod && data.saleMethod.length) { - const isSHow = this.data.buyIdList.some( - (item) => item == data.saleMethod[0].Id + if (data.saleMethod && data.saleMethod.length) { + const saleData = data.saleMethod.find((item) => item.SaleType == 'Normal') + if (saleData.State == 'Disable') return false + const isShow = this.data.buyIdList.some( + (item) => item == saleData.Id ); - return !isSHow; + // 宸茬粡璐拱 + if (isShow || saleData.Price == 0) return false + // 鏈喘涔帮紝鏌ョ湅閿�鍞柟寮忔槸鍚﹁繃鏈� + if (!isShow) { + const flag = new Date(saleData.EndDate).getTime() >= new Date().getTime() && + new Date(saleData.BeginDate).getTime() <= new Date().getTime() + if (flag) { + // 涓鸿繃鏈� 锛岄渶瑕佽喘涔� + return true + } else { + // 宸茶繃鏈� 鏃犻渶璐拱 + return false + } + } } else { return false; } @@ -1693,30 +1740,31 @@ }, // 鍒ゆ柇璧勬簮鍔犲叆璐墿杞︽寜閽槸鍚︽樉绀� isShoppingCart(data) { - let couldId = null - let codeData = null - if (this.data.resourceCodeList.length) { - codeData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning') - if (codeData && codeData.saleMethod && codeData.saleMethod.length) - couldId = codeData.saleMethod[0].Id - } - if (couldId) { - return this.data.buyIdList.indexOf(couldId) > -1 ? false : true - } else if (data.saleMethod && data.saleMethod.length) { - if (data.saleMethod[0].Price <= 0) return false; + if (data.saleMethod && data.saleMethod.length) { + const saleData = data.saleMethod.find((item) => item.SaleType == 'Normal') + // 鍏堝垽鏂槸鍚﹀厤璐� + if (saleData.Price <= 0) return false // 鍐嶅垽鏂槸鍚﹁喘涔� - const isBuy = this.data.buyIdList.some( - (item) => item == data.saleMethod[0].Id - ); + const isBuy = this.data.buyIdList.some((item) => item == saleData.Id) if (isBuy) { // 璐拱浜� - return false; + return false } else { // 鍒ゆ柇鏄惁鍔犲叆璐墿杞� - const isSHow = this.data.shoppingCartGetId.some( - (item) => item == data.saleMethod[0].Id - ); - return !isSHow; + const isShow = this.data.shoppingCartGetId.some((item) => item == saleData.Id) + if (isShow) return false + // 鏈喘涔帮紝鏌ョ湅閿�鍞柟寮忔槸鍚﹁繃鏈� + if (!isShow) { + const flag = new Date(saleData.EndDate).getTime() >= new Date().getTime() && + new Date(saleData.BeginDate).getTime() <= new Date().getTime() + if (flag) { + // 涓鸿繃鏈� 锛岄渶瑕佽喘涔� + return true + } else { + // 宸茶繃鏈� 鏃犻渶璐拱 + return false + } + } } } else { return false; @@ -1750,47 +1798,53 @@ flattenedArray.push(...childrenArray); } }); - return flattenedArray.filter((item) => item.sysType == "CmsItem"); + return flattenedArray; }, // 浜戝涔犱竴閿鍙� - async getFreeResource() { - const child = this.selectComponent("#learn-resource"); - const token = wx.getStorageSync(app.config.tokenKey); - if (!token) { - loginInfo(app, (data) => { - // 濡傛灉涓嶆槸绗竴娆$櫥褰曪紝浼氭墽琛屽洖璋� - if (data) { - // 鐧诲綍鎴愬姛锛岃嚜鍔ㄨ褰晅oken鍜岀敤鎴蜂俊鎭紝骞惰繑鍥瀟rue - } else { - // 鍑虹幇閿欒锛岃繑鍥瀎alse + getFreeResource() { + const getFreeFun = async () => { + // 棰嗗彇鏌ョ湅 锛屽厛鐪嬩簯瀛︿範涓婄殑 鍐嶇湅璧勬簮涓婄殑 + const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning') + const cloundMenuSaleMethod = + cloundMenu.saleMethod && cloundMenu.saleMethod.length ? + cloundMenu.saleMethod.find((ditem) => ditem.SaleType == 'Normal') : + undefined + let query = {} + if (this.data.isCloundHaveSaleMethod && !cloundMenuSaleMethod.Price) { + // 浜戝涔犱笂鏈夐攢鍞柟寮忥紝涓斾负0鍏冿紝鐩存帴棰嗗彇浜戝涔� + query = { + remarks: '浜戝涔�', + requests: [{ + saleMethodId: cloundMenuSaleMethod.Id, + count: 1 + }] } - }); - } else { - let arr = this.handleTreeData(this.data.learn).filter((item) => - this.resourceIsBuy(item) - ); - let freeIds = arr.filter((item) => { - return item.saleMethod[0].Price == 0; - }); - if (!freeIds.length) - return wx.showToast({ - icon: "error", - title: "鏆傛棤鍏嶈垂璧勬簮", - }); - child.changeReceive(true); - let requests = []; - freeIds.forEach((item, index) => { - if (this.resourceIsBuy(item)) { - requests.push({ - saleMethodId: item.saleMethod[0].Id, - count: 1, + } else { + // 棰嗗彇璧勬簮 + let arr = this.handleTreeData(this.data.learn).filter(item => this.resourceIsBuy(item)) + let freeIds = arr.filter((item) => { + return item.saleMethod.find((citem) => citem.SaleType == 'Normal').Price == 0 + }) + if (!freeIds.length) + return wx.showToast({ + icon: "error", + title: "鏆傛棤鍏嶈垂璧勬簮", }); - } - }); - let query = { - remarks: "浜戝涔�", - requests, - }; + let requests = []; + freeIds.forEach((item, index) => { + if (this.resourceIsBuy(item)) { + requests.push({ + saleMethodId: item.saleMethod[0].Id, + count: 1, + }); + } + }); + query = { + remarks: "浜戝涔�", + requests, + }; + } + child.changeReceive(true); try { const initOrderRes = await app.MG.store.initOrder(query); let parameter = { @@ -1816,6 +1870,14 @@ console.log(error); } } + const child = this.selectComponent("#learn-resource"); + const token = wx.getStorageSync(app.config.tokenKey); + if (!token) { + this.logInFun(() => {}); + } else { + getFreeFun() + } + }, // 浜戝涔犱竴閿喘涔� async allAddShoppiingCar() { @@ -1829,7 +1891,8 @@ }, }); } - let shopList = this.handleTreeData(this.data.learn).filter((item) => + let shopList = this.handleTreeData(this.data.learn).filter(item => item.cmsType == 'cmsItem') + shopList = shopList.filter((item) => this.resourceIsBuy(item) ); this.getShoppingCartProductGet(); @@ -1866,6 +1929,40 @@ }); } }, + // 浜戝涔犲叏閮ㄨ喘涔� + buyCloudLearnClass() { + const buyClass = async () => { + const cloundMenu = this.data.resourceCodeList.find((item) => item.refCode == 'jsek_cloudLearning') + let query = { + remarks: '浜戝涔�', + requests: [{ + saleMethodId: cloundMenu.saleMethod.find((eitem) => eitem.SaleType == 'Normal').Id, + count: 1 + }] + } + const initOrderRes = await app.MG.store.initOrder(query) + // 妫�鏌ヨ鍗曞彿鏄惁瀛樺湪 + if (initOrderRes.orderNumber) { + // bookService: orderNumber.value, 灏戜紶杩欎釜 锛屾殏鏃朵笉鐭ラ亾鏈変粈涔堢敤 + wx.navigateTo({ + url: `/pages/cart/paymentPage/index?&bookId=${this.data.bookDetail.id}&bookName=${this.data.bookDetail.name}&orderNumber=${initOrderRes.orderNumber}`, + }); + } else { + // 璁㈠崟鍙蜂笉瀛樺湪锛屾樉绀鸿鍛婃秷鎭� + wx.showToast({ + icon: "error", + title: "璇烽噸璇�", + }); + } + } + const token = wx.getStorageSync(app.config.tokenKey); + if (token) { + buyClass() + } else { + this.logInFun(() => {}) + } + + }, // 鍙樹负鎵�鏈塩heck true findAndUpdateItemsByIds(tree, ids) { function findAndUpdate(node) { @@ -1884,8 +1981,58 @@ } return tree; // 杩斿洖淇敼鍚庣殑瀹屾暣鏁扮粍 }, - handleTrue() { - // findAndUpdateItemsByIds(this.date.) + + // 棰樺簱璐拱 + async buyBank() { + let query = { + remarks: '浜戞祴璇�', + requests: [{ + saleMethodId: this.data.bankSaleData.Id, + count: 1 + }] + } + const initOrderRes = await app.MG.store.initOrder(query) + if (this.data.bankSaleData.Price) { + // 璐拱 + const url = "/pages/cart/paymentPage/index?orderNumber=" + initOrderRes.orderNumber + '&onNorderSaleMethod=' + initOrderRes.saleMethodLinks[0].orderSaleMethod.id; + wx.navigateTo({ + url, + }); + } else { + // 鍏嶈垂棰嗗彇 + app.MG.store + .confirmOrder({ + orderNum: initOrderRes.orderNumber, + }) + .then((res) => { + if (res) { + wx.showToast({ + title: "棰嗗彇鎴愬姛", + icon: "none", + duration: 1000, + }); + this.getBookInfo(this.data.bookDetail.id); + } + }); + } + }, + // 棰樺簱鍔犲叆璐墿杞� + handleShoppingBank() { + let query = { + requests: [{ + saleMethodId: this.data.bankSaleData.Id, + storeEventId: null, + agentCode: "浜戞祴璇�", + }, ], + }; + app.MG.store.addShoppingCart(query).then(res => { + wx.showToast({ + icon: 'success', + title: '鍔犲叆鎴愬姛', + }) + this.getShoppingCartProductGet(); + this.getBookInfo(this.data.bookDetail.id) + }) }, // 缁勫嵎鏍煎紡鍖栨棩鏈熸樉绀� DateFormat(date, fmt) { @@ -1956,53 +2103,62 @@ }); }, // 璐拱缁勫嵎 - 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, + buyMock() { + const buyMockFun = async () => { + let res; + if (!this.data.mockData.id) + return wx.showToast({ + icon: "error", + title: "鏆傛棤缁勫嵎", + mask: true, }); - 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: "棰嗗彇鎴愬姛", - }); + // 鏋勫缓璁㈠崟鏌ヨ瀵硅薄 + try { + let query = { + remarks: "缁勫嵎", + requests: [{ + saleMethodId: this.data.mockData.id, + count: 1, + }, ], + }; + if (this.data.flag) { this.setData({ - flag: true, + flag: false, }); - await this.recordBuyMock(); // 璁板綍璐拱鏃堕棿 + 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); } - } catch (error) { - console.log(error); } + const token = wx.getStorageSync(app.config.tokenKey); + if (token) { + buyMockFun() + } else { + this.logInFun(() => {}) + } + }, // 璁板綍璐拱缁勫嵎鏃堕棿 recordBuyMock() { @@ -2104,40 +2260,65 @@ }, // 搴曢儴璐拱鎸夐挳 buyBtn() { - if (this.data.tabValue == "brief" && !this.data.bookBuy) { - this.buyBook(); - } else if (this.data.tabValue == "jsek_cloudLearning") { - const tree = this.selectComponent("#tree"); - tree.onCloudShoppingCart(); - } else { - console.log(this.data.tabValue); + const buyFun = () => { + if (this.data.tabValue == "brief" && !this.data.bookBuy) { + this.buyBook(); + } else if (this.data.tabValue == "jsek_cloudLearning") { + const tree = this.selectComponent("#tree"); + tree.onCloudShoppingCart(); + } else { + console.log(this.data.tabValue); + } } + const token = wx.getStorageSync(app.config.tokenKey); + if (token) { + buyFun() + } else { + this.logInFun(() => {}) + } + }, - goRead() { - if (!this.data.noFile) { - wx.showToast({ - title: "鏆傛棤闃呰鏂囦欢", - icon: "none", - duration: 2000, + goRead(e) { + const readFun = (bookBuy) => { + if (!this.data.noFile) { + wx.showToast({ + title: "鏆傛棤闃呰鏂囦欢", + icon: "none", + duration: 2000, + }); + return false; + } + wx.navigateTo({ + url: "/packageBookService/pages/components/webView/index?md5=" + + this.data.fileInfo.md5 + + "&fileName=" + + this.data.fileInfo.bookName + + "&fileType=" + + this.data.fileInfo.fileType + + "&freePage=" + + this.data.fileInfo.freePage + + "&bookBuy=" + + bookBuy + + "&bookId=" + + this.data.bookDetail.id, }); - return false; } - wx.navigateTo({ - url: "/packageBookService/pages/components/webView/index?md5=" + - this.data.fileInfo.md5 + - "&fileName=" + - this.data.fileInfo.bookName + - "&fileType=" + - this.data.fileInfo.fileType + - "&freePage=" + - this.data.fileInfo.freePage + - "&bookBuy=" + - this.data.bookBuy + - "&bookId=" + - this.data.bookDetail.id, + const { + type + } = e.currentTarget.dataset + if (type == 'freeFile') return readFun(this.data.bookBuy) + if (this.data.bookDetail.price == '0.00') + return readFun(true) + const token = wx.getStorageSync(app.config.tokenKey); + if (token) { + readFun(this.data.bookBuy) + } else { + this.logInFun(() => { + readFun(this.data.bookBuy) + }) + } - }); }, //鏍蜂功鐢宠 @@ -2202,7 +2383,6 @@ } }); const smBook = list.find(item => item.content[0].id == this.data.bookDetail.id) - console.log('宸茬敵璇�', smBook); if (smBook && smBook.state == 'Normal') { const flag = new Date(smBook.feedBack.endDate + ' 23:59:59').getTime() > new Date().getTime() if (flag) { @@ -2251,179 +2431,127 @@ //鐢宠鐢靛瓙鏍蜂功 appplyElectronicBook() { - // 鍏堝垽鏂笅鏁欏笀璁よ瘉锛屾湭瀵瑰師鏈夐�昏緫淇敼 - let role = this.data.userInfo != null ? this.data.userInfo.role : null; - if (role && role == "Teacher") {} else { - return wx.showModal({ - title: "灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�", //鎻愮ず鐨勬爣棰� - content: "璇峰厛杩涜鏁欏笀璁よ瘉锛�", //鎻愮ず鐨勫唴瀹� - confirmColor: "#ff6c00", - cancelColor: "#949494", - success: function (res) { - if (res.confirm) { - wx.navigateTo({ - url: "/packageDomain/pages/teacherCertification/index", - }); - } else if (res.cancel) {} - }, - }); - } - if ( - this.data.bookDetail.isApplyBook == 2 || - this.data.bookDetail.isApplyBook == 4 - ) { + const applyFun = () => { + // 鍏堝垽鏂笅鏁欏笀璁よ瘉锛屾湭瀵瑰師鏈夐�昏緫淇敼 let role = this.data.userInfo != null ? this.data.userInfo.role : null; - if (role && role == "Teacher") { - if (!this.data.noFile) { - wx.showToast({ - title: "鏆傛棤鐢靛瓙涔︽枃浠�,璇疯仈绯荤鐞嗗憳!", - icon: "none", - duration: 1000, - }); - return; - } - if (this.data.ebookCount == 0) { - wx.showToast({ - title: "鎮ㄧ殑鐢靛瓙鏍蜂功鐢宠娆℃暟宸茬敤灏斤紝鑻ヨ缁х画锛岃鑱旂郴绠$悊鍛橈紒", - icon: "none", - duration: 1000, - }); - return false; - } - - let isHas = this.data.electronicBookList.find( - (eitem) => eitem.id == this.data.bookDetail.id - ); - if (isHas) { - wx.showToast({ - title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�", - icon: "none", - duration: 1000, - }); - return false; - } - let isApply = this.data.alreadyElectronicBookList.find( - (eitem) => eitem.content[0].id == this.data.bookDetail.id - ); - if (isApply) { - if (isApply.state == 'WaitAudit') { + if (role && role == "Teacher") {} else { + return wx.showModal({ + title: "灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�", //鎻愮ず鐨勬爣棰� + content: "璇峰厛杩涜鏁欏笀璁よ瘉锛�", //鎻愮ず鐨勫唴瀹� + confirmColor: "#ff6c00", + cancelColor: "#949494", + success: function (res) { + if (res.confirm) { + wx.navigateTo({ + url: "/packageDomain/pages/teacherCertification/index", + }); + } else if (res.cancel) {} + }, + }); + } + if ( + this.data.bookDetail.isApplyBook == 2 || + this.data.bookDetail.isApplyBook == 4 + ) { + let role = this.data.userInfo != null ? this.data.userInfo.role : null; + if (role && role == "Teacher") { + if (!this.data.noFile) { wx.showToast({ - title: "璇ヤ功宸茬敵璇凤紒", + title: "鏆傛棤鐢靛瓙涔︽枃浠�,璇疯仈绯荤鐞嗗憳!", + icon: "none", + duration: 1000, + }); + return; + } + if (this.data.ebookCount == 0) { + wx.showToast({ + title: "鎮ㄧ殑鐢靛瓙鏍蜂功鐢宠娆℃暟宸茬敤灏斤紝鑻ヨ缁х画锛岃鑱旂郴绠$悊鍛橈紒", icon: "none", duration: 1000, }); return false; - } else if (isApply.state == 'Normal') { - const flag = new Date(isApply.feedBack.endDate + ' 23:59:59').getTime() > new Date().getTime() - if (flag) { + } + + let isHas = this.data.electronicBookList.find( + (eitem) => eitem.id == this.data.bookDetail.id + ); + if (isHas) { + wx.showToast({ + title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�", + icon: "none", + duration: 1000, + }); + return false; + } + let isApply = this.data.alreadyElectronicBookList.find( + (eitem) => eitem.content[0].id == this.data.bookDetail.id + ); + if (isApply) { + if (isApply.state == 'WaitAudit') { wx.showToast({ title: "璇ヤ功宸茬敵璇凤紒", icon: "none", duration: 1000, }); return false; + } else if (isApply.state == 'Normal') { + const flag = new Date(isApply.feedBack.endDate + ' 23:59:59').getTime() > new Date().getTime() + if (flag) { + wx.showToast({ + title: "璇ヤ功宸茬敵璇凤紒", + icon: "none", + duration: 1000, + }); + return false; + } } } - } - if (this.data.electronicBookList.length >= 2) { - wx.showToast({ - title: "姣忔鏈�澶氬彧鍙敵璇�2鏈牱涔�", - icon: "none", - duration: 1000, + if (this.data.electronicBookList.length >= 2) { + wx.showToast({ + title: "姣忔鏈�澶氬彧鍙敵璇�2鏈牱涔�", + icon: "none", + duration: 1000, + }); + return false; + } + this.addBookFun(this.data.bookDetail, "eBook"); + } else { + wx.showModal({ + title: "灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�", //鎻愮ず鐨勬爣棰� + content: "璇峰厛杩涜鏁欏笀璁よ瘉锛�", //鎻愮ず鐨勫唴瀹� + confirmColor: "#ff6c00", + cancelColor: "#949494", + success: function (res) { + if (res.confirm) { + wx.navigateTo({ + url: "/packageDomain/pages/teacherCertification/index", + }); + } else if (res.cancel) {} + }, }); - return false; } - this.addBookFun(this.data.bookDetail, "eBook"); } else { - wx.showModal({ - title: "灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�", //鎻愮ず鐨勬爣棰� - content: "璇峰厛杩涜鏁欏笀璁よ瘉锛�", //鎻愮ず鐨勫唴瀹� - confirmColor: "#ff6c00", - cancelColor: "#949494", - success: function (res) { - if (res.confirm) { - wx.navigateTo({ - url: "/packageDomain/pages/teacherCertification/index", - }); - } else if (res.cancel) {} - }, + wx.showToast({ + title: "璇ヤ功涓嶈兘鐢宠鐢靛瓙鏍蜂功", + icon: "none", + duration: 1000, }); } - } else { - wx.showToast({ - title: "璇ヤ功涓嶈兘鐢宠鐢靛瓙鏍蜂功", - icon: "none", - duration: 1000, - }); } + const token = wx.getStorageSync(app.config.tokenKey); + if (token) { + applyFun() + } else { + this.logInFun(() => {}) + } + }, //鐢宠绾歌川鏍蜂功 appplyPaperBook() { - let role = this.data.userInfo != null ? this.data.userInfo.role : null; - if (role && role == "Teacher") {} else { - return wx.showModal({ - title: "灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�", //鎻愮ず鐨勬爣棰� - content: "璇峰厛杩涜鏁欏笀璁よ瘉锛�", //鎻愮ず鐨勫唴瀹� - confirmColor: "#ff6c00", - cancelColor: "#949494", - success: function (res) { - if (res.confirm) { - wx.navigateTo({ - url: "/packageDomain/pages/teacherCertification/index", - }); - } else if (res.cancel) {} - }, - }); - } - if ( - this.data.bookDetail.isApplyBook == 3 || - this.data.bookDetail.isApplyBook == 4 - ) { + const applyFun = () => { let role = this.data.userInfo != null ? this.data.userInfo.role : null; - if (role && role == "Teacher") { - // 鐐瑰嚮閫変腑 - if (this.data.paperBookCount == 0) { - wx.showToast({ - title: "鎮ㄧ殑绾歌川鏍蜂功鐢宠娆℃暟宸茬敤灏斤紝鑻ヨ缁х画锛岃鑱旂郴绠$悊鍛橈紒", - icon: "none", - duration: 1000, - }); - return false; - } - let isApply = this.data.alreadyPaperBookList.find( - (pitem) => pitem.content[0].id == this.data.bookDetail.id - ); - if (isApply) { - wx.showToast({ - title: "璇ヤ功宸茬敵璇凤紒", - icon: "none", - duration: 1000, - }); - return false; - } - - let isHas = this.data.paperBookList.find( - (pitem) => pitem.id == this.data.bookDetail.id - ); - if (isHas) { - wx.showToast({ - title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�", - icon: "none", - duration: 1000, - }); - return false; - } - if (this.data.paperBookList.length >= 2) { - wx.showToast({ - title: "姣忔鏈�澶氬彧鍙敵璇�2鏈牱涔�", - icon: "none", - duration: 1000, - }); - return false; - } - this.addBookFun(this.data.bookDetail, "pBook"); - } else { - wx.showModal({ + if (role && role == "Teacher") {} else { + return wx.showModal({ title: "灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�", //鎻愮ず鐨勬爣棰� content: "璇峰厛杩涜鏁欏笀璁よ瘉锛�", //鎻愮ず鐨勫唴瀹� confirmColor: "#ff6c00", @@ -2437,13 +2565,83 @@ }, }); } - } else { - wx.showToast({ - title: "璇ヤ功涓嶈兘鐢宠绾歌川鏍蜂功", - icon: "none", - duration: 1000, - }); + if ( + this.data.bookDetail.isApplyBook == 3 || + this.data.bookDetail.isApplyBook == 4 + ) { + let role = this.data.userInfo != null ? this.data.userInfo.role : null; + if (role && role == "Teacher") { + // 鐐瑰嚮閫変腑 + if (this.data.paperBookCount == 0) { + wx.showToast({ + title: "鎮ㄧ殑绾歌川鏍蜂功鐢宠娆℃暟宸茬敤灏斤紝鑻ヨ缁х画锛岃鑱旂郴绠$悊鍛橈紒", + icon: "none", + duration: 1000, + }); + return false; + } + let isApply = this.data.alreadyPaperBookList.find( + (pitem) => pitem.content[0].id == this.data.bookDetail.id + ); + if (isApply) { + wx.showToast({ + title: "璇ヤ功宸茬敵璇凤紒", + icon: "none", + duration: 1000, + }); + return false; + } + + let isHas = this.data.paperBookList.find( + (pitem) => pitem.id == this.data.bookDetail.id + ); + if (isHas) { + wx.showToast({ + title: "璇ヤ功宸插湪娓呭崟鍒楄〃涓�", + icon: "none", + duration: 1000, + }); + return false; + } + if (this.data.paperBookList.length >= 2) { + wx.showToast({ + title: "姣忔鏈�澶氬彧鍙敵璇�2鏈牱涔�", + icon: "none", + duration: 1000, + }); + return false; + } + this.addBookFun(this.data.bookDetail, "pBook"); + } else { + wx.showModal({ + title: "灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�", //鎻愮ず鐨勬爣棰� + content: "璇峰厛杩涜鏁欏笀璁よ瘉锛�", //鎻愮ず鐨勫唴瀹� + confirmColor: "#ff6c00", + cancelColor: "#949494", + success: function (res) { + if (res.confirm) { + wx.navigateTo({ + url: "/packageDomain/pages/teacherCertification/index", + }); + } else if (res.cancel) {} + }, + }); + } + } else { + wx.showToast({ + title: "璇ヤ功涓嶈兘鐢宠绾歌川鏍蜂功", + icon: "none", + duration: 1000, + }); + } } + const token = wx.getStorageSync(app.config.tokenKey); + if (token) { + applyFun() + } else { + this.logInFun(() => {}) + } + }, // 娣诲姞鏍蜂功 addBookFun(item, type) { @@ -2487,9 +2685,14 @@ //鍘绘牱涔︾敵璇峰崟 goApply() { - wx.navigateTo({ - url: "/packageDomain/pages/sampleBookList/applicationForm/index", - }); + const token = wx.getStorageSync(app.config.tokenKey); + if (token) { + wx.navigateTo({ + url: "/packageDomain/pages/sampleBookList/applicationForm/index", + }); + } else { + this.logInFun(() => {}) + } }, handleTree() { // const child = this.selectComponent('#teach-tree') @@ -2570,15 +2773,36 @@ return childrenList }, uploadFile(e) { - console.log(123) - this.setData({ - dialogBox: true, - isShowUp: true - }); + const uploadFun = () => { + const userInfo = JSON.parse(wx.getStorageSync(app.config.userInfoKey)) + if (userInfo.role != 'Teacher') return wx.showToast({ + icon: 'error', + title: '璇峰厛杩涜鏁欏笀璁よ瘉', + }) + this.setData({ + dialogBox: true, + isShowUp: true + }); + } + const token = wx.getStorageSync(app.config.tokenKey); + if (token) { + uploadFun() + } else { + this.logInFun(() => { + uploadFun() + }) + } + }, closeDialog() { this.setData({ dialogBox: false, + resourceInfo: { + resourceName: '', + fileType: '', + description: '', + agree: false + }, }); }, onCloseProtocol() { @@ -2617,14 +2841,29 @@ }, onNameInput(e) { - console.log(e.detail.value) this.setData({ 'resourceInfo.resourceName': e.detail.value, }); }, - onFileTypeInput(e) { + onResourcePicker(e) { this.setData({ - 'resourceInfo.fileType': e.detail.value, + resourceValue: [this.data.resourceInfo.fileType], + resourceVisible: true, + }); + }, + onPickerChange(e) { + const { + value + } = e.detail; + this.setData({ + resourceVisible: false, + resourceValue: value, + 'resourceInfo.fileType': value.join(' '), + }); + }, + onPickerCancel(e) { + this.setData({ + resourceVisible: false, }); }, textareaChange(e) { @@ -2665,6 +2904,7 @@ const pdfData = ['pdf'] const Compression = ['rar', 'zip'] const pictureData = ['jpg', 'png'] + const documentData = ['doc', 'docx', 'xls', 'xlsx', "ppt", "pptx"] if (audioData.indexOf(Extension) > -1) { medioType = '闊抽' } else if (videoData.indexOf(Extension) > -1) { @@ -2675,6 +2915,8 @@ medioType = '璧勬簮鍖�' } else if (pictureData.indexOf(Extension) > -1) { medioType = '鍥剧墖' + } else if (documentData.indexOf(Extension) > -1) { + medioType = '鏂囨。' } else { medioType = '鍏朵粬' } @@ -2718,6 +2960,7 @@ that.setData({ "resourceInfo.resourceName": FileName, "resourceInfo.fileType": medioType, + fileList: file, isShowUp: false }) @@ -2732,15 +2975,9 @@ }, handleRemove(e) { - console.log(e) - let md5 = e.currentTarget.dataset.md5 - for (let i = 0; i < this.data.fileList.length; i++) { - if (this.data.fileList.md5 == md5) { - this.data.fileList.splice(i, 1) - } - } this.setData({ isShowUp: true, + fileList: [] }); }, confirmM() { @@ -2753,7 +2990,7 @@ if (this.data.resourceInfo.fileType == '') { return wx.showToast({ icon: "error", - title: "璇峰~鍐欒祫婧愮被鍨�", + title: "璇烽�夋嫨璧勬簮绫诲瀷", }); } @@ -2781,11 +3018,25 @@ app.MG.ugc.newTopicMessage(query).then((res) => { wx.showToast({ icon: "success", - title: "璇蜂笂浼犺祫婧愭枃浠�", + title: "涓婁紶鎴愬姛", }); - this.setData({ - dialogBox: false, - }); + this.closeDialog() }) - } + }, + getCloundIsBuy() { + let flag = false + if (!this.data.isCloundHaveSaleMethod) flag = false + const cloundData = this.data.resourceCodeList.find(item => item.refCode == 'jsek_cloudLearning') + const saleData = cloundData.saleMethod.find(item => item.SaleType == "Normal") + if (!saleData) flag = false + flag = this.data.buyIdList.some(item => item == saleData.Id) + this.setData({ + cloundMenuIsBuy: flag + }) + }, + /** + * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜� + */ + onShareAppMessage() {}, + onShareTimeline() {} }) \ No newline at end of file -- Gitblit v1.9.1