197 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			197 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
// pages/main/main.js
 | 
						||
const app = getApp()
 | 
						||
const api = require("../../utils/request.js");
 | 
						||
Page({
 | 
						||
 | 
						||
  /**
 | 
						||
   * 页面的初始数据
 | 
						||
   */
 | 
						||
  data: {
 | 
						||
    Hei:0,
 | 
						||
    background: [app.globalData.mediahost + '/media/banner/1.jpg'],
 | 
						||
    indicatorDots: true,
 | 
						||
    vertical: false,
 | 
						||
    autoplay: true,
 | 
						||
    interval: 7000,
 | 
						||
    duration: 1500,
 | 
						||
    nowWork:null,
 | 
						||
    msgList: [
 | 
						||
      { title: "欢迎使用中科辐射学堂!" },
 | 
						||
      { title: "如有疑问,请致电课程顾问师老师:18355135390" },]
 | 
						||
  },
 | 
						||
  imgH: function (e) {
 | 
						||
    let winWid = wx.getSystemInfoSync().windowWidth;        //获取当前屏幕的宽度
 | 
						||
    let imgh = e.detail.height;                //图片高度
 | 
						||
    let imgw = e.detail.width;
 | 
						||
    let swiperH = winWid * imgh / imgw + "px";
 | 
						||
    this.setData({
 | 
						||
      Hei: swiperH        //设置高度
 | 
						||
    })
 | 
						||
  },
 | 
						||
  /**
 | 
						||
   * 生命周期函数--监听页面加载
 | 
						||
   */
 | 
						||
  onLoad: function (options) {
 | 
						||
    var that = this
 | 
						||
    api.request('/examtest/banner/', 'GET').then(res => {
 | 
						||
      let images = []
 | 
						||
      for(var i=0;i<res.data.length;i++){
 | 
						||
        images.push(app.globalData.mediahost + res.data[i].path)
 | 
						||
      }
 | 
						||
      that.setData({
 | 
						||
        background: images
 | 
						||
      })
 | 
						||
    })
 | 
						||
  },
 | 
						||
 | 
						||
  /**
 | 
						||
   * 生命周期函数--监听页面初次渲染完成
 | 
						||
   */
 | 
						||
  onReady: function () {
 | 
						||
 | 
						||
  },
 | 
						||
 | 
						||
  /**
 | 
						||
   * 生命周期函数--监听页面显示
 | 
						||
   */
 | 
						||
  onShow: function () {
 | 
						||
    // if(wx.getStorageSync('nowWork')){
 | 
						||
    //   this.setData({
 | 
						||
    //     nowWork: wx.getStorageSync('nowWork')
 | 
						||
    //   })
 | 
						||
    // }
 | 
						||
  },
 | 
						||
 | 
						||
  /**
 | 
						||
   * 生命周期函数--监听页面隐藏
 | 
						||
   */
 | 
						||
  onHide: function () {
 | 
						||
 | 
						||
  },
 | 
						||
 | 
						||
  /**
 | 
						||
   * 生命周期函数--监听页面卸载
 | 
						||
   */
 | 
						||
  onUnload: function () {
 | 
						||
 | 
						||
  },
 | 
						||
 | 
						||
  /**
 | 
						||
   * 页面相关事件处理函数--监听用户下拉动作
 | 
						||
   */
 | 
						||
  onPullDownRefresh: function () {
 | 
						||
 | 
						||
  },
 | 
						||
 | 
						||
  /**
 | 
						||
   * 页面上拉触底事件的处理函数
 | 
						||
   */
 | 
						||
  onReachBottom: function () {
 | 
						||
 | 
						||
  },
 | 
						||
 | 
						||
  /**
 | 
						||
   * 用户点击右上角分享
 | 
						||
   */
 | 
						||
  onShareAppMessage: function () {
 | 
						||
 | 
						||
  },
 | 
						||
  // chooseWork: function () {
 | 
						||
  //   wx.navigateTo({
 | 
						||
  //     url: '/pages/workscope/index',
 | 
						||
  //   })
 | 
						||
  // },
 | 
						||
  goLianxi: function () {
 | 
						||
    if (getApp().globalData.userinfo.workscope){
 | 
						||
      wx.navigateTo({
 | 
						||
        url: '/pages/lianxi/index',
 | 
						||
      })
 | 
						||
    }else{
 | 
						||
      wx.showToast({
 | 
						||
        title: '未开通权限\r\n请致电18355135390',
 | 
						||
        icon: 'none',
 | 
						||
        duration: 2000
 | 
						||
      })
 | 
						||
    }
 | 
						||
  },
 | 
						||
  goMoni: function () {
 | 
						||
    var that = this
 | 
						||
    const workscope = getApp().globalData.userinfo.workscope
 | 
						||
    if (workscope) {
 | 
						||
      that.genPaper(workscope)
 | 
						||
    }
 | 
						||
    else {
 | 
						||
      const remain_count = getApp().globalData.userinfo.remain_count
 | 
						||
      let confirmText, showCancel
 | 
						||
      if(remain_count>0){
 | 
						||
        wx.showModal({
 | 
						||
          title: '未开通权限!',
 | 
						||
          content: '您有' + remain_count + '次体验次数.',
 | 
						||
          confirmText: '体验一下',
 | 
						||
          success(res) {
 | 
						||
            if (res.confirm) {
 | 
						||
              that.genPaper2()
 | 
						||
            }
 | 
						||
          }
 | 
						||
        })
 | 
						||
      }else{
 | 
						||
        wx.showModal({
 | 
						||
          title: '未开通权限!',
 | 
						||
          content: '体验次数已用完',
 | 
						||
          showCancel: false,
 | 
						||
        })
 | 
						||
      }
 | 
						||
    }
 | 
						||
  },
 | 
						||
  goYati: function () {
 | 
						||
    if (getApp().globalData.userinfo.workscope) {
 | 
						||
      wx.navigateTo({
 | 
						||
        url: '/pages/yati/index',
 | 
						||
      })
 | 
						||
    } else {
 | 
						||
      wx.showToast({
 | 
						||
        title: '未开通权限\r\n请联系课程顾问',
 | 
						||
        icon: 'none',
 | 
						||
        duration: 2000
 | 
						||
      })
 | 
						||
    }
 | 
						||
  },
 | 
						||
  testList: function (){
 | 
						||
    wx.navigateTo({
 | 
						||
      url: '/pages/test/list',
 | 
						||
    })
 | 
						||
  },
 | 
						||
  genPaper: function (workId) {
 | 
						||
    wx.showLoading({
 | 
						||
      title: '正在生成试卷',
 | 
						||
      mask:true
 | 
						||
    })
 | 
						||
    api.request('/examtest/workscope/' + workId + '/monitest/', 'GET').then(res => {
 | 
						||
      wx.hideLoading()
 | 
						||
      try {
 | 
						||
        wx.setStorageSync('examtest', res.data)
 | 
						||
      } catch (e) { }
 | 
						||
      wx.navigateTo({
 | 
						||
        url: '/pages/moni/note',
 | 
						||
      })
 | 
						||
    })
 | 
						||
    
 | 
						||
  },
 | 
						||
  genPaper2: function () {
 | 
						||
    wx.showLoading({
 | 
						||
      title: '正在生成试卷',
 | 
						||
      mask: true
 | 
						||
    })
 | 
						||
    api.request('/examtest/workscope/monitest2/', 'GET').then(res => {
 | 
						||
      wx.hideLoading()
 | 
						||
      try {
 | 
						||
        wx.setStorageSync('examtest', res.data)
 | 
						||
        getApp().globalData.userinfo.remain_count = res.data.remain_count
 | 
						||
      } catch (e) { }
 | 
						||
      wx.navigateTo({
 | 
						||
        url: '/pages/moni/note',
 | 
						||
      })
 | 
						||
    })
 | 
						||
 | 
						||
  },
 | 
						||
}) |