| | |
| | | // 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(); |
| | | Page({ |
| | | /** |
| | | * 页面的初始数据 |
| | | */ |
| | | data: { |
| | | // 进页面默认切换 展开的id |
| | | // defaultactiveTeachid 教学资源 |
| | | // defaultactiveLearnid 云学习 |
| | | bookId: "", |
| | | barHeight: "", |
| | | navBarHeight: "", |
| | |
| | | showIndex: '', |
| | | successOrderNumber: '', |
| | | applicationState: '', // 电子样书申请状态 |
| | | |
| | | dialogBox: false, |
| | | resourceInfo: { |
| | | resourceName: '', |
| | | fileType: '', |
| | | 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: '' |
| | | }, |
| | | |
| | | resetTree: function (e) { |
| | |
| | | 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), |
| | | }) |
| | | let token = wx.getStorageSync(app.config.tokenKey) |
| | | if (!token) { |
| | | loginInfo(app, (data) => { |
| | | if (data) {} else {} |
| | | }) |
| | | } |
| | | this.getBookInfo(options.id); |
| | | // this.getResourceClass(); // 获取资源所属分类 |
| | | const token = wx.getStorageSync(app.config.tokenKey); |
| | | token = wx.getStorageSync(app.config.tokenKey) |
| | | if (token) { |
| | | this.getShoppingCartProductGet(); |
| | | this.getApplyInfo(options.id); |
| | |
| | | // 获取申请次数 |
| | | this.getSelectPaperBookCount(); |
| | | this.getSelectBookCount(); |
| | | } |
| | | if (options.tabValue) { |
| | | this.setData({ |
| | | tabValue: options.tabValue, |
| | | }); |
| | | |
| | | |
| | | } |
| | | }, |
| | | |
| | |
| | | dangdangLink: [], |
| | | weidianLink: [], |
| | | content: [], |
| | | catalogue: [], |
| | | authorIntroduction: [], |
| | | // isApplyPaperBook: [], |
| | | // isApplyEBook: [], |
| | |
| | | await this.getBookClass(classData); |
| | | } |
| | | } |
| | | 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) |
| | | } |
| | | } |
| | | |
| | | // 获取组卷销售id |
| | | if (res.datas.saleMethod && res.datas.saleMethod.length) { |
| | |
| | | } |
| | | } |
| | | this.setData({ |
| | | "bookDetail.publicationDate": this.formatDate( |
| | | this.data.bookDetail.publicationDate |
| | | ), |
| | | "bookDetail.publicationDate": moment(this.data.bookDetail.publicationDate).format("YYYY年MM月"), |
| | | "bookDetail.price": this.numFormat(this.data.bookDetail.price), |
| | | "bookDetail.oldPrice": this.numFormat(this.data.bookDetail.oldPrice), |
| | | "bookDetail.paperPrice": this.numFormat( |
| | |
| | | link |
| | | } = e.currentTarget.dataset; |
| | | wx.navigateTo({ |
| | | url: `/packageBookService/pages/bookServices/webpage/index?url=${link}`, |
| | | url: `/packageBookService/pages/bookServices/linkPage/index?path=${link}`, |
| | | }); |
| | | }, |
| | | // tag切换 |
| | |
| | | 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) { |
| | |
| | | }, |
| | | |
| | | // 扁平化数据转换tree |
| | | getTreeList(rootList, pathLength, newArr, path, addNum) { |
| | | getTreeList(rootList, pathLength, 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)) { |
| | |
| | | } |
| | | // newArr.push(item) |
| | | // 在插入过程中对数据进行排序 |
| | | newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item, addNum) |
| | | newArr = this.insertAndSortObjectsByProductLinkPath(newArr, item) |
| | | // 插进数组后 从原数据中删除 |
| | | rootList = rootList.filter(nitem => nitem.id != item.id) |
| | | } |
| | |
| | | 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, addnum1) |
| | | this.getTreeList(rootList, pathLength + addnum1, i.children, i.productLinkPath) |
| | | if (i.children.length == 0) { |
| | | delete i.children |
| | | } |
| | |
| | | }, |
| | | |
| | | // 排序数组 按照productLinkPath |
| | | insertAndSortObjectsByProductLinkPath(array, newObj, addNum) { |
| | | insertAndSortObjectsByProductLinkPath(array, newObj) { |
| | | // 查找新对象应该插入的位置 |
| | | let insertIndex = array.findIndex(obj => Number(newObj.productLinkPath.substring(newObj.productLinkPath.length - addNum, newObj.productLinkPath.length)) < Number(obj.productLinkPath.substring(obj.productLinkPath.length - addNum, obj.productLinkPath.length))); |
| | | 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))); |
| | | // 如果没有找到合适的位置,则放在数组末尾 |
| | | if (insertIndex === -1) { |
| | | insertIndex = array.length; |
| | |
| | | // 测试6 正式5 |
| | | // 对数组进行排序 |
| | | array.sort((a, b) => { |
| | | if (Number(a.productLinkPath.substring(a.productLinkPath.length - addNum, a.productLinkPath.length)) < Number(b.productLinkPath.substring(b.productLinkPath.length - addNum, b.productLinkPath.length))) { |
| | | 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.length - addNum, a.productLinkPath.length)) > Number(b.productLinkPath.substring(b.productLinkPath.length - addNum, b.productLinkPath.length))) { |
| | | 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 |
| | |
| | | }) |
| | | } |
| | | } |
| | | const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 14 ? 8 : 6 |
| | | 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, '\\', addNum) |
| | | this.getTreeList(res.datas.cmsDatas[0].datas, num, list, '\\') |
| | | list = this.ensureTreeConsistency(list) |
| | | list = this.changeResourceChildren(list) |
| | | console.log('修改后', 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)); |
| | | |
| | | // const newUSeList = this.deleteTreeData(list, result) |
| | | // console.log('树剔除', result, newUSeList); |
| | | // console.log('树加一', this.increaseTreeData(list, newUSeList, 16094)); |
| | | this.setData({ |
| | | openTeachids: result, |
| | | loading: false, |
| | |
| | | let list = [] |
| | | // 测试 6位// 正式 5位// 测试调用传20,内部7 正式调用传17 内部传6 |
| | | |
| | | const addNum = query.cmsPath.length > 10 ? 7 : query.cmsPath.length > 14 ? 8 : 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, '\\', addNum) |
| | | that.getTreeList(data, num, list, '\\') |
| | | list = that.ensureTreeConsistency(list) |
| | | that.findChildIds(list[0].children, result); |
| | | that.setData({ |
| | |
| | | let resultList = [] |
| | | for (let index = 0; index < list.length; index++) { |
| | | const item = list[index]; |
| | | for (let cindex = 0; cindex < item.children.length; cindex++) { |
| | | const citem = item.children[cindex]; |
| | | citem.children = [] |
| | | if (item.children.length > 0) { |
| | | for (let cindex = 0; cindex < item.children.length; cindex++) { |
| | | const citem = item.children[cindex]; |
| | | citem.children = [] |
| | | } |
| | | } |
| | | resultList.push(item) |
| | | } |
| | |
| | | }, |
| | | // 传递ids,将需要展开的id的children 赋值 |
| | | increaseTreeData(treeList, list, openid) { |
| | | |
| | | let num = 0; |
| | | // let useData = treeList.find(item => item.id == openid) |
| | | for (let index = 0; index < treeList.length; index++) { |
| | | const item = treeList[index]; |
| | | if (item.id == openid && num >= 3) { |
| | | debugger |
| | | let useArr = item.children ? item.children : [] |
| | | changeList(list, openid, useArr) |
| | | this.changeList(list, openid, useArr) |
| | | } else { |
| | | num += 1 |
| | | this.increaseTreeData(item.children, list, openid) |
| | | } |
| | | } |
| | | // 递归前两层,找出需要展开的 |
| | | const changeList = (isList, id, childrenList) => { |
| | | for (let dindex = 0; dindex < isList.length; dindex++) { |
| | | const ditem = isList[cindex]; |
| | | if (ditem.id == id) { |
| | | diitem.children = childrenList |
| | | return true |
| | | } else { |
| | | changeList(ditem.children, id, childrenList) |
| | | } |
| | | |
| | | }, |
| | | // 递归前两层,找出需要展开的 |
| | | changeList(isList, id, childrenList) { |
| | | for (let dindex = 0; dindex < isList.length; dindex++) { |
| | | const ditem = isList[dindex]; |
| | | if (ditem.id == id) { |
| | | ditem.children = childrenList |
| | | return true |
| | | } else { |
| | | this.changeList(ditem.children, id, childrenList) |
| | | } |
| | | } |
| | | return list |
| | | return childrenList |
| | | }, |
| | | uploadFile(e) { |
| | | this.setData({ |
| | | dialogBox: true, |
| | | isShowUp: true |
| | | }); |
| | | }, |
| | | closeDialog() { |
| | | this.setData({ |
| | | dialogBox: false, |
| | | resourceInfo: { |
| | | resourceName: '', |
| | | fileType: '', |
| | | description: '', |
| | | agree: false |
| | | }, |
| | | }); |
| | | }, |
| | | onCloseProtocol() { |
| | | this.setData({ |
| | | protocolShow: false, |
| | | }); |
| | | }, |
| | | onVisibleChange(e) { |
| | | this.setData({ |
| | | protocolShow: e.detail.visible, |
| | | }); |
| | | }, |
| | | //查看协议 |
| | | getAgreement() { |
| | | let query = { |
| | | path: 'jsek_protocol', |
| | | fields: { |
| | | content: [], |
| | | } |
| | | } |
| | | app.MG.resource.getItem(query).then((res) => { |
| | | try { |
| | | |
| | | const data = res.datas.find((e) => e.refCode == 'jsek_authorizationAndConsentLetter') |
| | | this.setData({ |
| | | protocolTxt: data && data.content ? data.content : '暂无协议', |
| | | protocolShow: true |
| | | }); |
| | | } catch (error) { |
| | | this.setData({ |
| | | protocolTxt: '暂无协议', |
| | | protocolShow: true, |
| | | }); |
| | | } |
| | | }) |
| | | |
| | | }, |
| | | onNameInput(e) { |
| | | console.log(e.detail.value) |
| | | this.setData({ |
| | | 'resourceInfo.resourceName': e.detail.value, |
| | | }); |
| | | }, |
| | | onResourcePicker(e) { |
| | | this.setData({ |
| | | 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) { |
| | | this.setData({ |
| | | 'resourceInfo.description': e.detail.value, |
| | | }); |
| | | }, |
| | | onChange() { |
| | | if (this.data.resourceInfo.agree) { |
| | | this.setData({ |
| | | 'resourceInfo.agree': false, |
| | | }); |
| | | } else { |
| | | this.setData({ |
| | | 'resourceInfo.agree': true, |
| | | }); |
| | | } |
| | | }, |
| | | uploadPicture() { |
| | | var that = this; |
| | | wx.chooseMessageFile({ |
| | | count: 1, |
| | | type: 'file', |
| | | success(res) { |
| | | const isLt2M = res.tempFiles[0].size / 1024 / 1024 < 50 |
| | | if (!isLt2M) { |
| | | return wx.showToast({ |
| | | title: "上传文件大小不能超过 50MB!", |
| | | icon: "none", |
| | | duration: 1000, |
| | | }); |
| | | } |
| | | const FileName = res.tempFiles[0].name.split('.')[0] |
| | | const Extension = res.tempFiles[0].name.split('.')[1] |
| | | var medioType = '' |
| | | const audioData = ['mp3', 'mp3'] |
| | | const videoData = ['mp4', 'avi'] |
| | | 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) { |
| | | medioType = '视频' |
| | | } else if (pdfData.indexOf(Extension) > -1) { |
| | | medioType = 'PDF' |
| | | } else if (Compression.indexOf(Extension) > -1) { |
| | | medioType = '资源包' |
| | | } else if (pictureData.indexOf(Extension) > -1) { |
| | | medioType = '图片' |
| | | } else if (documentData.indexOf(Extension) > -1) { |
| | | medioType = '文档' |
| | | } else { |
| | | medioType = '其他' |
| | | } |
| | | wx.getFileSystemManager().getFileInfo({ |
| | | filePath: res.tempFiles[0].path, //选择图片返回的相对路径 |
| | | // encoding: 'binary', //编码格式 |
| | | success: ress => { |
| | | //成功的回调 |
| | | let md5 = ress.digest; |
| | | let formData = new FormData(); |
| | | formData.append('Md5', md5); |
| | | formData.append('FileName', FileName); |
| | | formData.append('FileType', res.tempFiles[0].type); |
| | | formData.appendFile("file", res.tempFiles[0].path); |
| | | const data = formData.getData(); |
| | | let _token = wx.getStorageSync(app.config.tokenKey); |
| | | let header = {}; |
| | | if (_token == null) { |
| | | header["Authorization"] = `Basic ${Base64.encode(website.clientId + ":" + website.clientSecret)}`; |
| | | } else { |
| | | header["Authorization"] = `Bearer ` + _token; |
| | | } |
| | | new Promise((resolve, reject) => { |
| | | wx.request({ |
| | | url: app.config.requestCtx + '/file/api/ApiUpload', |
| | | method: 'POST', |
| | | header: { |
| | | 'content-type': data.contentType, |
| | | ...header |
| | | }, |
| | | data: data.buffer, |
| | | success(res1) { |
| | | resolve(res1.data); |
| | | if (res1.data) { |
| | | let file = [{ |
| | | name: res.tempFiles[0].name, |
| | | md5: md5, |
| | | type: medioType, |
| | | FileType: Extension |
| | | }] |
| | | that.setData({ |
| | | "resourceInfo.resourceName": FileName, |
| | | "resourceInfo.fileType": medioType, |
| | | |
| | | fileList: file, |
| | | isShowUp: false |
| | | }) |
| | | } |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | }) |
| | | |
| | | }, |
| | | handleRemove(e) { |
| | | this.setData({ |
| | | isShowUp: true, |
| | | fileList: [] |
| | | }); |
| | | }, |
| | | confirmM() { |
| | | if (this.data.resourceInfo.resourceName == '') { |
| | | return wx.showToast({ |
| | | icon: "error", |
| | | title: "请填写资源名称", |
| | | }); |
| | | } |
| | | if (this.data.resourceInfo.fileType == '') { |
| | | return wx.showToast({ |
| | | icon: "error", |
| | | title: "请选择资源类型", |
| | | }); |
| | | } |
| | | |
| | | if (!this.data.fileList.length) { |
| | | return wx.showToast({ |
| | | icon: "error", |
| | | title: "请上传资源文件", |
| | | }); |
| | | } |
| | | if (!this.data.resourceInfo.agree) { |
| | | return wx.showToast({ |
| | | icon: "none", |
| | | title: "请同意《授权同意书》!", |
| | | }); |
| | | } |
| | | let query = { |
| | | topicIdOrRefCode: "uploadFiles", |
| | | name: this.data.bookDetail.name, |
| | | content: JSON.stringify(JSON.parse(JSON.stringify(this.data.fileList))), |
| | | type: 'UserSubmit', |
| | | description: this.data.resourceInfo.description, |
| | | cmsTypeRefCode: '', |
| | | newDataListRequest: [] |
| | | } |
| | | app.MG.ugc.newTopicMessage(query).then((res) => { |
| | | wx.showToast({ |
| | | icon: "success", |
| | | title: "请上传资源文件", |
| | | }); |
| | | this.closeDialog() |
| | | }) |
| | | } |
| | | }) |