From 4c46ea24641b5c1e18c55eb86477d0e0bc444580 Mon Sep 17 00:00:00 2001
From: yiming <m13691596795@163.com>
Date: 星期二, 18 六月 2024 17:52:47 +0800
Subject: [PATCH] 数字课程详情

---
 pages/digitalCourses/digitalCoursesDetails/index.js |  297 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 297 insertions(+), 0 deletions(-)

diff --git a/pages/digitalCourses/digitalCoursesDetails/index.js b/pages/digitalCourses/digitalCoursesDetails/index.js
index 423eb66..5444f63 100644
--- a/pages/digitalCourses/digitalCoursesDetails/index.js
+++ b/pages/digitalCourses/digitalCoursesDetails/index.js
@@ -1,18 +1,104 @@
 // pages/digitalCourses/digitalCoursesDetails/index.js
+const app = getApp()
+import Toast from "tdesign-miniprogram/toast";
 Page({
 
   /**
    * 椤甸潰鐨勫垵濮嬫暟鎹�
    */
   data: {
+    scrollJudge: true,
+    loading: true,
+    digitalsData: [],
+    tabValue: 0,
+    learnResourceIcon: {
+      name: "/static/images/digitalTextbooks/shengshu-t@2x.png",
+    },
+    learnResourceClickIcon: {
+      name: "/static/images/digitalTextbooks/zhengshu-t-click@3x.png",
+    },
+    briefIcon: {
+      name: "/static/images/digitalTextbooks/jibenxinxi-t@2x.png",
+    },
+    briefIconClick: {
+      name: "/static/images/digitalTextbooks/jibenxinxi-t-click@3x.png",
+    },
+    courseLearning: {
+      name: "/static/images/digitalCourses/jiaoxueziyuan@2x.png"
+    },
+    courseLearningClick: {
+      name: "/static/images/digitalCourses/jiaoxueziyuan.png"
+    },
+    learningNotes: {
+      name: "/static/images/digitalCourses/biji锛廼con@2x.png"
+    },
+    learningNotesClick: {
+      name: "/static/images/bookService/detail/biji-click-icon.png",
+    },
+
+    onlineQuestioning: {
+      name: "/static/images/digitalCourses/tiwen@2x.png"
+    },
+    onlineQuestioningClick: {
+      name: "/static/images/digitalCourses/tiwen-click@2x.png"
+    },
+
+    dialogBox: false
 
   },
+  formatDate(dateString) {
+    if (!dateString) {
+      return "";
+    }
+    const match = dateString.match(
+      /^(\d{4})\/(\d{1,2})\/(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/
+    );
+    if (!match) {
+      throw new Error("Invalid date format");
+    }
 
+    const [, year, month, day, hours, minutes, seconds] = match;
+    const date = new Date(
+      parseInt(year, 10),
+      parseInt(month, 10) - 1,
+      parseInt(day, 10),
+      parseInt(hours, 10),
+      parseInt(minutes, 10),
+      parseInt(seconds, 10)
+    );
+
+    if (isNaN(date.getTime())) {
+      throw new Error("Invalid date");
+    }
+
+    // 鐢变簬灏忕▼搴忕幆澧冨彲鑳戒笉鏀寔 Intl.DateTimeFormat锛屾垜浠娇鐢ㄧ畝鍖栫殑鏍煎紡鍖栨柟娉�
+    const formatted = `${year}骞�${this.formatMonth(month)}`;
+    return formatted;
+  },
+  formatMonth(month) {
+    const months = [
+      "1鏈�",
+      "2鏈�",
+      "3鏈�",
+      "4鏈�",
+      "5鏈�",
+      "6鏈�",
+      "7鏈�",
+      "8鏈�",
+      "9鏈�",
+      "10鏈�",
+      "11鏈�",
+      "12鏈�",
+    ];
+    return months[parseInt(month, 10) - 1];
+  },
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
     console.log(options);
+    this.digitalCoursesDetailsGet(options.id)
+
   },
 
   /**
@@ -62,5 +148,216 @@
    */
   onShareAppMessage() {
 
+  },
+  digitalCoursesDetailsGet(digitalTextId) {
+
+    let query = {
+      path: '*',
+      queryType: '*',
+      productId: digitalTextId,
+      storeInfo: 'jsek_digitalCourses',
+      coverSize: {
+        height: 300
+      },
+      fields: {
+        seriesName: [],
+        author: [],
+        isbn: [],
+        publicationDate: [],
+        bookClassification: [],
+        paperPrice: [],
+        JDLink: [],
+        tmallLink: [],
+        dangdangLink: [],
+        weidianLink: [],
+        content: [],
+        authorIntroduction: [],
+        isApplyBook: [],
+        isSell: [],
+        pdf: [],
+        protectedEpub: [],
+        probationPage: [], //pdf璇曡椤垫暟
+        freeEpubPage: [],
+        courseLeader: [],
+        affiliatedUnit: [],
+        publishingUnit: [],
+        classHours: [],
+        productLinkPath: []
+        //epub璇曡鐧惧垎姣�
+      }
+    }
+    app.MG.store.getProductDetail(query).then(res => {
+      console.log(res);
+      res.datas.publicationDate = this.formatDate(res.datas.publicationDate)
+      res.datas.price = res.datas.price.toFixed(2)
+
+      wx.setNavigationBarTitle({
+        title: res.datas.name,
+      })
+
+      this.setData({
+        digitalsData: res.datas,
+        loading: false
+      })
+    })
+  },
+  onTabsChange(event) {
+
+    const value = event.detail.value
+    this.setData({
+      tabValue: value
+    })
+    console.log(this.data.tabValue);
+  },
+
+
+  // 鍥句功娣诲姞璐墿杞�
+  async addBookShopcCar() {
+    if (!this.data.expire) {
+      const shoppingCartGetId = [];
+      let query = {
+        start: 0,
+        size: 9999,
+        filterList: [],
+        searchList: [],
+      };
+      const res = await app.MG.store.getShoppingCartProductList(query);
+      res.datas.forEach((item) => {
+        shoppingCartGetId.push(item.saleMethod.id);
+      });
+      const determine = shoppingCartGetId.some(
+        (item) => item == this.data.digitalsData.defaultSaleMethodId
+      );
+      if (!determine) {
+        let query = {
+          requests: [{
+            saleMethodId: this.data.digitalsData.defaultSaleMethodId,
+            storeEventId: null,
+            agentCode: "鐢靛瓙涔�",
+          }, ],
+        };
+        const addRes = app.MG.store.addShoppingCart(query);
+        this.showSuccessToast();
+      } else {
+        Toast({
+          context: this,
+          selector: "#t-toast",
+          message: "璇ヤ功宸插湪璐墿杞︼紝璇峰嬁閲嶅娣诲姞",
+          theme: "warning",
+          direction: "column",
+        });
+      }
+    } else {
+      wx.showToast({
+        title: "鍟嗗搧涓嶅湪鏈夋晥鏈�",
+        icon: "none",
+        duration: 1000,
+      });
+    }
+  },
+  showSuccessToast() {
+    Toast({
+      context: this,
+      selector: "#t-toast",
+      message: "娣诲姞鎴愬姛",
+      theme: "success",
+      direction: "column",
+    });
+  },
+
+  //璐拱鎸夐挳
+
+  async buyBtn() {
+    if (!this.data.expire) {
+      let bookOrdersId = "";
+      let query = {
+        remarks: "鐢靛瓙涔�",
+        requests: [{
+          saleMethodId: this.data.digitalsData.defaultSaleMethodId,
+          count: 1,
+        }, ],
+      };
+      // 鍙戣捣璁㈠崟鍒濆鍖栬姹傚苟绛夊緟缁撴灉
+      const res = await app.MG.store.initOrder(query);
+      // 鑾峰彇璁㈠崟鍙峰苟璧嬪�肩粰 orderNumber.value
+      console.log(res, 'res456');
+      bookOrdersId = res.orderNumber;
+      // 妫�鏌ヨ鍗曞彿鏄惁瀛樺湪
+      if (bookOrdersId) {
+        if (this.data.digitalsData.price == "0.00") {
+          app.MG.store
+            .confirmOrder({
+              orderNum: bookOrdersId,
+            })
+            .then((res) => {
+              this.digitalTextbooksDetailsGet(this.data.digitalTextId)
+              if (res) {
+                wx.showToast({
+                  title: "棰嗗彇鎴愬姛",
+                  icon: "none",
+                  duration: 1000,
+                });
+                this.getBookInfo(this.data.bookDetail.id);
+              }
+            });
+        } else {
+          const url = "/pages/cart/paymentPage/index?orderNumber=" + bookOrdersId + '&onNorderSaleMethod=' + res.saleMethodLinks[0].orderSaleMethod.id;
+          wx.navigateTo({
+            url,
+          });
+        }
+      } else {
+        console.log(222);
+      }
+    } else {
+      wx.showToast({
+        title: "鍟嗗搧涓嶅湪鏈夋晥鏈�",
+        icon: "none",
+        duration: 1000,
+      });
+    }
+  },
+  showDialog(e) {
+    const {
+      key
+    } = e.currentTarget.dataset;
+    this.setData({
+      [key]: true,
+      dialogKey: key
+    });
+  },
+
+  closeDialog() {
+    const {
+      dialogKey
+    } = this.data;
+    this.setData({
+      [dialogKey]: false
+    });
+  },
+  onCertificate() {
+
+
+    var page = getCurrentPages().pop(); // 鑾峰彇褰撳墠椤甸潰瀹炰緥
+    page.setData({
+      // 鍔ㄦ�佽缃姝㈡粴鍔ㄧ殑鏍峰紡
+      disableScrollStyle: 'overflow: hidden;'
+    });
+    this.setData({
+      dialogBox: true,
+      scrollJudge: ''
+    })
+  },
+  closeDialog() {
+    this.setData({
+      dialogBox: false,
+      scrollJudge: true
+    })
+  },
+  confirmM() {
+    this.setData({
+      dialogBox: false,
+      scrollJudge: true
+    })
   }
 })
\ No newline at end of file

--
Gitblit v1.9.1