闫增涛
2025-03-31 04c7b0163caeae4ab1c5da62e301fa993101cfad
packageBookService/pages/bookServices/detail/components/testResource/testResource.js
@@ -1,119 +1,194 @@
// pages/bookServices/detail/components/testResource/testResource.js
const app = getApp()
import {
  loginInfo
} from "../../../../../../assets/js/login";
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isBuyBank: {
      type: Boolean
    },
    isShoppingBank: {
      type: Boolean
    },
    bankSaleData: {
      type: Object
    },
    list: {
      type: Array,
      value: []
      value: [],
    },
    bookInfo: {
      type: Object,
      value: "",
    },
    tab: {
      type: String,
      value: "",
    },
    openIds: {
      type: Array,
      value: [],
    },
    mockData: {
      type: Object,
      value: {}
    }
      value: {},
    },
    storeInfo: {
      type: String,
      value: "",
    },
    jslx: {
      type: Boolean,
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    selectBtn: 'test',  // test  mock
    radioItem: 'test',
    selectBtn: "test", // test  mock
    radioItem: "test",
    loading: false,
  },
  ready() {},
  /**
   * 组件的方法列表
   */
  methods: {
    async goTest(e) {
      const value = e.currentTarget.dataset.value
      const token = wx.getStorageSync('jsek-token')
      if (!token) {
        return wx.getUserProfile({
          desc: '用户登录',
          success: (res) => {
            console.log(res);
          }
        })
      }
      wx.showLoading({
        title: '加载中',
      })
      // 获取章节下是否有题目
      let idPathList = []
      let query = {
        path: '*',
        queryType: '*',
        productId: this.properties.bookInfo.id,
        cmsPath: value.productLinkPath,
        pading: {
          start: 0,
          size: 999
        }
      }
      if (value.childrenFolderCount == 0) {
        wx.hideLoading()
        return wx.showToast({
          icon: "error",
          title: '暂无数据',
        })
      } else {
        const res = await app.MG.store.getProductDetail(query)
        res.datas.cmsDatas[0].datas.forEach((item) => {
          idPathList.push({
            id: item.id,
            name: item.name,
            productLinkPath: item.productLinkPath,
            type: item.type
          })
        })
      }
      wx.hideLoading()
      wx.navigateTo({
        url: `/packageBookService/pages/bookServices/examination/examination?bookId=${this.properties.bookInfo.id}&productLinkPath=${value.productLinkPath}&rootCmsItemId=${this.properties.bookInfo.rootCmsItemId}&idPathList=${JSON.stringify(idPathList)}&answerTitle=${value.name}&answerType=${'option'}`,
    testBtn() {
      this.setData({
        radioItem: 'test'
      })
    },
    goMycollect(e) {
      const answertype = e.currentTarget.dataset.answertype
      const token = wx.getStorageSync('jsek-token')
    mockBtn() {
      this.setData({
        radioItem: 'mock'
      })
    },
    async goTest(e) {
      const value = e.detail.value.item;
      const token = wx.getStorageSync("jsek-token");
      if (!token) {
        return wx.getUserProfile({
          desc: '用户登录',
          desc: "用户登录",
          success: (res) => {
            console.log(res);
          }
          },
        });
      }
      if (!this.data.isBuyBank) return wx.showToast({
        icon: 'error',
        title: '请先购买题库',
      })
      wx.showLoading({
        title: "加载中",
      });
      // 获取章节下是否有题目
      let idPathList = [];
      if (this.properties.storeInfo || this.properties.jslx) {
        idPathList.push({
          id: this.properties.bookInfo.id,
          name: this.properties.bookInfo.name,
          productLinkPath: value.productLinkPath,
          type: value.type,
        })
      } else {
        let query = {
          path: "*",
          queryType: "*",
          productId: this.properties.bookInfo.id,
          cmsPath: value.productLinkPath,
          pading: {
            start: 0,
            size: 999,
          },
        };
        if (value.childrenFolderCount == 0 && value.childrenCount == 0) {
          wx.hideLoading();
          return wx.showToast({
            icon: "error",
            title: "暂无数据",
          });
        } else {
          const res = await app.MG.store.getProductDetail(query);
          res.datas.cmsDatas[0].datas.forEach((item) => {
            idPathList.push({
              id: item.id,
              name: item.name,
              productLinkPath: item.productLinkPath,
              type: item.type,
            });
          });
        }
      }
      wx.hideLoading();
      if (value.refCode == "psychology") {
        const listName = value.name
        wx.navigateTo({
          url: `/packageBookService/pages/psychologyAnswer/psychologyAnswer?listName=${
            listName
        }`
        })
      } else {
        wx.navigateTo({
          url: `/packageBookService/pages/bookServices/examination/examination?bookId=${
            this.properties.bookInfo.id
          }&productLinkPath=${value.productLinkPath}&rootCmsItemId=${
            this.properties.bookInfo.rootCmsItemId
          }&idPathList=${JSON.stringify(idPathList)}&answerTitle=${
            value.name
          }&answerType=option&storeInfo=${this.properties.storeInfo}&jslx=${this.properties.jslx}`,
        });
      }
    },
    goMycollect(e) {
      const gotoPage = () => {
        wx.navigateTo({
          url: `/packageBookService/pages/bookServices/examination/examination?bookId=${
            this.properties.bookInfo.id
          }&rootCmsItemId=${this.properties.bookInfo.rootCmsItemId}&answerTitle=${
            answertype == "collectQuestion" ? "我的收藏" : "我的错题"
          }&answerType=${answertype}`,
        });
      }
      const answertype = e.currentTarget.dataset.answertype;
      const token = wx.getStorageSync("jsek-token");
      if (token) {
        gotoPage()
      } else {
        loginInfo(app, (data) => {
          if (data) {}
        })
      }
      wx.navigateTo({
        url: `/packageBookService/pages/bookServices/examination/examination?bookId=${this.properties.bookInfo.id}&rootCmsItemId=${this.properties.bookInfo.rootCmsItemId}&answerTitle=${answertype == 'collectQuestion' ? '我的收藏' : '我的错题'}&answerType=${answertype}`,
      })
    },
    // 练习 组件切换
    onRadioChange(e) {
      this.setData({
        radioItem: e.detail.value
      })
        radioItem: e.detail.value,
      });
      if (e.detail.value == "mock") {}
    },
    async getMockId() {
      wx.showLoading({
        title: '加载中'
      })
      let id
        title: "加载中",
      });
      let id;
      let query = {
        start: 0,
        size: 99,
        productId: this.properties.bookInfo.id
      }
        productId: this.properties.bookInfo.id,
      };
      await app.MG.edu.getQuizConfigListByProduct(query).then((res) => {
        id = res.datas[0].id
      })
      return id
        id = res.datas[0].id;
      });
      return id;
    },
    // 组卷跳转答题界面
    async goMackPaper(e) {
@@ -121,12 +196,48 @@
      // if (!token) {
      //   return logIn()
      // }
      const mockid = await this.getMockId()
      wx.hideLoading()
      const item = e.currentTarget.dataset.item
      const mockid = await this.getMockId();
      wx.hideLoading();
      const item = e.currentTarget.dataset.item;
      wx.navigateTo({
        url: `/packageBookService/pages/bookServices/examination/examination?bookId=${this.properties.bookInfo.id}&rootCmsItemId=${this.properties.bookInfo.rootCmsItemId}&answerTitle=${item.name}&answerType=${'mock'}&uuid=${item.id}&mockid=${mockid}`,
      })
        url: `/packageBookService/pages/bookServices/examination/examination?bookId=${
          this.properties.bookInfo.id
        }&rootCmsItemId=${this.properties.bookInfo.rootCmsItemId}&answerTitle=${
          item.name
        }&answerType=${"mock"}&uuid=${item.id}&mockid=${mockid}`,
      });
    },
    // 购买组卷
    buyMock() {
      var myEventDetail = {};
      var myEventOption = {
        bubbles: true,
        composed: true,
      };
      this.triggerEvent("buyMock", myEventDetail, myEventOption);
    },
    changeTestLoaidng(type) {
      this.setData({
        loading: type,
      });
    },
    // 题库购买
    buyBank() {
      var myEventDetail = {} // detail对象,提供给事件监听函数
      var myEventOption = {
        bubbles: true,
        composed: true
      } // 触发事件的选项
      this.triggerEvent('buyBank', myEventDetail, myEventOption)
    },
    // 题库加入购物车
    handleShoppingBank() {
      var myEventDetail = {}
      var myEventOption = {
        bubbles: true,
        composed: true
      }
      this.triggerEvent('handleShoppingBank', myEventDetail, myEventOption)
    }
  }
})
  },
});