| | |
| | | import { |
| | | loginInfo |
| | | } from "../../../../assets/js/login"; |
| | | import FormData from '../../../../utils/formdata/index.js'; |
| | | const app = getApp(); |
| | | Page({ |
| | | /** |
| | |
| | | showIndex: '', |
| | | successOrderNumber: '', |
| | | applicationState: '', // 电子样书申请状态 |
| | | |
| | | dialogBox: false, |
| | | resourceInfo: { |
| | | resourceName: '', |
| | | fileType: '', |
| | | description: '', |
| | | agree: false |
| | | }, |
| | | fileList: [], |
| | | isShowUp: true, |
| | | protocolShow: false, |
| | | protocolTxt: '' |
| | | }, |
| | | |
| | | resetTree: function (e) { |
| | |
| | | dangdangLink: [], |
| | | weidianLink: [], |
| | | content: [], |
| | | catalogue: [], |
| | | authorIntroduction: [], |
| | | // isApplyPaperBook: [], |
| | | // isApplyEBook: [], |
| | |
| | | }, |
| | | // 传递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) => { |
| | | changeList(isList, id, childrenList) { |
| | | for (let dindex = 0; dindex < isList.length; dindex++) { |
| | | const ditem = isList[cindex]; |
| | | const ditem = isList[dindex]; |
| | | if (ditem.id == id) { |
| | | diitem.children = childrenList |
| | | ditem.children = childrenList |
| | | return true |
| | | } else { |
| | | changeList(ditem.children, id, childrenList) |
| | | this.changeList(ditem.children, id, childrenList) |
| | | } |
| | | } |
| | | return childrenList |
| | | }, |
| | | uploadFile(e) { |
| | | console.log(123) |
| | | this.setData({ |
| | | dialogBox: true, |
| | | isShowUp: true |
| | | }); |
| | | }, |
| | | closeDialog() { |
| | | this.setData({ |
| | | dialogBox: false, |
| | | }); |
| | | }, |
| | | onCloseProtocol() { |
| | | this.setData({ |
| | | protocolShow: false, |
| | | }); |
| | | }, |
| | | onVisibleChange(e) { |
| | | this.setData({ |
| | | protocolShow: e.detail.visible, |
| | | }); |
| | | }, |
| | | //查看协议 |
| | | getAgreement() { |
| | | let query = { |
| | | path: 'jsek_protocol', |
| | | fields: { |
| | | content: [], |
| | | } |
| | | return list |
| | | } |
| | | 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, |
| | | }); |
| | | }, |
| | | onFileTypeInput(e) { |
| | | this.setData({ |
| | | 'resourceInfo.fileType': e.detail.value, |
| | | }); |
| | | }, |
| | | 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'] |
| | | 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 { |
| | | 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) { |
| | | 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, |
| | | }); |
| | | }, |
| | | 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.setData({ |
| | | dialogBox: false, |
| | | }); |
| | | }) |
| | | } |
| | | }) |