366 lines
9.1 KiB
JavaScript
366 lines
9.1 KiB
JavaScript
// pages/main/main.js
|
||
const app = getApp()
|
||
const api = require("../../utils/request.js");
|
||
const Api = require("../../api/index");
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
Hei:'300rpx',
|
||
wrongnum: 0,
|
||
collectnum: 0,
|
||
dg1:false,
|
||
background: [],
|
||
indicatorDots: true,
|
||
vertical: false,
|
||
autoplay: true,
|
||
interval: 7000,
|
||
duration: 1500,
|
||
nowWork:null,
|
||
userinfo:{},
|
||
msgList: [
|
||
{ title: "欢迎使用气味培训平台" },
|
||
{ title: "培训报名、考证发证请关注新闻咨询" },
|
||
{ title: "注册用户有3次自助模考机会" },
|
||
]
|
||
},
|
||
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) {
|
||
let that = this;
|
||
if(app.globalData.userinfo&&app.globalData.userinfo.name!==undefined){
|
||
let userinfo = app.globalData.userinfo;
|
||
that.setData({
|
||
userinfo: userinfo,
|
||
search: that.search.bind(that)
|
||
})
|
||
}else{
|
||
// debugger;
|
||
app.callBackUserinfo=res=>{
|
||
if(app.globalData.userinfo&&app.globalData.userinfo.name!==undefined){
|
||
let userinfo = app.globalData.userinfo;
|
||
that.setData({
|
||
userinfo: userinfo,
|
||
search: that.search.bind(that)
|
||
})
|
||
}
|
||
}
|
||
}
|
||
|
||
api.request('/examtest/banner/', 'GET').then(res => {
|
||
if(res.data.length>0){
|
||
let images = []
|
||
for(var i=0;i<res.data.length;i++){
|
||
images.push(app.globalData.mediahost + res.data[i].path)
|
||
}
|
||
that.setData({
|
||
background: images
|
||
})
|
||
}
|
||
})
|
||
|
||
},
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow: function () {
|
||
// let that = this;
|
||
this.getNum();
|
||
// let userinfo = wx.getStorageSync('userinfo');
|
||
// that.setData({
|
||
// userinfo: userinfo
|
||
// })
|
||
//获取用户信息,判断返回信息是否有name,如果有不做处理,继续渲染页面,如果没有,则跳到信息完善页面
|
||
// if(userinfo.role_name == '游客'||(userinfo.name!==''&&userinfo.name!==null&&userinfo.name!=='未知'&&userinfo.name!==undefined)){
|
||
|
||
// }else{
|
||
// wx.redirectTo({
|
||
// url: '/pages/login/registe/registe',
|
||
// })
|
||
// }
|
||
// Api.getBanners().then(res=>{
|
||
// if(res.data.length>0){
|
||
// let images = []
|
||
// for(var i=0;i<res.data.length;i++){
|
||
// images.push(app.globalData.mediahost + res.data[i].path)
|
||
// }
|
||
// that.setData({
|
||
// background: images
|
||
// })
|
||
// }
|
||
// });
|
||
},
|
||
/** 页面相关事件处理函数--监听用户下拉动作 */
|
||
onPullDownRefresh: function () {
|
||
|
||
},
|
||
//培训/考试报名
|
||
goEnroll(){
|
||
wx.navigateTo({
|
||
url: '/pages/main/threshold/threshold',
|
||
})
|
||
},
|
||
//视频
|
||
goVideo(){
|
||
wx.navigateTo({
|
||
url: '/pages/material/video',
|
||
})
|
||
},
|
||
//阈值数据库
|
||
toThreshold: function () {
|
||
wx.navigateTo({
|
||
url: '/pages/main/threshold/threshold',
|
||
})
|
||
},
|
||
goFile(){
|
||
wx.switchTab({
|
||
url: '/pages/material/index',
|
||
})
|
||
},
|
||
//业务介绍
|
||
goIntroduction(){
|
||
api.request('/cms/article/', 'GET', {page: 1,limit: 10}).then(res => {
|
||
let results = res.data.results;
|
||
let id = null;
|
||
for(let i=0;i<results.length;i++){
|
||
if(results[i].title=='国检集团气味评价板块介绍'){
|
||
id=results[i].id;
|
||
wx.navigateTo({
|
||
url: '/pages/article/detail?id='+id,
|
||
})
|
||
}
|
||
}
|
||
})
|
||
// wx.navigateTo({
|
||
// url: '/pages/article/detail?id=1',
|
||
// })
|
||
},
|
||
//成绩查询
|
||
goScore(){
|
||
wx.navigateTo({
|
||
url: '/pages/candidate/index',
|
||
})
|
||
|
||
},
|
||
//证书查询
|
||
goCertificate(){
|
||
wx.navigateTo({
|
||
url: '/pages/candidate/index',
|
||
})
|
||
},
|
||
//参加考试
|
||
goExam(){
|
||
wx.navigateTo({
|
||
url: '/pages/exam/index',
|
||
})
|
||
},
|
||
goCuoti(){
|
||
wx.navigateTo({
|
||
url: '/pages/cuoti/index',
|
||
})
|
||
},
|
||
goShoucang(){
|
||
wx.navigateTo({
|
||
url: '/pages/collect/main',
|
||
})
|
||
},
|
||
goLianxi: function () {
|
||
if (getApp().globalData.userinfo.workscope){
|
||
wx.navigateTo({
|
||
url: '/pages/lianxi/index',
|
||
})
|
||
}else{
|
||
wx.showModal({
|
||
title: '暂未开通权限!',
|
||
content: '查看各地区课程顾问联系方式。',
|
||
confirmText: '查看',
|
||
success(res) {
|
||
if (res.confirm) {
|
||
wx.navigateTo({
|
||
url: '/pages/article/detail?id=3',
|
||
})
|
||
}
|
||
}
|
||
})
|
||
}
|
||
},
|
||
goYati: function () {
|
||
if (getApp().globalData.userinfo.workscope) {
|
||
wx.navigateTo({
|
||
url: '/pages/yati/index',
|
||
})
|
||
} else {
|
||
wx.showModal({
|
||
title: '暂未开通权限!',
|
||
content: '查看各地区课程顾问联系方式。',
|
||
confirmText: '查看',
|
||
success(res) {
|
||
if (res.confirm) {
|
||
wx.navigateTo({
|
||
url: '/pages/article/detail?id=6',
|
||
})
|
||
}
|
||
}
|
||
})
|
||
}
|
||
},
|
||
showExp: function (){
|
||
var that = this
|
||
const workscope = getApp().globalData.userinfo.workscope
|
||
const remain_count = getApp().globalData.userinfo.remain_count
|
||
if (!workscope && remain_count){
|
||
wx.showModal({
|
||
title: '暂未开通权限!',
|
||
content: '您有' + remain_count + '次体验次数.',
|
||
confirmText: '体验一下',
|
||
success(res) {
|
||
if (res.confirm) {
|
||
that.genPaper2()
|
||
}
|
||
}
|
||
})
|
||
}
|
||
},
|
||
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,
|
||
})
|
||
}
|
||
}
|
||
},
|
||
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',
|
||
})
|
||
})
|
||
|
||
},
|
||
showDg: function(){
|
||
this.setData({
|
||
dg1:true
|
||
})
|
||
},
|
||
Baoming: function (){
|
||
wx.navigateToMiniProgram({
|
||
appId: 'wxdcf5bbfb50dbbac8',
|
||
path: '',
|
||
success(res) {
|
||
// 打开其他小程序成功同步触发
|
||
// wx.showToast({
|
||
// title: '跳转成功'
|
||
// })
|
||
}
|
||
})
|
||
},
|
||
search: function (value) {
|
||
return new Promise((resolve, reject) => {
|
||
api.request('/question/question/', 'GET', {search:value,page:1,limit:20}).then(res => {
|
||
if(res.data && res.data.results){
|
||
for(var i=0; i<res.data.results.length;i++){
|
||
res.data.results[i].text = res.data.results[i].name.replace('<p>','').replace('</p>','').substring(0,18)+'...'
|
||
res.data.results[i].value = res.data.results[i].id
|
||
}
|
||
resolve(res.data.results)
|
||
}else{
|
||
resolve([{text: '无搜索结果', value: 0}])
|
||
}
|
||
})
|
||
})
|
||
},
|
||
selectResult: function (e) {
|
||
wx.navigateTo({
|
||
url: `/pages/question/detail?id=${e.detail.item.id}`,
|
||
})
|
||
},
|
||
getNum: function(){
|
||
try{
|
||
const ctms = wx.getStorageSync('ctms')
|
||
this.setData({
|
||
wrongnum:ctms.length
|
||
})
|
||
}catch(e){}
|
||
},
|
||
goTest: function(){
|
||
var that = this
|
||
const workscope = getApp().globalData.userinfo.workscope
|
||
wx.showLoading({
|
||
title: '正在生成试卷',
|
||
mask:true
|
||
})
|
||
api.request('/examtest/workscope/' + workscope + '/examtest/', 'GET').then(res => {
|
||
wx.hideLoading()
|
||
try {
|
||
wx.setStorageSync('examtest', res.data)
|
||
} catch (e) { }
|
||
wx.navigateTo({
|
||
url: '/pages/exam/note',
|
||
})
|
||
})
|
||
|
||
}
|
||
}) |