From 4ef1826180997bac879913bf17867bd3e390c29d Mon Sep 17 00:00:00 2001
From: yiming <m13691596795@163.com>
Date: 星期四, 28 三月 2024 09:24:46 +0800
Subject: [PATCH] 微信支付修改

---
 packageBookService/pages/bookServices/detail/index.js |  315 ++++++++++++++++++++++++++++++++++------------------
 1 files changed, 204 insertions(+), 111 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js
index bc9ec6c..6eb4cc2 100644
--- a/packageBookService/pages/bookServices/detail/index.js
+++ b/packageBookService/pages/bookServices/detail/index.js
@@ -34,16 +34,20 @@
     openTeachids: [],
     openLearnids: [],
     openTestids: [],
+    applyResourceState: false, // 鐢宠鏁欏璧勬簮鎸夐挳闃叉姈
     resourceClassList: [], // 璧勬簮鎵�灞炲垎绫�
-    applyState: "",  // 鏁欏璧勬簮鐢宠鐘舵��
-    deadline: "",  // 鏁欏璧勬簮鐢宠鏈夋晥鏃ユ湡
-    rejectCause: "",  // 涓嬭浇鎷掔粷鍘熷洜
+    applyState: "", // 鏁欏璧勬簮鐢宠鐘舵��
+    deadline: "", // 鏁欏璧勬簮鐢宠鏈夋晥鏃ユ湡
+    rejectCause: "", // 涓嬭浇鎷掔粷鍘熷洜
     buyIdList: [],
     shoppingCartGetId: [], // 宸茶喘涔癷d鍒楄〃
     shoppingList: [],
     loading: false,
-    isShowTeachDownload: false,  // 鎻愮ずPC涓嬭浇寮圭獥鐘舵��
-    confirmBtn: { content: '鎴戠煡閬撲簡', variant: 'base' },
+    isShowTeachDownload: false, // 鎻愮ずPC涓嬭浇寮圭獥鐘舵��
+    confirmBtn: {
+      content: '鎴戠煡閬撲簡',
+      variant: 'base'
+    },
     mockData: {
       id: 0, // 閿�鍞甶d
       price: 0, // 鍞环
@@ -53,11 +57,10 @@
       mockList: [] // 鐢ㄦ埛缁勫嵎鎻愪氦淇℃伅
     },
     flag: true,
-    applyResourceLoading: false,
     noResources: false,
-    selectedIds: "",//鍟嗗搧鎴栧瓙鍟嗗搧閿�鍞柟寮�
+    selectedIds: "", //鍟嗗搧鎴栧瓙鍟嗗搧閿�鍞柟寮�
     bookBuy: false, //鍟嗗搧鎴栧瓙鍟嗗搧鏄惁璐拱
-    expire: false,//鍟嗗搧鎴栧瓙鍟嗗搧閿�鍞柟寮忔槸鍚﹁繃鏈�
+    expire: false, //鍟嗗搧鎴栧瓙鍟嗗搧閿�鍞柟寮忔槸鍚﹁繃鏈�
     noFile: false, //鍟嗗搧鎴栧瓙鍟嗘湁鏃犵數瀛愪功鏂囦欢
     num: 0, //鏍蜂功鐢宠鍗曟暟閲�
     alreadyPaperBookList: [], //宸茬敵璇风焊璐ㄦ牱涔�
@@ -72,10 +75,49 @@
       fileType: "",
       md5: "",
       freePage: ""
-    },  //闃呰鍣ㄦ暟鎹�
+    }, //闃呰鍣ㄦ暟鎹�
     buyResourceData: {
       productLinkPath: '',
       refCode: '',
+    },
+    briefIcon: {
+      name: "/static/images/bookService/detail/tushujianjie-g.png"
+    },
+    briefIconClick: {
+      name: '/static/images/bookService/detail/tushujianjie-click.png'
+    },
+    eBookIcon: {
+      name: '/static/images/bookService/detail/ebook-g.png'
+    },
+    eBookClickIcon: {
+      name: '/static/images/bookService/detail/ebook-click.png'
+    },
+    teachResourcesIcon: {
+      name: '/static/images/bookService/detail/jiaoxueziyuan.png'
+    },
+    teachResourcesClickIcon: {
+      name: '/static/images/bookService/detail/jiaoxueziyuan-click.png'
+    },
+    learnResourceIcon: {
+      name: '/static/images/bookService/detail/yunxuexi.png'
+    },
+    learnResourceClickIcon: {
+      name: '/static/images/bookService/detail/yunxuexi-click.png'
+    },
+    testResourceIocn: {
+      name: '/static/images/bookService/detail/test-icon-g.png'
+    },
+    testResourceClickIocn: {
+      name: '/static/images/bookService/detail/test-click-icon.png'
+    },
+    noteIcon: {
+      name: '/static/images/bookService/detail/biji-icon-g.png'
+    },
+    noteClickIcon: {
+      name: '/static/images/bookService/detail/biji-click-icon.png'
+    },
+    icon1: {
+      name: "/static/images/bookService/detail/dangdang.png"
     }
   },
 
@@ -118,6 +160,20 @@
         userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey))
       })
     }
+
+  },
+
+  /**
+   * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
+   */
+  onReady() {
+
+  },
+
+  /**
+   * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず
+   */
+  onShow() {
     if (wx.getStorageSync("paperBookList")) {
       this.setData({
         paperBookList: wx.getStorageSync("paperBookList"),
@@ -134,26 +190,14 @@
   },
 
   /**
-   * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
-   */
-  onReady() {
-
-  },
-
-  /**
-   * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず
-   */
-  onShow() { },
-
-  /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌
    */
-  onHide() { },
+  onHide() {},
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇
    */
-  onUnload() { },
+  onUnload() {},
 
   /**
    * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔
@@ -176,11 +220,11 @@
   /**
    * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�
    */
-  onShareAppMessage() { },
+  onShareAppMessage() {},
   // 鏍煎紡鍖栨棩鏈�
   formatDate(dateString) {
     if (!dateString) {
-      return 'Invalid date';
+      return '';
     }
     const match = dateString.match(/^(\d{4})\/(\d{1,2})\/(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
     if (!match) {
@@ -281,9 +325,12 @@
       });
       this.getSubTtem();
       // 鑾峰彇鍥句功鍒嗙被
-      const iconType = JSON.parse(res.datas.bookClassification)[0][0];
-      const classType = JSON.parse(res.datas.bookClassification)[0][1];
-      const className = await this.getBookClass(iconType, classType)
+      let className = ''
+      if (Array.isArray(res.datas.bookClassification) && res.datas.bookClassification.length) {
+        const iconType = JSON.parse(res.datas.bookClassification)[0][0];
+        const classType = JSON.parse(res.datas.bookClassification)[0][1];
+        className = await this.getBookClass(iconType, classType)
+      }
       // 鑾峰彇缁勫嵎閿�鍞甶d
       if (res.datas.saleMethod && res.datas.saleMethod.length) {
         res.datas.saleMethod.forEach((item) => {
@@ -399,7 +446,6 @@
             });
           }
         }
-        console.log(this.data.fileInfo, 456)
         this.setData({
           selectedIds: this.data.bookDetail.defaultSaleMethodId,
           bookBuy: this.data.bookDetail.purchasedSaleMethodIdList.indexOf(this.data.bookDetail.defaultSaleMethodId) > -1
@@ -481,7 +527,9 @@
   },
   // 璺宠浆缃戝簵
   goShop(e) {
-    const { link } = e.currentTarget.dataset;
+    const {
+      link
+    } = e.currentTarget.dataset;
     wx.navigateTo({
       url: `/packageBookService/pages/bookServices/webpage/index?url=${link}`,
     })
@@ -500,9 +548,9 @@
             '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' && !this.data.teach.length) ||
+          (e.detail.value == 'jsek_cloudLearning' && !this.data.learn.length) ||
+          (e.detail.value == 'questionBank' && !this.data.test.length)) {
           this.getResourceData(checkData)
         }
       } else {
@@ -589,22 +637,26 @@
               item.checked = false
             })
             const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
+            let result = []
             if (type.refCode == 'jsek_teachingResources') {
+              this.findChildIds(list, result)
               this.setData({
                 teach: list,
-                loading: false
+                loading: false,
+                openTeachids: result
               })
-              this.findChildIds(this.data.teach, this.data.openTeachids = [])
+              console.log('鏁欏璧勬簮', this.data.teach, this.data.applyState);
             } 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)
+              // res.datas.cmsDatas[0].datas.forEach(item => {
+              //   item.checked = false
+              // })
+              // const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
+              this.findChildIds(list, result)
               this.setData({
                 learn: list,
-                loading: false
+                loading: false,
+                openLearnids: result
               })
-              this.findChildIds(this.data.learn, this.data.openLearnids = [])
             }
           } else {
             // 鏃犳暟鎹�
@@ -654,7 +706,8 @@
         isDownload: [],
         jsek_resourceBrief: [],
         jsek_link: [],
-        accessType: []
+        accessType: [],
+        learnSelectType: []
       },
       pading: {
         start: 0,
@@ -697,12 +750,12 @@
     for (let i = 0; i < data.length; i++) {
       if (index < 3) {
         const item = data[i]
-        if (item.childrenFolderCount > 0) {
+        if (item.children && item.children.length > 0) {
           result.push(item.id)
           for (let j = 0; j < item.children.length; j++) {
             if (index < 3) {
               const childrenItme = item.children[j]
-              if (item.childrenCount > 0) {
+              if (item.children && item.children.length > 0) {
                 result.push(childrenItme.id)
                 index += 1
               }
@@ -710,7 +763,7 @@
               break
             }
           }
-        } else if (item.childrenCount > 0) {
+        } else if (item.children && item.children.length > 0) {
           result.push(item.id)
           index += 1
         }
@@ -753,13 +806,11 @@
       console.log(determine);
       if (!determine) {
         let query = {
-          requests: [
-            {
-              saleMethodId: this.data.selectedIds,
-              storeEventId: null,
-              agentCode: '鐢靛瓙涔�'
-            }
-          ]
+          requests: [{
+            saleMethodId: this.data.selectedIds,
+            storeEventId: null,
+            agentCode: '鐢靛瓙涔�'
+          }]
         }
         const addRes = app.MG.store.addShoppingCart(query)
         this.showSuccessToast()
@@ -768,8 +819,8 @@
         Toast({
           context: this,
           selector: '#t-toast',
-          message: '宸叉坊鍔�',
-          theme: 'success',
+          message: '璇ヤ功宸插湪璐墿杞︼紝璇峰嬁閲嶅娣诲姞',
+          theme: 'warning',
           direction: 'column',
         });
       }
@@ -794,19 +845,16 @@
     });
   },
 
-
-
   async buyBook() {
+    console.log(this.data.bookItemDetail.defaultSaleMethodId, 'this.data.bookItemDetail.defaultSaleMethodId');
     if (!this.data.expire) {
       let bookOrdersId = ''
       let query = {
         remarks: '鐢靛瓙涔�',
-        requests: [
-          {
-            saleMethodId: this.data.bookItemDetail.defaultSaleMethodId ? this.data.bookItemDetail.defaultSaleMethodId : this.data.bookDetail.defaultSaleMethodId,
-            count: 1
-          }
-        ]
+        requests: [{
+          saleMethodId: this.data.bookItemDetail.defaultSaleMethodId ? this.data.bookItemDetail.defaultSaleMethodId : this.data.bookDetail.defaultSaleMethodId,
+          count: 1
+        }]
       }
       // 鍙戣捣璁㈠崟鍒濆鍖栬姹傚苟绛夊緟缁撴灉
       const res = await app.MG.store.initOrder(query)
@@ -832,7 +880,7 @@
   },
 
   // 鑾峰彇鏁欏璧勬簮涓嬭浇鏄惁鐢宠閫氳繃
-  getApplyInfo(id) {
+  async getApplyInfo(id) {
     // 鑾峰彇褰撳墠鏃堕棿
     const currentDate = new Date()
     let query = {
@@ -845,7 +893,7 @@
       appRefCode: app.config.appRefCode,
       topicIdOrRefCode: 'productDownLoad'
     }
-    app.MG.ugc.getTopicMessageList(query).then((res) => {
+    await app.MG.ugc.getTopicMessageList(query).then((res) => {
       const applyResource = res.datas.find((item) => {
         let content = []
         try {
@@ -901,13 +949,23 @@
       }
     })
     this.setData({
-      applyResourceLoading: false
+      applyResourceState: false,
     })
+    wx.hideLoading()
   },
   // 鐢宠鏁欏璧勬簮
   applyResource() {
+    if (this.data.applyResourceState) {
+      return wx.showToast({
+        icon: 'error',
+        title: '璇峰嬁閲嶅鐐瑰嚮',
+      })
+    }
     this.setData({
-      applyResourceLoading: true
+      applyResourceState: true
+    })
+    wx.showLoading({
+      title: '鍔犺浇涓�',
     })
     // let role = userStore.userInfo ? userStore.userInfo.role : null
     // if (role) {
@@ -920,22 +978,20 @@
       cmsTypeRefCode: '',
       newDataListRequest: [],
       name: this.data.bookDetail.name, // name涓虹敵璇风殑涔︽湰鍚嶇О
-      content: JSON.stringify([
-        {
-          name: this.data.bookDetail.name,
-          id: this.data.bookDetail.id,
-          // defaultSaleMethodId: bookData.value.defaultSaleMethodId,
-          icon: this.data.bookDetail.icon
-        }
-      ])
+      content: JSON.stringify([{
+        name: this.data.bookDetail.name,
+        id: this.data.bookDetail.id,
+        // defaultSaleMethodId: bookData.value.defaultSaleMethodId,
+        icon: this.data.bookDetail.icon
+      }])
     }
-    app.MG.ugc.newTopicMessage(query).then((res) => {
+    app.MG.ugc.newTopicMessage(query).then(async (res) => {
       if (res) {
         wx.showToast({
           title: '鐢宠宸叉彁浜わ紝璇峰緟瀹℃牳閫氳繃鍚庝笅杞�',
         })
       }
-      this.getApplyInfo(this.data.bookDetail.id)
+      await this.getApplyInfo(this.data.bookDetail.id)
     })
     //   } else {
     //     ElMessageBox.confirm('璇峰厛杩涜鏁欏笀璁よ瘉锛�', '灏婃暚鐨勭敤鎴凤紝鎮ㄥソ锛�', {
@@ -1278,9 +1334,9 @@
         if (new RegExp('(' + k + ')').test(fmt)) {
           fmt = fmt.replace(
             RegExp.$1,
-            RegExp.$1.length == 1
-              ? (o)[k]
-              : ('00' + (o)[k]).substr(('' + (o)[k]).length)
+            RegExp.$1.length == 1 ?
+            (o)[k] :
+            ('00' + (o)[k]).substr(('' + (o)[k]).length)
           )
         }
       }
@@ -1301,7 +1357,6 @@
         keys: [this.data.bookId]
       })
       .then((res) => {
-        console.log(JSON.parse(res[0].value));
         if (res && res.length) {
           const mock = JSON.parse(res[0].value)
           mock.forEach(item => {
@@ -1334,12 +1389,10 @@
     try {
       let query = {
         remarks: '缁勫嵎',
-        requests: [
-          {
-            saleMethodId: this.data.mockData.id,
-            count: 1
-          }
-        ]
+        requests: [{
+          saleMethodId: this.data.mockData.id,
+          count: 1
+        }]
       }
       if (this.data.flag) {
         this.setData({
@@ -1354,7 +1407,9 @@
       } else {
         // 0鍏冪洿鎺ラ鍙�
         // 纭璁㈠崟
-        const confirmOrderRes = await app.MG.store.confirmOrder({ orderNum: res.orderNumber })
+        const confirmOrderRes = await app.MG.store.confirmOrder({
+          orderNum: res.orderNumber
+        })
         if (confirmOrderRes) {
           wx.showToast({
             icon: "success",
@@ -1374,36 +1429,39 @@
   recordBuyMock() {
     const num = this.data.mockData.mockList.length
     const id = tool.uuid(8)
-    const createDate = new Date().getTime()
+    const createDate = this.DateFormat(new Date().getTime(), 'yyyy-MM-dd')
     const mockList = this.data.mockData.mockList
-    mockList.push({ id, createDate, name: `绗�${num + 1}濂楄瘯鍗穈, state: '0' })
+    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)
-        }
-      ]
+      setKeyRequests: [{
+        domain: 'mockData',
+        key: this.data.bookDetail.id + '',
+        value: JSON.stringify(this.data.mockData.mockList)
+      }]
     })
   },
   // 搴曢儴璐拱鎸夐挳
   buyBtn() {
-    if (this.data.tabValue == 'brief') {
+    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 if (this.data.tabValue == 'questionBank') {
-      this.buyMock()
-    } else {
-      console.log(this.data.tabValue);
-    }
+    // 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);
+    // }
   },
 
   goRead() {
@@ -1426,6 +1484,7 @@
   appplyElectronicBook() {
     console.log(this.data.bookDetail)
     if (this.data.bookDetail.isApplyBook == 2 || this.data.bookDetail.isApplyBook == 4) {
+
       let role = this.data.userInfo != null ? this.data.userInfo.role : null
       if (role) {
         if (role == 'Teacher') {
@@ -1447,12 +1506,17 @@
                 wx.navigateTo({
                   url: "/packageDomain/pages/teacherCertification/index",
                 });
-              } else if (res.cancel) {
-              }
+              } else if (res.cancel) {}
             }
           })
         }
       }
+    } else {
+      wx.showToast({
+        title: "璇ヤ功涓嶈兘鐢宠鐢靛瓙鏍蜂功",
+        icon: 'none',
+        duration: 1000,
+      })
     }
   },
   //鐢宠绾歌川鏍蜂功
@@ -1471,12 +1535,17 @@
                 wx.navigateTo({
                   url: "/packageDomain/pages/teacherCertification/index",
                 });
-              } else if (res.cancel) {
-              }
+              } else if (res.cancel) {}
             }
           })
         }
       }
+    } else {
+      wx.showToast({
+        title: "璇ヤ功涓嶈兘鐢宠绾歌川鏍蜂功",
+        icon: 'none',
+        duration: 1000,
+      })
     }
   },
   //鑾峰彇褰撳墠宸茬敵璇锋鏁帮紙绾歌川锛�
@@ -1695,5 +1764,29 @@
       url: "/packageDomain/pages/sampleBookList/applicationForm/index",
     });
   },
-
-})
+  handleTree() {
+    // const child = this.selectComponent('#teach-tree')
+    let tree
+    // let openIds = child.data.openIds
+    if (this.data.tabValue == 'jsek_teachingResources') {
+      tree = this.data.teach
+    } else {
+      tree = this.data.learn
+    }
+    for (let index = 0; index < tree.length; index++) {
+      const item = tree[index];
+      if (item.children && item.children.length > 0) {
+        const num = this.data.openTeachids.findIndex(citem => item.id == citem)
+        if (num >= 0) {
+          item.open = true
+        } else {
+          item.open = false
+        }
+        this.handleTree(item.children)
+      }
+    }
+    this.setData({
+      teach: tree
+    })
+  },
+})
\ No newline at end of file

--
Gitblit v1.9.1