From 81b30e7fb0763bce403431f0c1f64d5a9e36dfb2 Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期三, 20 三月 2024 15:42:13 +0800
Subject: [PATCH] Merge refs/remotes/origin/master into refs/heads/master

---
 packageBookService/pages/bookServices/detail/index.js |  105 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 96 insertions(+), 9 deletions(-)

diff --git a/packageBookService/pages/bookServices/detail/index.js b/packageBookService/pages/bookServices/detail/index.js
index 0bc5d6c..77bf47c 100644
--- a/packageBookService/pages/bookServices/detail/index.js
+++ b/packageBookService/pages/bookServices/detail/index.js
@@ -1,6 +1,7 @@
 // pages/bookServices/detail/index.js
 import Message from 'tdesign-miniprogram/message/index.js';
 import Toast from 'tdesign-miniprogram/toast';
+import tool from '../../../../assets/js/toolClass'
 const app = getApp();
 Page({
   /**
@@ -49,7 +50,8 @@
       useCount: 0, // 缁勪欢宸蹭娇鐢ㄦ鏁�
       residue: 0, // 缁勫嵎鍓╀綑娆℃暟
       mockList: [] // 鐢ㄦ埛缁勫嵎鎻愪氦淇℃伅
-    }
+    },
+    flag: true
   },
 
 
@@ -415,20 +417,22 @@
         //鏁欏璧勬簮 浜戝涔�
         if (type.refCode == 'jsek_teachingResources' || type.refCode == 'jsek_cloudLearning') {
           if (res.datas.cmsDatas[0].datas.length > 0) {
+            res.datas.cmsDatas[0].datas.forEach(item => {
+              item.checked = false
+            })
+            const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
             if (type.refCode == 'jsek_teachingResources') {
-              res.datas.cmsDatas[0].datas.forEach(item => {
-                item.checked = false
-              })
-              const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
-
-              console.log(list, 'list');
               this.setData({
                 teach: list,
                 loading: false
               })
               this.findChildIds(this.data.teach, this.data.openTeachids = [])
             } else if (type.refCode == 'jsek_cloudLearning') {
-              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)
+              console.log(list, 'currentlist');
               this.setData({
                 learn: list,
                 loading: false
@@ -513,6 +517,7 @@
       if (this.data.tabValue == 'jsek_teachingResources') {
         item.checked = false
       } else if (this.data.tabValue == 'jsek_cloudLearning') {
+        item.checked = false
         item.isbuy = this.resourceIsBuy(item)
         item.isShopCar = this.isShoppingCart(item)
       }
@@ -1115,6 +1120,88 @@
           })
         }
       })
-  }
+  },
+  // 璐拱缁勫嵎
+  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
+        })
+        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)
+    }
+  },
+  // 璁板綍璐拱缁勫嵎鏃堕棿
+  recordBuyMock() {
+    const num = this.data.mockData.mockList.length
+    const id = tool.uuid(8)
+    const createDate = new Date().getTime()
+    const mockList = this.data.mockData.mockList
+    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)
+        }
+      ]
+    })
+  },
+  // 搴曢儴璐拱鎸夐挳
+  buyBtn() {
+    if (this.data.tabValue == 'brief') {
+      this.buyBook()
+    }
+    else if (this.data.tabValue == 'jsek_cloudLearning') {
+      console.log('浜戝涔�');
+    } else if (this.data.tabValue == 'questionBank') {
+      this.buyMock()
+    } else {
+      console.log(this.data.tabValue);
+    }
+  }
 })

--
Gitblit v1.9.1