const util = require('../../utils/util.js'); const api = require('../../config/api.js'); const user = require('../../utils/user.js'); //获取应用实例 const app = getApp(); Page({ data: { isShow: false, //控制确认学生信息对话框 stulist: {}, xyrwList: [], rwname:'', rwempty: 0, batchno: '', nationId: '', list:[], loadingHidden: true, flag: false, openid: '' }, isValidID:function (id) { if (!/^\d{17}(\d|X)$/.test(id)) return false; // 检查格式是否正确 // 计算第18位校验码 const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; const checkCode = '10X98765432'; let sum = 0; for (let i = 0; i < id.length - 1; i++) { sum += parseInt(id[i], 10) * weights[i]; } sum = sum % 11; // 验证第18位校验码是否正确 return checkCode[sum] === id[17].toUpperCase(); }, btnAdd: function(){ if(this.isValidID(this.data.nationId) == false){ wx.showToast({ title: '身份证不合法!', icon:'success', duration: 1000 }) this.setData({ nationId: '', }); return; } //根据身份证号和批次号查询学生信息 var that = this; util.request(api.smstudentByInit, { nationid: that.data.nationId, batchno: this.data.batchno }) .then(function(res) { if (res.code === 0) { console.log(res.data); if(res.data == null){ wx.showToast({ title: '无此体检人员', icon:'error' }) }else{ that.setData({ stulist: res.data, isShow: true }); } } }); }, onCancelStudent: function(){ }, onConfirmStudent: function(){ let that = this; let cardNum = this.data.stulist.nationId; // let type = this.data.type let hzxm =this.data.stulist.name; let sex = this.getSexFromIdCard(this.data.stulist.nationId) let age = this.calculateAge(this.data.stulist.nationId) let userid = this.data.stulist.id; // let classid = this.data.xytjinfo.classid; let classname = this.data.stulist.classname; let schoolname = this.data.stulist.schoolname; let sqName = this.data.stulist.sqName; let cardtype = ""; console.log(hzxm) console.log(cardNum) console.log(sex) console.log(age) console.log(userid) //家长确认学生信息,进行建档和关联就诊人操作 util.requestPost(api.smcreatestudent, { openid: app.globalData.openId, name: hzxm, deptId: userid, sex: sex, age: age, className: classname, schoolName: schoolname, sqName: sqName, nationId: cardNum }) .then(function(res) { console.log(res); if (res.code === 0) { console.log("createstudent res:"); console.log(res); console.log("createstudent resdata:"); console.log(res.data); cardtype = res.data; // if(type == 0) // { // // app.globalData.gdefaultflag = type; // app.globalData.gname = hzxm; // app.globalData.gsex = sex; // app.globalData.gage = age; // // app.globalData.gdeptId = classid; // app.globalData.gclassName = classname; // app.globalData.gschoolName = schoolname; // app.globalData.gnationId = cardNum; // } //自动建档并关联到父openid that.linkUser(hzxm, cardNum, cardtype); wx.showToast({ title: '添加成功', icon:'success' }) setTimeout(item => { wx.navigateBack({ delta: 1 //返回上一级页面 }) },1000) } else{ wx.showToast({ title: res.msg, icon:'error' }) } }); }, linkUser:function(gname, xPatid, cardtype){ //第二步 关联到父openid console.log(xPatid, 'usrPatid'); wx.request({ url:'https://fy.btlsoln.com:8443/patientBindWXUser?cardno&cardtype&openid&relate&type&hzxm', method:"GET", data:{ cardno: xPatid, cardtype: cardtype, relate: '1', //都是子女 type: '1', //不当做默认就诊人 openid: app.globalData.openId, hzxm: gname }, header: { 'content-type': 'application/json' }, success: (res)=> { if(res.data.errCode == 0){ wx.showToast({ title: '关联就诊人成功', icon:'success' }) return true; }else{ wx.showToast({ title: "关联就诊人失败", icon:'error' }) return false; } } }) }, //获取下园任务列表 getXyrwList: function() { var that = this; util.request(api.smxyrwinfo, { }) .then(function(res) { if (res.code === 0) { console.log("xyrwinfo resdata:"); console.log(res.data); if(res.data.length == 0){ that.setData({ rwempty: 0 }); app.globalData.hasXyrw = false; }else{ that.setData({ rwempty: 1, xyrwList: res.data, rwname: res.data[0].batchName, batchno: res.data[0].batchno }); app.globalData.hasXyrw = true; that.getPerList(res.data[0].batchno); } } }); }, //取列表 getPerList: function(resbatchno){ let that = this; util.request(api.smstudentByparent, { openid: app.globalData.openId, batchno: resbatchno }) .then(function(res) { if (res.code === 0) { console.log("list res:"); console.log(res); console.log("list resdata:"); console.log(res.data); that.setData({ list: res.data }); console.log("list length", that.data.list.length); if(that.data.list.length == 0 ){ that.setData({ loadingHidden: false, flag: false }); }else{ //有体检人,取出默认体检人 var filterNum = that.data.list.filter(function(person,index,arrs){ return person.defaultflag==0 }); console.log("fileter"); console.log(filterNum); that.setData({ loadingHidden: true, flag: true }); } that.setData({ loadingHidden: true }); } }) }, naviToAdd(){ let state = 0 wx.navigateTo({ url: '/pages/studentMsgDel/studentMsgDel?state='+state, }) }, naviToDet(e){ return; console.log(e.currentTarget.dataset.item) let item = e.currentTarget.dataset.item let idCard = item.nationId let trueName = item.name let type = item.defaultflag let sex = item.sex let age = item.age let classid = item.deptId let classname = item.className let schoolname = item.schoolName let state = 1 var id = 0; id = item.id wx.navigateTo({ url: '/pages/studentMsgDel/studentMsgDel?state='+state+'&classid='+classid+'&classname='+classname+'&schoolname='+schoolname+'&idCard='+idCard+'&trueName='+trueName+'&type='+type +'&sex='+sex +'&age='+age +'&id='+id, }) }, naviToXytj(){ wx.navigateTo({ url: '/pages/xytj/xytj', }) }, onChange({ detail }) { this.setData({ checked: detail }); }, onShareAppMessage: function() { }, onPullDownRefresh() { }, onLoad: function(options) { // 页面初始化 options为页面跳转所带来的参数 this.getXyrwList(); this.setData({ loadingHidden: false, }) }, onReady: function() { // 页面渲染完成 wx.setNavigationBarTitle({ title: "管理体检人员" }) }, onShow: function() { // 页面显示 this.getPerList() this.setData({ loadingHidden: false, }) }, onHide: function() { // 页面隐藏 }, onUnload: function() { // 页面关闭 }, // 从身份证号码中提取性别信息 getSexFromIdCard: function(idCard){ var org_gender = idCard.substring(16, 17); // var sex = org_gender % 2 == 1 ? "男" : "女"; var sex = org_gender % 2 == 1 ? 1 : 2; return sex; // 这里假设身份证号码长度为18位并按照标准格式存放 }, // 从身份证号码中提取生日信息(格式为YYYYMMDD) getBirthdayFromIdCard: function(idCard){ return idCard.substring(6, 14); // 这里假设身份证号码长度为18位并按照标准格式存放 }, // 将字符串类型的生日转换成Date对象 convertToDateObject: function(birthdayString){ const year = birthdayString.substr(0, 4); const month = birthdayString.substr(4, 2); const day = birthdayString.substr(6, 2); return new Date(`${year}-${month}-${day}`); }, // 计算年龄函数 calculateAge: function(idCard){ // 获取当前日期 const currentDate = new Date(); const birthdate = this.convertToDateObject(this.getBirthdayFromIdCard(idCard)); let age; if (currentDate >= birthdate && !isNaN(currentDate)) { age = Math.floor((currentDate - birthdate) / (365 * 24 * 60 * 60 * 1000)); } else { console.error('无效的身份证号码或者未知错误'); } return age || ''; } })