123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- const app = require('../../utils/util.js');
- const tools = require('../../utils/tools.js');
- import WxValidate from '../../utils/WxValidate';
- const COS = require('../../utils/cos.js');
- Page({
- data: {
- isRz: 0,
- userName: "",
- phone: "",
- card: "",
- isInput1: false,
- isInput2: false,
- isInput3: false,
- carWin_img: '', //存放照片路径的
- cosPath: "" //腾讯云上传的路径
- },
- // 错误信息回显
- showModal(error) {
- wx.showModal({
- content: error.msg,
- showCancel: false,
- })
- },
- openCamera() {
- wx.chooseImage({
- count: 1,
- sizeType: ['original', 'compressed'],
- sourceType: ['', 'camera'],
- success:(res)=> {
- console.log(res)
- let path = res.tempFilePaths[0];
- // tempFilePath可以作为img标签的src属性显示图片
- console.log(path)
- this.setData({
- carWin_img: path
- })
- }
- })
- },
- // 提交
- tj(sessionKey, params) {
- wx.request({
- url: app.globalData.publicUrl + '/wx/student/uthentication',
- method: "post",
- data: {
- studentName: params.userName,
- studentCard: params.card,
- phone: params.phone,
- sessionKey: sessionKey
- },
- success: function (res) {
- wx.hideLoading()
- if (res.data.code == 0) {
- wx.showModal({
- showCancel: false,
- content: "提交成功啦",
- success(res) {
- if (res.confirm) {
- wx.switchTab({
- url: '../index/index'
- })
- }
- }
- })
- } else {
- wx.showModal({
- showCancel: false,
- content: res.data.msg
- })
- }
- }
- })
- },
- // 表单提交 跳转tj()
- async formSubmit(e) {
- wx.showLoading({
- mask: true,
- title: '加载中',
- })
- if (this.data.isRz == 0) {
- const params = e.detail.value
- if (!this.WxValidate.checkForm(params)) {
- const error = this.WxValidate.errorList[0]
- this.showModal(error)
- wx.hideLoading()
- return false
- }
- const sessionKey = await tools.checkSessionAndLogin();
- this.tj(sessionKey, params);
- } else {
- wx.hideLoading()
- wx.showModal({
- showCancel: false,
- content: "您已经认证过了"
- })
- }
- },
- // 如果有就把信息回显出来
- getInformation(sessionKey) {
- // let _this = this;
- wx.request({
- url: app.globalData.publicUrl + '/wx/student/selStudentSessionKeyEcho',
- method: "post",
- data: {
- sessionKey: sessionKey
- },
- success: (res) => {
- if (res.data.code == 0) {
- if (res.data.data !== null || res.data.data !== "") {
- this.setData({
- isRz: 1,
- userName: res.data.data.miniName,
- phone: res.data.data.miniPhone,
- card: res.data.data.studentCard,
- isInput3: true
- })
- }
- }
- }
- })
- },
- async onLoad() {
- const sessionKey = await tools.checkSessionAndLogin();
- this.getInformation(sessionKey);
- this.initValidate();
- },
- // 验证字段的规则
- initValidate() {
- const rules = {
- userName: {
- required: true
- },
- phone: {
- required: true,
- tel: true,
- },
- card: {
- required: true,
- idcard: true,
- }
- }
- // 验证字段的提示信息,若不传则调用默认的信息
- const messages = {
- userName: {
- required: '请输入姓名'
- },
- phone: {
- required: '请输入手机号',
- tel: '请输入正确的手机号',
- },
- card: {
- required: '请输入身份证号码',
- idcard: '请输入正确的身份证号码',
- }
- }
- // 创建实例对象
- this.WxValidate = new WxValidate(rules, messages)
- }
- })
|