Files
kelfy-mini/pages/studentMsgDel/studentMsgDel.js
2025-11-13 13:39:24 +08:00

819 lines
20 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../utils/user.js');
//获取应用实例
const app = getApp();
//var app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
//默认为0从根节点开始
parentid: 0,
//学生归属的学校id
deptid: 0,
//班级选择
classxpList:[],
classxpListBackup: [],
classIndexes: '',
classcurrent: '',
classSwitch: false,
//学校选择
schoolxpList:[],
schoolxpListBackup: [],
schoolIndexes: '',
schoolcurrent: '',
schoolSwitch: false,
//体检部门信息
schoolname: '',
classname: '',
studentname: '',
xytjinfo: {
jdid: '',
jdname: '',
sqid: '',
sqname: '',
schoolid: '',
schoolname: '',
classid: '',
classname: ''
},
// show:false,
// show2:false,
// show3:false,
showsex: false,
relateSex:[
{name:'男',value:'1'},
{name:'女',value:'2'},
],
// relate:[
// {name:'本人',relate:'0'},
// {name:'子女',relate:'1'},
// {name:'夫妻',relate:'2'},
// {name:'父母',relate:'3'},
// {name:'朋友',relate:'4'},
// ],
// cardType: [
// // { name: '病历卡', value: 0 },
// { name: '就诊卡', value: 1 ,msg:"请输入就诊卡号"},
// // { name: '保障卡', value: 3 },
// { name: '社保卡', value: 1 ,msg:'请输入社保卡号'},
// { name: '身份证(电子健康卡)', value: 4 ,msg:'请输入身份证号码'},
// ],
state:'',//新增编辑状态
type:'',//是否默认
checked: '',//默认按钮选中状态
idCard:'',//身份证
trueName:'',//姓名
sex: '', //性别
sexdisp: '', //性别显示
age: '', //年龄
id: 0, //学生表主键id
xschoolname: '',
xclassname: '',
xclassid: '',
sfzList:[],
msg:"请输入号码",
relateNmae:'',//关系名
relateId:'',//关系值
carNum:'',//就诊卡
title:'',//标题
cardT:'',//证件类型
disabled:'',
zjh:'',//证件号
usrPatid:'' //学生就诊卡
},
showPopSex(){
this.setData({ showsex: true });
},
onCloseSex(){
this.setData({ showsex: false });
},
confirmSex(e){
console.log(e.currentTarget.dataset.item)
let item = e.currentTarget.dataset.item
this.setData({
sex : item.value,
sexdisp: item.name,
showsex: false
})
},
onChange({ detail }) {
this.setData({ checked: detail });
},
del(){
var userid = 0;
userid = this.data.id;
wx.showModal({
title: '',
content: '确定删除此体检人信息吗?',
cancelText:"否",
confirmText:'是',
success: function(res) {
if (res.confirm) {
util.requestForm(api.deletestudent, {
id: userid
}, "DELETE")
.then(function(res) {
if (res.code === 0) {
console.log("deletestudent res:");
console.log(res);
console.log("deletestudent resdata:");
console.log(res.data);
wx.showToast({
title: '删除成功',
icon:'success'
})
setTimeout(item => {
wx.navigateBack({
delta: 1 //返回上一级页面
})
},1000)
}
});
}
}
})
},
save(){
//是否默认体检人
if(this.data.checked == true){
this.setData({
type:0
})
}else{
this.setData({
type:1
})
}
// let relate = this.data.relateId
// let cardType = this.data.cardV
// let medical_card = this.data.carNum
let that = this;
let cardNum = this.data.idCard
let type = this.data.type
let hzxm =this.data.trueName
let sex = this.getSexFromIdCard(this.data.idCard)
let age = this.calculateAge(this.data.idCard)
let userid = this.data.id;
let classid = this.data.xytjinfo.classid;
let classname = this.data.xytjinfo.classname;
let schoolname = this.data.xytjinfo.schoolname;
console.log(hzxm)
console.log(cardNum)
console.log(type)
console.log(sex)
console.log(age)
console.log(this.data.state)
//state 0 -- 新增
if(this.data.state == 0){
if(cardNum ==''){
wx.showModal({
content: '请填写完整身份证号码',
showCancel: false,
})
}else{
util.requestPost(api.createstudent, {
openid: app.globalData.openId,
defaultflag: type,
name: hzxm,
sex: sex,
age: age,
deptId: classid,
className: classname,
schoolName: schoolname,
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);
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);
wx.showToast({
title: '添加成功',
icon:'success'
})
setTimeout(item => {
wx.navigateBack({
delta: 1 //返回上一级页面
})
},1000)
}
else{
wx.showToast({
title: res.msg,
icon:'error'
})
}
});
}
}else{
//如果已经是默认体检人,不允许改变,需要先设置其他人为默认
console.log("默认 体检人");
console.log(app.globalData.gnationId);
if(type == 1 && (app.globalData.gnationId === cardNum) ){
wx.showModal({
content: '至少一个人为默认体检人',
showCancel: false,
})
}else{
wx.showModal({
title: '',
content: '确定更改此体检人信息吗?',
cancelText:"否",
confirmText:'是',
success: function(res) {
if (res.confirm) {
util.requestPost(api.updatestudent, {
openid: app.globalData.openId,
defaultflag: type,
name: hzxm,
sex: sex,
nationId: cardNum,
id: userid,
deptId: classid,
className: classname,
schoolName: schoolname,
age: age
})
.then(function(res) {
if (res.code === 0) {
console.log("updatestudent res:");
console.log(res);
console.log("updatestudent resdata:");
console.log(res.data);
console.log(hzxm)
console.log(cardNum)
console.log(type)
console.log(sex)
console.log(age)
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;
}
wx.showToast({
title: '编辑成功',
icon:'success'
})
setTimeout(item => {
wx.navigateBack({
delta: 1 //返回上一级页面
})
},1000)
}
else{
wx.showToast({
title: res.msg,
icon:'error'
})
}
});
}
}
})
}
}
},
linkUser:function(gname, xPatid){
//第二步 关联到父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: '1',
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;
}
}
})
},
checkUser(gname, gnationId){
let that = this;
//查档
wx.request({
url:'https://fy.btlsoln.com:8443/his/getPatient?cardno&cardtype&hzxm',
method:"GET",
data:{
cardno: gnationId,
cardtype: '4', //只支持身份证建档
hzxm: gname
},
header: {
'content-type': 'application/json'
},
success: (res)=> {
if(res.data.errCode == 0){
console.log(res.data,'exist user')
console.log(res.data.list[0].brzt,'exist user')
if(res.data.list[0].brzt == 'R'){
//需要建档
//第一步 先做身份证建档
console.log("开始建档");
util.requestForm(api.addUser, {
hzxm: gname,
sfzh: gnationId,
lxdh: ''
})
.then(function(res) {
console.log(res, 'adduser res');
if (res.errCode == 0) {
console.log(res.list[0].patid, 'patid');
that.setData({
usrPatid: res.list[0].patid
})
wx.showToast({
title: '自动建档成功',
icon:'success'
})
// that.linkUser(gname, res.list[0].patid);
that.linkUser(gname, gnationId);
}
else{
wx.showToast({
title: res.errMsg,
icon:'error'
})
return false;
}
});
}
else{
//已经建档
// that.linkUser(gname, res.data.list[0].patid);
that.linkUser(gname, gnationId);
}
}else{
console.log(res.data,'error for check user')
}
},
fail: (res)=> {
console.log(res.data,'exception for check user')
return false;
}
})
},
showModal(error) {
wx.showModal({
content: error.msg,
showCancel: false,
})
},
trueName:function(e){
this.setData({
trueName:e.detail.value
})
},
change_trueName(e){
let hzxm =e.detail.value.replace(/\./g,'·')
hzxm =hzxm.replace(/\。/g,'·')
this.setData({
trueName:hzxm
})
},
zjh:function(e){
this.setData({
zjh:e.detail.value
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// url: '/pages/studentMsgDel/studentMsgDel?state='+state+'&idCard='+idCard+'&trueName='+trueName+'&type='+type +'&sex='+sex +'&age='+age+'&state='+state,
console.log(options,"编辑")
this.setData({
state:options.state,
id: options.id
})
if(options.sex == 1){
this.setData({
sexdisp: '男'
})
}else if(options.sex == 2){
this.setData({
sexdisp: '女'
})
}
if(options.type == 0){
this.setData({
checked:true,
type: 0
})
}else {
this.setData({
checked:false,
type: 1
})
}
if(options.state == 0){
this.setData({
title:"添加体检人"
})
}else{
this.setData({
title:"编辑体检人",
trueName:options.trueName,
idCard:options.idCard,
sex:options.sex,
age:options.age,
id: options.id,
schoolname: options.schoolname,
classname: options.classname,
disabled:"disabled"
})
}
//设置值
this.data.xytjinfo.schoolname = options.schoolname;
this.data.xytjinfo.classname = options.classname;
this.data.xytjinfo.classid = options.classid;
this.schoolList();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
wx.setNavigationBarTitle({
title: this.data.title
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
//班级
classList: function() {
var that = this;
util.request(api.deptinfo, {
parentid: this.data.parentid
})
.then(function(res) {
if (res.code === 0) {
console.log("classinfo res:");
console.log(res);
console.log("classinfo resdata:");
console.log(res.data);
that.setData({
classxpList: res.data,
classxpListBackup: res.data
});
}
});
},
//开启控件
classOn: function(){
this.setData({
classSwitch: true
})
},
//关闭控件
classShutdown: function(){
let List = [];
this.setData({
classSwitch: false
})
//恢复数据
for(let i = 0;i < this.data.classxpListBackup.length;i++){
List.push(this.data.classxpListBackup[i]);
}
this.setData({
classxpList: List,
classIndexes: ''
})
},
//条件输入事件
setclassIndexes(event){
this.setData({
classIndexes: event.detail,
});
console.log("classIndexes:" + event.detail)
},
//点击确定搜索时触发事件
classGo: function(){
wx.showToast({
title: '加载中',
icon: "loading",
duration: 1000
})
let row = [];
if(this.data.classIndexes){
this.data.classxpListBackup.forEach((item) => {
if (item.name.indexOf(this.data.classIndexes) > -1) {
row.push(item);
}
});
}else{
row = this.data.classxpListBackup
}
this.setData({
classcurrent: this.data.classIndexes,
classxpList: row
})
},
//用户选择某个选项后触发事件
classIdentification(event){
let List = [];
let Backups = this.data.classxpListBackup;
let id = event.detail.value.id;
console.log("pick select value:");
console.log(event.detail.value);
console.log("pick select id:" + event.detail.index);
this.data.xytjinfo.classid = event.detail.value.id;
this.data.xytjinfo.classname = event.detail.value.name;
this.setData({ classname: event.detail.value.name });
//根据选择的id获取下一级结构
// this.setData({ deptid: event.detail.value.id});
// this.studentList();
console.log("set select classid:" + this.data.xytjinfo.classid);
console.log("set select classname:" + this.data.xytjinfo.classname);
for(let i = 0;i < Backups.length;i++){
List.push(Backups[i]);
}
this.setData({
classxpList: List,
})
console.log("pick after list:");
console.log(this.data.classxpList);
console.log("pick after list backup");
console.log(this.data.classxpListBackup);
this.classShutdown();
},
//学校
schoolList: function() {
var that = this;
util.request(api.deptinfo, {
parentid: this.data.parentid
})
.then(function(res) {
if (res.code === 0) {
console.log("schoolinfo res:");
console.log(res);
console.log("schoolinfo resdata:");
console.log(res.data);
that.setData({
schoolxpList: res.data,
schoolxpListBackup: res.data
});
}
});
},
//开启控件
schoolOn: function(){
this.setData({
schoolSwitch: true
})
},
//关闭控件
schoolShutdown: function(){
let List = [];
this.setData({
schoolSwitch: false
})
//恢复数据
for(let i = 0;i < this.data.schoolxpListBackup.length;i++){
List.push(this.data.schoolxpListBackup[i]);
}
this.setData({
schoolxpList: List,
schoolIndexes: ''
})
},
//条件输入事件
setschoolIndexes(event){
this.setData({
schoolIndexes: event.detail,
});
console.log("schoolIndexes:" + event.detail)
},
//点击确定搜索时触发事件
schoolGo: function(){
wx.showToast({
title: '加载中',
icon: "loading",
duration: 1000
})
let row = [];
if(this.data.schoolIndexes){
this.data.schoolxpListBackup.forEach((item) => {
if (item.name.indexOf(this.data.schoolIndexes) > -1) {
row.push(item);
}
});
}else{
row = this.data.schoolxpListBackup
}
this.setData({
schoolcurrent: this.data.schoolIndexes,
schoolxpList: row
})
},
//用户选择某个选项后触发事件
schoolIdentification(event){
let List = [];
let Backups = this.data.schoolxpListBackup;
let id = event.detail.value.id;
console.log("pick select value:");
console.log(event.detail.value);
console.log("pick select id:" + event.detail.index);
this.data.xytjinfo.schoolid = event.detail.value.id;
this.data.xytjinfo.schoolname = event.detail.value.name;
this.setData({ schoolname: event.detail.value.name });
//根据选择的id获取下一级结构
this.setData({ parentid: event.detail.value.id});
this.classList();
console.log("set select schoolid:" + this.data.xytjinfo.schoolid);
console.log("set select schoolname:" + this.data.xytjinfo.schoolname);
for(let i = 0;i < Backups.length;i++){
List.push(Backups[i]);
}
this.setData({
schoolxpList: List,
})
console.log("pick after list:");
console.log(this.data.schoolxpList);
console.log("pick after list backup");
console.log(this.data.schoolxpListBackup);
this.schoolShutdown();
},
// 从身份证号码中提取性别信息
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 || '';
},
// 调用示例
// const idCardNumber = 'xxxxxxxxx'; // 输入真实的身份证号码
// console.log(calculateAge(idCardNumber));
})