// packageA/pages/preDocumented/preDocumented.js
const networkUtil = require("../../../utils/network_util.js");
const api = require("../../../utils/apiFile.js");
const makePy = require("../../../utils/makepy.js");
const numberUtil = require("../../../utils/numberUtil.js");
import { AreaPicker } from "../../../utils/areaSelector/selector.js"
let liveType = "";
let hospitalId;
Page(Object.assign({}, AreaPicker,{
data: {
postObj: {},
queryData:{},
currentAddress: {},
currentAddress1: {},
sex:[
{
name:"男",
value:1,
checked:true
},
{
name:"女",
value:0,
checked:false
},
],
childCardShow: false,
items: [
{value: 'wr', name: '未入', checked: 'true'},
{value: 'yr', name: '已入'},
],
liveTypes: ['常住','流动','暂住','有居住证'],
liveTypestr: [
{
"id":"57624c440cf23d4631523ea1",
"code":"bd",
"enable":1,
"parentId":"57624c330cf23d4631523ea0",
"name":"常住",
"parentName":null,
"desc":null,
"level":null,
"weight":null,
"leastUse":null,
"basicConfigs":[
],
"childConfigs":null
},
{
"id":"57624c5e0cf23d4631523ea2",
"code":"wd",
"enable":1,
"parentId":"57624c330cf23d4631523ea0",
"name":"流动",
"parentName":null,
"desc":null,
"level":null,
"weight":null,
"leastUse":null,
"basicConfigs":[
],
"childConfigs":null
},
{
"id":"5a371bce0cf2ab082ac30433",
"code":"bdcz",
"enable":1,
"parentId":"57624c330cf23d4631523ea0",
"name":"暂住",
"parentName":null,
"desc":null,
"level":null,
"weight":null,
"leastUse":null,
"basicConfigs":[
],
"childConfigs":null
},
{
"id":"62270e679932d29c07242e4f",
"code":"jzz",
"enable":1,
"parentId":"57624c330cf23d4631523ea0",
"name":"有居住证",
"parentName":null,
"desc":null,
"level":null,
"weight":null,
"leastUse":null,
"basicConfigs":[
],
"childConfigs":null
}
],
quality:[
{
name:"农业",
value:1,
checked:false
},
{
name:"非农业",
value:2,
checked:false
},
],
selectedChild:{},
isChooseBox:true,
//页面显示 1 新增建档 2 查看建档
showViewType:0,
hospitals:[],
SearchHospitals:[],
pickerBoxModal:true,
endDate:'',
submiting:false
},
onLoad: function (options) {
hospitalId = options.hospitalId;
var that = this;
networkUtil.showLoading()
networkUtil._get(api.getConfigHospitals,{}, function(res) {
if(0 == res.data.errorcode){
that.setData({
hospitals:res.data.data,
selectHospital: {}, //{'hospitalId':216,'hospitalName':'秦皇岛市妇幼保健院'},
'queryData.hospital': {} //{'hospitalId':216,'hospitalName':'秦皇岛市妇幼保健院'}
})
if (hospitalId!==null&&hospitalId!==undefined&&hospitalId!==""&&hospitalId===2100001605) {
that.setData({
selectHospital: {'hospitalId':2100001605,'hospitalName':'隆化县妇幼保健院'},
'queryData.hospital': {'hospitalId':2100001605,'hospitalName':'隆化县妇幼保健院'}
})
}
}
}, function(res) {
networkUtil.showErrorToast(res.errormsg)
})
var date = new Date();
var nowMonth = date.getMonth() + 1;
var strDate = date.getDate();
// 日期分割符号
var seperator = "-";
that.setData({
endDate:date.getFullYear() + seperator + nowMonth + seperator + strDate
})
wx.onKeyboardHeightChange(res => {
console.log(res.height)
this.setData({
bottom:res.height
})
})
},
bindPickerChange: function(e) {
let type = this.data.liveTypes[e.detail.value];
for (var i in this.data.liveTypestr) {
if (type === this.data.liveTypestr[i].name) {
liveType = this.data.liveTypestr[i].id;
}
}
this.setData({
index: e.detail.value
})
},
bindDateChange(e){
let value = e.detail.value;
this.setData({
['postObj.birth']: value
})
},
bindKeyInput(e) {
let key = e.currentTarget.id;
let value = e.detail.value;
this.setData({
['postObj.' + key]: value
})
},
checkboxChange (e) {
const items = this.data.items
const values = e.detail.value
for (let i = 0, lenI = items.length; i < lenI; ++i) {
items[i].checked = false
for (let j = 0, lenJ = values.length; j < lenJ; ++j) {
if (items[i].value === values[j]) {
items[i].checked = true
break
}
}
}
this.setData({
items
})
},
radioChange(e) {
let value = e.detail.value;
this.setData({
['postObj.sex']: value
})
},
radioChange1(e) {
let childCardShow = e.detail.value;
if (childCardShow==='yr') {
childCardShow = true;
} else {
childCardShow = false;
}
this.setData({
childCardShow: childCardShow
})
},
radioChange2(e) {
let value = e.detail.value;
this.setData({
['postObj.babyAccountNature']: value
})
},
bindQueryInput(e) {
// console.log(e)
let key = e.currentTarget.id;
let value = e.detail.value;
this.setData({
['queryData.' + key]: value
})
},
fouseSearchHospital(e){
let resultArr = this.data.SearchHospitals
if(this.data.SearchHospitals.length == 0){
resultArr = this.data.hospitals;
}
this.setData({
pickerBoxModal:false,
SearchHospitals:resultArr,
'queryData.hospital':resultArr[0],
})
},
bindSearchHospital(e){
let value = e.detail.value;
let that = this;
let resultArr = [],arr = that.data.hospitals,col='hospitalName';
for(var i= 0, searchText, tmp; i<arr.length; i++) {
tmp = arr[i];
if("object" == typeof(tmp)) {
searchText = String(tmp[col]);
searchText += makePy._makePy(searchText);
searchText = searchText.toLowerCase();
value = value.toLowerCase();
if(-1 != searchText.indexOf(value)) {
resultArr.push(tmp);
}
}
}
if(resultArr.length == 0){
that.setData({
pickerBoxModal:false,
SearchHospitals:resultArr,
'selectHospital.hospitalId': 0,
'queryData.hospital':{},
})
}else{
that.setData({
pickerBoxModal:false,
SearchHospitals:resultArr,
'selectHospital.hospitalId': 0,
'queryData.hospital':resultArr[0],
})
}
},
bindHospitalChange(e){
let value = e.detail.value;
let that = this;
// console.log(value)
this.setData({
selectHospital: that.data.SearchHospitals[value]
})
},
confirmSelect(){
if(this.data.selectHospital.hospitalId&&this.data.selectHospital.hospitalId!=0){
this.setData({
pickerBoxModal:true,
'queryData.hospital': this.data.selectHospital
})
}else(
this.setData({
pickerBoxModal:true,
selectHospital: this.data.queryData.hospital
})
)
},
query(){
let value = this.data.queryData.phone;
let hospital = this.data.queryData.hospital;
var that = this;
if(!(value&&numberUtil.IsTelPhoneNumber(value))){
wx.showModal({
title: '提示',
content: '请输入正确的母亲手机号!',
showCancel: false,
})
return
}
if(!hospital.hospitalId){
wx.showModal({
title: '提示',
content: '请选择建档机构!',
showCancel: false,
})
return
}
this.setData({
pickerBoxModal:true,
postObj:{}
})
networkUtil.showLoading()
var query = {phone:value,hospitalId:0}
query.hospitalId = hospital.hospitalId;
networkUtil._get(api.getBabyAppBuildInfo,query, function(res) {
if(0 == res.data.errorcode){
if(res.data.data.length>1){
that.setData({
childList : res.data.data,
isChooseBox : false
})
}else{
let postObj = res.data.data[0];
if (postObj) {
postObj.liveType = "";
}
that.setData({
postObj : postObj,
showViewType:1
})
}
}
}, function(res) {
networkUtil.showErrorToast(res.errormsg)
})
},
onAreaCommit(locationList, e) {//当用户更换地区
// console.log('选择地址后', locationList)
var self = this;
self.addrInfo = {
province: locationList[0] || {},
city: locationList[1] || {},
area: locationList[2] || {},
street: locationList[3] || {},
}
var address = {}
address.details = ''
for (var i in locationList){
address.details += locationList[i].name
}
address.addEntry = locationList
if (e.target.dataset.name == 'currentAddress') {
self.setData({
isShow: 0,
currentAddress: address
});
} else if (e.target.dataset.name == 'currentAddress1') {
self.setData({
isShow: 0,
currentAddress1: address
});
}
},
checkForm(postData){
let flag = true;
var data = postData;
var value = "";
if(!data.mommyCardNo){
flag = false;
value += "母亲姓名 "
}
if(data.mommyCardNo&&!numberUtil.checkIdCard(data.mommyCardNo,'woman')){
flag = false;
value += "母亲身份证号码 "
}
if(!(data.phone&&numberUtil.IsTelPhoneNumber(data.phone))){
flag = false;
value += "母亲手机号 "
}
if(!data.liveType){
flag = false;
value += "居住属性 "
}
if(!data.babyName){
flag = false;
value += "儿童姓名 "
}
if (this.data.childCardShow) {
if(data.babyCard&&!numberUtil.validateIdCard(data.babyCard)){
flag = false;
value += "儿童身份证号码 "
}
}
if(!data.birth){
flag = false;
value += "出生日期 "
}
if(!data.sex){
flag = false;
value += "儿童性别 "
}
if(!data.height){
flag = false;
value += "儿童出生身长 "
}
if(!data.weight){
flag = false;
value += "儿童出生体重 "
}
if(!this.data.currentAddress.addEntry) {
flag = false;
value += "户籍地址 "
}
if(!data.babyAddress) {
flag = false;
value += "街道门牌 "
}
return {
flag:flag,
value:value
};
},
submitData () {
let that = this;
if (that.data.postObj!==undefined&&that.data.postObj!==null&&that.data.postObj!=='') {
if ((that.data.postObj.sINCard===undefined||that.data.postObj.sINCard===null||that.data.postObj.sINCard==='')&&(that.data.postObj.vcCardNo===undefined||that.data.postObj.vcCardNo===null||that.data.postObj.vcCardNo==='')) {
wx.showModal({
title: '提示',
content: '社保卡和就诊卡尽量填写一项!',
confirmText: '填写卡号',
cancelText: '直接保存',
success (res) {
if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
that.submitDataArchives()
}
}
})
} else {
that.submitDataArchives()
}
}else {
wx.showToast({
title: '请填写表单!',
icon: 'error',
duration: 2000
})
}
},
submitDataArchives() {
let hospital = this.data.queryData.hospital;
let postData = this.data.postObj;
postData.liveType = liveType;
postData.hospitalId = hospital.hospitalId;
if (this.data.currentAddress) {
if (this.data.currentAddress.addEntry) {
postData.babyProvinceId = this.data.currentAddress.addEntry[0].id;
postData.babyCityId = this.data.currentAddress.addEntry[1].id;
postData.babyAreaId = this.data.currentAddress.addEntry[2].id;
postData.babyStreetId = this.data.currentAddress.addEntry[3].id;
}
}
if (this.data.currentAddress1) {
if (this.data.currentAddress1.addEntry) {
postData.provinceId = this.data.currentAddress1.addEntry[0].id;
postData.cityId = this.data.currentAddress1.addEntry[1].id;
postData.areaId = this.data.currentAddress1.addEntry[2].id;
postData.streetId = this.data.currentAddress1.addEntry[3].id;
}
}
if (postData.vcCardNo===null) {
delete postData.vcCardNo;
}
if (postData.sINCard===null) {
delete postData.sINCard;
}
var key = this.checkForm(postData);
var that = this;
if(key.flag){
this.setData({
submiting:true
})
// console.log(postData)
networkUtil._post(api.addBuildArticle, postData , (res)=> {
if (0===res.data.errorcode) {
wx.showModal({
title: '成功提交',
content: "您的建档信息已提交,请尽快前往我院建档中心进行档案审核,审核通过后请使用档案信息登录,为避免错过重要医疗信息,审核通过后请使用档案信息登录小程序并持续关注美生孕育公众号。",
showCancel: false,
submiting:false,
success: function (res){
that.setData({
babyInfo:postData,
'babyInfo.hospitalName':that.data.queryData.hospital.hospitalName,
showViewType:2
})
}
})
} else {
wx.showModal({
title: '提交失败',
content: '错误信息:'+res.errormsg,
showCancel: false,
success: function (res) {
}
})
}
}, function (res) {
wx.showModal({
title: '提交失败',
content: '错误信息:'+res.errormsg,
showCancel: false,
success: function (res) {
}
})
},'application/json')
}else{
wx.showModal({
title: '表单填写不规范',
content: "这些项目未正确填写:"+key.value,
showCancel: false,
success: function (res) {
}
})
}
}
}))