From 485fcbbc57cbf7495286359250135c482ec1360a Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期五, 30 八月 2024 09:50:00 +0800
Subject: [PATCH] xz

---
 packageBookService/pages/bookServices/detail/index.js |  260 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 245 insertions(+), 15 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js
index 4214b0e..bbc3420 100644
--- a/packageBookService/pages/bookServices/detail/index.js
+++ b/packageBookService/pages/bookServices/detail/index.js
@@ -4,6 +4,7 @@
 import {
   loginInfo
 } from "../../../../assets/js/login";
+import FormData from '../../../../utils/formdata/index.js';
 const app = getApp();
 Page({
   /**
@@ -157,7 +158,17 @@
     showIndex: '',
     successOrderNumber: '',
     applicationState: '', // 鐢靛瓙鏍蜂功鐢宠鐘舵��
-
+    dialogBox: false,
+    resourceInfo: {
+      resourceName: '',
+      fileType: '',
+      description: '',
+      agree: false
+    },
+    fileList: [],
+    isShowUp: true,
+    protocolShow: false,
+    protocolTxt: ''
   },
 
   resetTree: function (e) {
@@ -376,6 +387,7 @@
         dangdangLink: [],
         weidianLink: [],
         content: [],
+        catalogue: [],
         authorIntroduction: [],
         // isApplyPaperBook: [],
         // isApplyEBook: [],
@@ -2527,32 +2539,250 @@
   },
   // 浼犻�抜ds锛屽皢闇�瑕佸睍寮�鐨刬d鐨刢hildren 璧嬪��
   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) {
+    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: [],
+      }
+    }
+    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,
+      });
+    })
   }
 })
\ No newline at end of file

--
Gitblit v1.9.1