From 3f1ea0a8e4bb02bf7544df8660b15cfa69d6b84a Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期五, 15 三月 2024 18:54:04 +0800
Subject: [PATCH] Merge refs/remotes/origin/master into refs/heads/master

---
 pages/bookServices/detail/index.js |  195 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 186 insertions(+), 9 deletions(-)

diff --git a/pages/bookServices/detail/index.js b/pages/bookServices/detail/index.js
index 396240d..406ce39 100644
--- a/pages/bookServices/detail/index.js
+++ b/pages/bookServices/detail/index.js
@@ -1,5 +1,6 @@
 // pages/bookServices/detail/index.js
 import Message from 'tdesign-miniprogram/message/index.js';
+import Toast from 'tdesign-miniprogram/toast/index';
 const app = getApp();
 Page({
   /**
@@ -41,7 +42,16 @@
     loading: false,
     isShowTeachDownload: false,  // 鎻愮ずPC涓嬭浇寮圭獥鐘舵��
     confirmBtn: { content: '鎴戠煡閬撲簡', variant: 'base' },
+    mockData: {
+      id: 0, // 閿�鍞甶d
+      price: 0, // 鍞环
+      count: 0, // 缁勫嵎宸茶喘涔版鏁�
+      useCount: 0, // 缁勪欢宸蹭娇鐢ㄦ鏁�
+      residue: 0, // 缁勫嵎鍓╀綑娆℃暟
+      mockList: [] // 鐢ㄦ埛缁勫嵎鎻愪氦淇℃伅
+    }
   },
+
 
   resetTree: function (e) {
     this.setData({
@@ -69,10 +79,11 @@
     });
     this.getBookInfo(options.id);
     this.getResourceClass() // 鑾峰彇璧勬簮鎵�灞炲垎绫�
-    this.getApplyInfo(options.id)
     const token = wx.getStorageSync('jsek-token')
     if (token) {
       this.getShoppingCartProductGet()
+      this.getApplyInfo(options.id)
+      this.getMockData()
     }
   },
 
@@ -177,6 +188,11 @@
   },
   // 鑾峰彇鍥句功璇︽儏
   getBookInfo(id) {
+    this.setData({
+      "mockData'.id": 0,
+      "mockData.price": 0,
+      "mockData.count": 0
+    })
     const query = {
       path: '*',
       queryType: '*',
@@ -212,7 +228,7 @@
       },
     };
     app.MG.store.getProductDetail(query).then(async (res) => {
-
+      console.log(res.datas);
       this.setData({
         bookDetail: res.datas,
         cmsDatas: res.datas.cmsDatas[0].datas,
@@ -222,6 +238,29 @@
       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)
+      // 鑾峰彇缁勫嵎閿�鍞甶d
+      if (res.datas.saleMethod && res.datas.saleMethod.length) {
+        res.datas.saleMethod.forEach((item) => {
+          if (item.SaleType == 'combinationTestPaper') {
+            this.setData({
+              'mockData.id': item.Id,
+              'mockData.price': item.Price
+            })
+          }
+        })
+      }
+      // 鑾峰彇缁勫嵎宸茶喘涔版鏁�
+      if (res.datas.purchasedSaleMethodIdList && res.datas.purchasedSaleMethodIdList.length) {
+        if (this.data.mockData.id) {
+          let count = res.datas.purchasedSaleMethodIdList.filter(
+            (item) => item == this.data.mockData.id
+          ).length
+          this.setData({
+            'mockData.count': count
+          })
+        }
+      }
+      console.log('缁勫嵎淇℃伅', this.data.mockData);
       this.setData({
         'bookDetail.publicationDate': this.formatDate(this.data.bookDetail.publicationDate),
         'bookDetail.class': className,
@@ -230,6 +269,7 @@
         'bookDetail.paperPrice': this.numFormat(this.data.bookDetail.paperPrice),
       });
     });
+
   },
   // 鑾峰彇鍥句功鍒嗙被
   async getBookClass(iconType, classType) {
@@ -296,8 +336,8 @@
   goShop(e) {
     const { link } = e.currentTarget.dataset;
     wx.navigateTo({
-      url: link,
-    });
+      url: `/pages/bookServices/webpage/index?url=${link}`,
+    })
   },
   onTabsChange(e) {
     this.setData({
@@ -380,6 +420,8 @@
                 item.checked = false
               })
               const list = await this.getAllResource(res.datas.cmsDatas[0].datas)
+
+              console.log(list, 'list');
               this.setData({
                 teach: list,
                 loading: false
@@ -507,18 +549,89 @@
   },
 
   // 鍥句功娣诲姞璐墿杞�
-  addBookShopcCar() {
+  async addBookShopcCar() {
+    const shoppingCartGetId = []
+
     let query = {
+      start: 0,
+      size: 999,
+      filterList: [],
+      searchList: []
+    }
+    const res = await app.MG.store.getShoppingCartProductList(query)
+    res.datas.forEach((item) => {
+      shoppingCartGetId.push(item.saleMethod.id)
+    })
+    console.log(shoppingCartGetId, 'shoppingCartGetId');
+    console.log(this.data.bookDetail.defaultSaleMethodId, 'this.data.bookDetail.defaultSaleMethodId');
+    const determine = shoppingCartGetId.some((item) => item == this.data.bookDetail.defaultSaleMethodId)
+    console.log(determine);
+
+    if (!determine) {
+      let query = {
+        requests: [
+          {
+            saleMethodId: this.data.bookDetail.defaultSaleMethodId,
+            storeEventId: null,
+            agentCode: '鐢靛瓙涔�'
+          }
+        ]
+      }
+      const addRes = app.MG.store.addShoppingCart(query)
+      this.showSuccessToast()
+
+    } else {
+      Toast({
+        context: this,
+        selector: '#t-toast',
+        message: '宸叉坊鍔�',
+        theme: 'success',
+        direction: 'column',
+      });
+    }
+
+  },
+
+  showSuccessToast() {
+    Toast({
+      context: this,
+      selector: '#t-toast',
+      message: '娣诲姞鎴愬姛',
+      theme: 'success',
+      direction: 'column',
+    });
+  },
+
+
+
+  async buyBook() {
+    let bookOrdersId = ''
+    let query = {
+      remarks: '鐢靛瓙涔�',
       requests: [
         {
           saleMethodId: this.data.bookDetail.defaultSaleMethodId,
-          storeEventId: null,
-          agentCode: '鐢靛瓙涔�'
+          count: 1
         }
       ]
     }
-    const addRes = app.MG.store.addShoppingCart(query)
+    // 鍙戣捣璁㈠崟鍒濆鍖栬姹傚苟绛夊緟缁撴灉
+    const res = await app.MG.store.initOrder(query)
+    // 鑾峰彇璁㈠崟鍙峰苟璧嬪�肩粰 orderNumber.value
+    bookOrdersId = res.orderNumber
+    console.log(bookOrdersId);
+    // 妫�鏌ヨ鍗曞彿鏄惁瀛樺湪
+    if (bookOrdersId) {
+      const url = '/pages/cart/paymentPage/index?orderNumber=' + bookOrdersId
+      wx.navigateTo({
+        url
+      })
+    } else {
+      console.log(222);
+    }
+
   },
+
   // 鑾峰彇鏁欏璧勬簮涓嬭浇鏄惁鐢宠閫氳繃
   getApplyInfo(id) {
     // 鑾峰彇褰撳墠鏃堕棿
@@ -908,7 +1021,7 @@
     if (initOrderRes.orderNumber) {
       // bookService: orderNumber.value,  灏戜紶杩欎釜 锛屾殏鏃朵笉鐭ラ亾鏈変粈涔堢敤
       wx.navigateTo({
-        url: `/pages/cart/paymentPage/index?&bookId=${this.data.bookDetail.id}&bookName=${this.data.bookDetail.name}&orderNum=${initOrderRes.orderNumber}`,
+        url: `/pages/cart/paymentPage/index?&bookId=${this.data.bookDetail.id}&bookName=${this.data.bookDetail.name}&orderNumber=${initOrderRes.orderNumber}`,
       })
     } else {
       // 璁㈠崟鍙蜂笉瀛樺湪锛屾樉绀鸿鍛婃秷鎭�
@@ -939,5 +1052,69 @@
   handleTrue() {
     // findAndUpdateItemsByIds(this.date.)
   },
+  // 缁勫嵎鏍煎紡鍖栨棩鏈熸樉绀�
+  DateFormat(date, fmt) {
+    if (date && fmt) {
+      let _date = new Date(date)
+      var o = {
+        'M+': _date.getMonth() + 1, //鏈堜唤
+        'd+': _date.getDate(), //鏃�
+        'h+': _date.getHours(), //灏忔椂
+        'm+': _date.getMinutes(), //鍒�
+        's+': _date.getSeconds(), //绉�
+        'q+': Math.floor((_date.getMonth() + 3) / 3), //瀛e害
+        S: _date.getMilliseconds() //姣
+      }
+      if (/(y+)/.test(fmt)) {
+        fmt = fmt.replace(RegExp.$1, (_date.getFullYear() + '').substr(4 - RegExp.$1.length))
+      }
+      for (var k in o) {
+        if (new RegExp('(' + k + ')').test(fmt)) {
+          fmt = fmt.replace(
+            RegExp.$1,
+            RegExp.$1.length == 1
+              ? (o)[k]
+              : ('00' + (o)[k]).substr(('' + (o)[k]).length)
+          )
+        }
+      }
+      return fmt
+    } else {
+      return ''
+    }
+  },
+  // 鑾峰彇缁勫嵎绛旈鏁版嵁
+  getMockData() {
+    this.setData({
+      'mockData.useCount': 0,
+      'mockData.mockList': []
+    })
+    app.MG.identity
+      .getUserKey({
+        domain: 'mockData',
+        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 => {
+            item.createDate = this.DateFormat(item.createDate, 'yyyy-MM-dd')
+          })
+          this.setData({
+            'mockData.mockList': mock
+          })
+          // 缁勫嵎宸蹭娇鐢ㄦ鏁�
+          res.forEach((item) => {
+            // 宸茬粡鏈夌瓟棰樺垎鏁扮瓑鏁版嵁锛岃瘉鏄庣粍鍗峰凡缁忎娇鐢ㄥ畬姣�
+            if (item.resultData) {
+              this.setData({
+                'mockData.useCount': this.data.mockData.useCount + 1
+              })
+            }
+          })
+        }
+      })
+  }
 
 })

--
Gitblit v1.9.1