Commit e5985b49 by chenzhenan

修复生活事件量表bug,新增量表信息录入增加手机号必填,验证身份证号

parent fb9ccfdf
...@@ -118,9 +118,16 @@ Page({ ...@@ -118,9 +118,16 @@ Page({
let answerIndex = parameter.answerIndex let answerIndex = parameter.answerIndex
let contentIndex = parameter.contentIndex let contentIndex = parameter.contentIndex
let currentIndex = this.data.currentIndex let currentIndex = this.data.currentIndex
let scaleTitleIndex = parameter.scaleTitleIndex
if (this.data.isCanClick === false) { if (this.data.isCanClick === false) {
return return
} }
if(scaleTitleIndex != currentIndex){
return
}
if(this.data.questionData[answerIndex].isShow === false){
return
}
this.setData({ this.setData({
isCanClick:false isCanClick:false
}) })
...@@ -144,7 +151,6 @@ Page({ ...@@ -144,7 +151,6 @@ Page({
//判断是否可以提交了 //判断是否可以提交了
this.canSubmit() this.canSubmit()
} else { } else {
this.setData({ this.setData({
currentIndex:currentIndex+1 currentIndex:currentIndex+1
}) })
...@@ -161,7 +167,7 @@ Page({ ...@@ -161,7 +167,7 @@ Page({
}) })
} }
clearTimeout(timer) clearTimeout(timer)
}, 200) },200)
} else { } else {
//将选项存入答题记录,同时更新视图内容,记录答题 //将选项存入答题记录,同时更新视图内容,记录答题
let record = this.data.answerRecord[this.data.currentIndex] let record = this.data.answerRecord[this.data.currentIndex]
...@@ -213,6 +219,7 @@ Page({ ...@@ -213,6 +219,7 @@ Page({
//提交 //提交
submit: debouce(function () { submit: debouce(function () {
//验证数据的完整性 //验证数据的完整性
console.log(this.data.answerRecord)
if (!checkAnswerRecord(this.data.answerRecord)) { if (!checkAnswerRecord(this.data.answerRecord)) {
wx.showModal({ wx.showModal({
showCancel: false, showCancel: false,
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<block wx:for="{{scaleTitleData}}" wx:for-item="scaleTitle" wx:for-index="scaleTitleIndex" wx:key="scaleTitleIndex"> <block wx:for="{{scaleTitleData}}" wx:for-item="scaleTitle" wx:for-index="scaleTitleIndex" wx:key="scaleTitleIndex">
<block wx:if="{{currentIndex === scaleTitleIndex}}"> <block wx:if="{{currentIndex === scaleTitleIndex}}">
<block wx:for="{{questionData}}" wx:for-index="answerIndex" wx:for-item="answerItem" wx:key="answerIndex"> <block wx:for="{{questionData}}" wx:for-index="answerIndex" wx:for-item="answerItem" wx:key="answerIndex">
<block wx:if="{{answerItem.isShow}}"> <view hidden="{{!answerItem.isShow}}">
<view class="con"> <view class="con">
<text style="margin-top: 10rpx;">{{scaleTitle}}--{{answerItem.subtitle}}</text> <text style="margin-top: 10rpx;">{{scaleTitle}}--{{answerItem.subtitle}}</text>
</view> </view>
...@@ -11,11 +11,12 @@ ...@@ -11,11 +11,12 @@
wx:key="contentIndex"> wx:key="contentIndex">
<view bindtap="selectOption" data-content-item="{{contentItem}}" data-answer-index="{{answerIndex}}" <view bindtap="selectOption" data-content-item="{{contentItem}}" data-answer-index="{{answerIndex}}"
data-content-index="{{contentIndex}}" data-content-index="{{contentIndex}}"
data-scale-title-index="{{scaleTitleIndex}}"
class="answer + {{answerRecord[currentIndex][answerIndex].index === contentIndex?'s-active':''}}"> class="answer + {{answerRecord[currentIndex][answerIndex].index === contentIndex?'s-active':''}}">
<text>{{contentItem.title}}</text> <text>{{contentItem.title}}</text>
</view> </view>
</view> </view>
</block> </view>
</block> </block>
</block> </block>
</block> </block>
......
var Api = require('../../utils/api.js'); var Api = require('../../utils/api.js');
import { validateIdCard } from '../../utils/util'
var app = getApp(); var app = getApp();
Page({ Page({
...@@ -412,6 +413,7 @@ Page({ ...@@ -412,6 +413,7 @@ Page({
data.name = that.data.username; //姓名 data.name = that.data.username; //姓名
data.sex = that.data.sex; //性别 data.sex = that.data.sex; //性别
data.birthday = that.data.date; // 年龄 data.birthday = that.data.date; // 年龄
data.usernumber = that.data.usernumber //手机号
data.jobnumber = that.data.jobnumber; //工号 data.jobnumber = that.data.jobnumber; //工号
data.sheqvNumber = that.data.sheqvNumber; data.sheqvNumber = that.data.sheqvNumber;
data.workNumber = that.data.workNumber; data.workNumber = that.data.workNumber;
...@@ -424,13 +426,27 @@ Page({ ...@@ -424,13 +426,27 @@ Page({
// 新添加学历功能 // 新添加学历功能
data.edu = that.data.index||0; data.edu = that.data.index||0;
console.log('data',data) console.log('data',data)
if (data.name == '' || data.name == 'null' || data.sex == "null" || data.sex == "" || data.birthday == '' || data.birthday == 'null' || data.edu == 0||data.idCard==""||data.username1==""||data.select==0) { if (data.name == '' || data.name == 'null' || data.sex == "null" || data.sex == "" || data.birthday == '' || data.birthday == 'null' || data.edu == 0||data.idCard==""||data.username1==""||data.select==0){
that.setData({ that.setData({
payInfo: true payInfo: true
}) })
Api.alert('请完善信息'); Api.alert('请完善信息');
return; return;
} }
if( data.usernumber=='' || data.usernumber == 'null' || data.usernumber.length != 11){
that.setData({
payInfo: true
})
Api.alert('请填写正确的手机号');
return;
}
if(!validateIdCard(data.idCard)){
that.setData({
payInfo: true
})
Api.alert('请填写正确的身份证号');
return;
}
var timer1 = setTimeout(function () { var timer1 = setTimeout(function () {
// Api.alert("加载失败,请重试") // Api.alert("加载失败,请重试")
wx.hideLoading() wx.hideLoading()
......
...@@ -242,6 +242,24 @@ function debouce(func, delay, immediate) { ...@@ -242,6 +242,24 @@ function debouce(func, delay, immediate) {
} }
} }
/** /**
* 节流函数
* @param {function} fn 实际要执行的函数
* @param {interval} interval 间隔时间,如果interval不传,则默认300ms
*/
function throttle(fn, interval) {
var enterTime = 0; //触发的时间
var gapTime = interval || 300; //间隔时间,如果interval不传,则默认300ms
return function() {
var context = this; //闭包取当前函数this
var backTime = new Date(); //第一次函数return即触发的时间
if (backTime - enterTime >= gapTime) {
//封装实参的对象arguments
fn.apply(context, arguments);
enterTime = backTime; //赋值给第一次触发的时间,这样就保存了第二次触发的时间
}
};
}
/**
* 秒数转换时间 * 秒数转换时间
* @param {Int} value * @param {Int} value
*/ */
...@@ -294,9 +312,49 @@ function base64src(base64data) { ...@@ -294,9 +312,49 @@ function base64src(base64data) {
fail() { fail() {
reject(new Error('ERROR_BASE64SRC_WRITE')); reject(new Error('ERROR_BASE64SRC_WRITE'));
}, },
}); })
}); })
}; }
/**
*身份验证
* @param {string} idCard 身份证号码
*/
function validateIdCard(idCard) {
//15位和18位身份证号码的正则表达式
var regIdCard =
/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
//如果通过该验证,说明身份证格式正确,但准确性还需计算
if (regIdCard.test(idCard)) {
if (idCard.length == 18) {
var idCardWi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); //将前17位加权因子保存在数组里
var idCardY = new Array(1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2); //这是除以11后,可能产生的11位余数、验证码,也保存成数组
var idCardWiSum = 0; //用来保存前17位各自乖以加权因子后的总和
for (var i = 0; i < 17; i++) {
idCardWiSum += idCard.substring(i, i + 1) * idCardWi[i];
}
var idCardMod = idCardWiSum % 11; //计算出校验码所在数组的位置
var idCardLast = idCard.substring(17); //得到最后一位身份证号码
//如果等于2,则说明校验码是10,身份证号码最后一位应该是X
if (idCardMod == 2) {
if (idCardLast == "X" || idCardLast == "x") {
return true;
} else {
return false;
}
} else {
//用计算出的验证码与最后一位身份证号码匹配,如果一致,说明通过,否则是无效的身份证号码
if (idCardLast == idCardY[idCardMod]) {
return true;
} else {
return false;
}
}
}
} else {
return false;
}
}
module.exports = { module.exports = {
base64src:base64src, base64src:base64src,
formatTime: formatTime, formatTime: formatTime,
...@@ -307,6 +365,8 @@ module.exports = { ...@@ -307,6 +365,8 @@ module.exports = {
formatLocation: formatLocation, formatLocation: formatLocation,
timestampToTime: timestampToTime, timestampToTime: timestampToTime,
debouce:debouce, debouce:debouce,
throttle:throttle,
isEmpty:isEmpty, isEmpty:isEmpty,
formatSeconds:formatSeconds formatSeconds:formatSeconds,
validateIdCard:validateIdCard
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment