examtest_mp/pages/exam/index.js

167 lines
3.4 KiB
JavaScript

// pages/qtest/form.js
const api = require("../../utils/request.js");
Page({
/**
* 页面的初始数据
*/
data: {
if_checked:false,
userInfo:{},
form:{
deptname:null,
code:null
}
},
idinput: function(e){
this.data.form.ID_number = e.detail.value
},
nameinput: function(e){
this.data.form.name = e.detail.value
},
companyinput: function(e){
this.data.form.company_name = e.detail.value
},
deptinput: function(e){
this.data.form.deptname = e.detail.value
},
codeinput: function(e){
this.data.form.code = e.detail.value
},
submit: function(){
var that = this
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
if(!reg.test(this.data.form.ID_number))
{
wx.showToast({
title: '身份证号有误',
icon:'none'
})
return false;
}
if(this.data.form.deptname&&this.data.form.code&&this.data.form.name&&this.data.form.company_name&&this.data.form.ID_number){
wx.showLoading({
title: '加入考试...',
mask:true
})
let data = this.data.form
api.request('/examtest/exam/attend/','POST', data).then(res=>{
wx.showToast({
title: '加入考试成功',
icon:'none'
})
wx.showLoading({
title: '正在组卷...',
mask:true
})
let exam = res.data.exam
api.request(`/examtest/exam/${exam}/init/`,'POST', data).then(res=>{
wx.hideLoading()
try {
wx.setStorageSync('examtest', res.data)
} catch (e) { }
wx.navigateTo({
url: '/pages/exam/note',
})
}).catch(e=>{
wx.hideLoading({
success: (res) => {},
})
})
})
}else{
wx.showToast({
title: '信息不完整',
icon:'none'
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.showLoading({
title: '获取基本信息中..',
})
api.request('/crm/consumer/info/','GET').then(res=>{
wx.hideLoading()
let userinfo = res.data.userinfo
getApp().globalData.userinfo = userinfo
this.setData(
{
userinfo: res.data.userinfo,
form:{
deptname:res.data.userinfo.deptname,
company_name:res.data.userinfo.company_name,
ID_number: res.data.userinfo.ID_number1,
name: res.data.userinfo.name
},
}
)
}).catch(e=>{wx.hideLoading()})
},
checkedChange(e){
let if_checked = !this.data.if_checked;
this.setData({
if_checked:if_checked
})
},
clickSure(){
wx.showToast({
icon: 'none',
title: '请先阅读并同意协议',
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})