From cd98c69ff835643f518337ee9ab532885c647efb Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期五, 15 三月 2024 18:48:39 +0800
Subject: [PATCH] 合并代码

---
 pages/bookServices/detail/index.js |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 106 insertions(+), 5 deletions(-)

diff --git a/pages/bookServices/detail/index.js b/pages/bookServices/detail/index.js
index 6e744f6..0a17a1e 100644
--- a/pages/bookServices/detail/index.js
+++ b/pages/bookServices/detail/index.js
@@ -42,7 +42,14 @@
     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) {
@@ -71,10 +78,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()
     }
   },
 
@@ -179,6 +187,11 @@
   },
   // 鑾峰彇鍥句功璇︽儏
   getBookInfo(id) {
+    this.setData({
+      "mockData'.id": 0,
+      "mockData.price": 0,
+      "mockData.count": 0
+    })
     const query = {
       path: '*',
       queryType: '*',
@@ -214,7 +227,7 @@
       },
     };
     app.MG.store.getProductDetail(query).then(async (res) => {
-
+      console.log(res.datas);
       this.setData({
         bookDetail: res.datas,
         cmsDatas: res.datas.cmsDatas[0].datas,
@@ -224,6 +237,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,
@@ -232,6 +268,7 @@
         'bookDetail.paperPrice': this.numFormat(this.data.bookDetail.paperPrice),
       });
     });
+
   },
   // 鑾峰彇鍥句功鍒嗙被
   async getBookClass(iconType, classType) {
@@ -298,8 +335,8 @@
   goShop(e) {
     const { link } = e.currentTarget.dataset;
     wx.navigateTo({
-      url: link,
-    });
+      url: `/pages/bookServices/webpage/index?url=${link}`,
+    })
   },
   onTabsChange(e) {
     this.setData({
@@ -1014,5 +1051,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