155 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			155 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
| // pages/qtest/form.js
 | |
| const api = require("../../utils/request.js");
 | |
| Page({
 | |
| 
 | |
|   /**
 | |
|    * 页面的初始数据
 | |
|    */
 | |
|   data: {
 | |
|       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()})
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 生命周期函数--监听页面初次渲染完成
 | |
|    */
 | |
|   onReady: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 生命周期函数--监听页面显示
 | |
|    */
 | |
|   onShow: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 生命周期函数--监听页面隐藏
 | |
|    */
 | |
|   onHide: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 生命周期函数--监听页面卸载
 | |
|    */
 | |
|   onUnload: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 页面相关事件处理函数--监听用户下拉动作
 | |
|    */
 | |
|   onPullDownRefresh: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 页面上拉触底事件的处理函数
 | |
|    */
 | |
|   onReachBottom: function () {
 | |
| 
 | |
|   },
 | |
| 
 | |
|   /**
 | |
|    * 用户点击右上角分享
 | |
|    */
 | |
|   onShareAppMessage: function () {
 | |
| 
 | |
|   }
 | |
| }) |