var msgId, patiCode; var groupCode = [], groupName = [], healthManagementCode=[], healthManagementName=[], diseaseCode=[], diseaseName=[]; var type, self, signStatus; var hzCode=""//患者CODE var signType=1 var signedData = null; //添加服务类型的数据 var currService; var refuseReason = "";//拒绝签约原因 // 居民标签 var $juminLabels = $('#jumin_labels input[data-val=jumin_labels]'); var docInfo; mui.init(); mui.plusReady(function() { plus.nativeUI.showWaiting(); self = plus.webview.currentWebview(); msgId = self.msgId; patiCode = self.patiCode; type = self.type; signStatus = self.signStatus; var status = self.status; docInfo = JSON.parse(plus.storage.getItem("docInfo")); initPage(); bindEvents(); }); function initPage(){ console.log("signStatus = "+signStatus); if(signStatus == 1 || signStatus == 8 || signStatus == 9) { //签约 $(".demo-comtop").find("h1").text("签约处理"); $('#btn_refuse').text("拒绝签约"); $('#btn_agree').text("同意签约"); var promise1 = getReqPromises([{url:"/doctor/family_contract/patient_signing",data:{patient: patiCode}}, // {url:"/doctor/patient/disease_sanshi",data:{patient: patiCode}}, // {url:"/doctor/family_contract/getSanshiSign",data:{patientCode:patiCode}}, {url:"/doctor/admin-teams/team/"+ docInfo.code +"/teamsLimit",data:{},reqType: 'GET'},//获取签约团队 {url:"/common/getDictByDictName?name=SIGN_EXPENSES",data:{},reqType: 'GET'},//设置政府补贴 {url:"/doctor/sign/getSigndict", data:{}, reqType: "GET"}]);//获取服务团队的信息 console.log(promise1); return promise1.then(function(datas){ console.log(datas); var data0 = datas[0], data1 = datas[1], data2 = datas[2], data3 = datas[3]; // data4 = datas[4]; // data5 = datas[5]; // setApplyData(data0,data1); // initData(1,data2); // getQytd(data3); // setExpenses(data4); // fillServiceDropdown(data5); setApplyData(data0); getQytd(data1); setExpenses(data2); fillServiceDropdown(data3); //改签获得历史签约团队 if(signStatus == 9){ getHisSignInfo(); } $("#div_qianyue").removeClass("c-hide"); $("#div_jieyue").addClass("c-hide"); $('.c-main').removeClass('c-hide'); plus.nativeUI.closeWaiting(); }).catch(function(e) { console && console.error(e); }); } else if(signStatus == 4) { //解约 $(".demo-comtop").find("h1").text("解约处理"); $('#btn_refuse').text("拒绝解约"); $('#btn_agree').text("同意解约"); if(self.reason) { $("#div_jieyue").find("textarea").val(self.reason); } else { $("#div_jieyue").find("textarea").attr("placeholder", "该居民无说明解约理由") } // 解约申请时间 var applyUnsignDate = ""; var promise2 = getReqPromises([{url:"/doctor/patient_group/patient",data:{code: patiCode}},//居民信息 {url:"/doctor/family_contract/getSanshiSign",data:{patientCode:patiCode}}, {url:"/doctor/admin-teams/team/"+ docInfo.code +"/teamsLimit",data:{},reqType: 'GET'}, {url:"/common/getDictByDictName?name=SIGN_EXPENSES",data:{},reqType: 'GET'}, {url:"/doctor/sign/getSigndict", data:{}, reqType: "GET"}]);//获取服务团队的信息 return promise2.then(function(datas){ var data0 = datas[0], data1 = datas[1], data2 = datas[2], data3 = datas[3]; data4 = datas[4]; if(data0.status == 200) { hzCode=data0.data.code; initData(2,data1); applyUnsignDate = data0.data.jtSign.applyUnsignDate; $("#pati_info").html(template("pati_info_tmpl", data0.data)); var applySurrDate = applyUnsignDate.slice(0,16); $("#app_date").text("申请解约时间:"+applySurrDate); $('.c-main').removeClass('c-hide'); } getQytd(data2); setExpenses(data3); fillServiceDropdown(data4); $("#div_jieyue").removeClass("c-hide"); $("#div_qianyue").addClass("c-hide"); plus.nativeUI.closeWaiting(); }) } } //获得历史签约信息 function getHisSignInfo(){ var url = "/doctor/sign/getPatientSignLogInfo", params = {patient:patiCode}; sendPost(url, params, null, function(res){ if(res.status == 200){ var data = res.data, arr = []; if(data.oldHospitalName){ arr.push(data.oldHospitalName); } if(data.oldTeamName){ arr.push(data.oldTeamName); } if(data.OldLeaderName){ arr.push(data.OldLeaderName); } if(data.OldDoctorName){ arr.push(data.OldDoctorName); } if(data.OldHealthDoctorName){ arr.push(data.OldHealthDoctorName); } var text = arr.join(","); $("#teamInfo").text(text); $("#hisInfo").show(); } }); } function setApplyData (data1,data2) { if(data1){ if(data1.status == 200) { var data=data1.data, appDate = ""; if(signStatus == 1 || signStatus == 8 || signStatus == 9) { console.log(data); appDate = data.applyDate ? data.applyDate.slice(0,16): ""; $("#pati_info").html(template("pati_info_tmpl", data1.data)); $("#app_date").text("申请签约时间:"+appDate); signedData = data1.data; } }else{ mui.toast(res.msg); } } } //获取政府补贴数据 function setExpenses(res){ var expensesCode=[]; var expensesName=[]; if(res.status == 200) { var expensesList = res.list; for(var i = 0; i < expensesList.length; i++) { expensesCode.push(expensesList[i].code); expensesName.push(expensesList[i].value); } activExpensesM(expensesCode,expensesName); }; } //设置政府补贴下拉框 function activExpensesM(expensesCodes,expensesNames) { var $expensesInput = $('#li_expenses input[data-val=expenses]'); $expensesInput.mobiscroll({ theme: 'ios', lang: 'zh', customWheels: true, wheels: [ [{ keys: [expensesCodes[1],expensesCodes[0],expensesCodes[3],expensesCodes[2]], values: [expensesNames[1],expensesNames[0],expensesNames[3],expensesNames[2]] }] ], onSelect: function(valueText, inst) { var dd = eval("[" + valueText + "]"); var name=dd[0].values $(this).val(name); currExpenses = dd[0].keys; $('#li_expenses input[data-val=expenses]').attr("data-code",currExpenses); } }); // 获取政府补贴下拉框mibiscroll实例 var expensesMobiscroll = $expensesInput.mobiscroll('getInst'); var valueText = "{keys:'"+expensesCodes[0]+"',values:'"+expensesNames[0]+"'}"; expensesMobiscroll.setVal([valueText]); $expensesInput.val(expensesNames[0]); $expensesInput.attr("data-code",expensesCodes[0]); } //普通 老年 高血 糖尿 孕妇 儿童 贫困 计生 重性 残疾 结核 function filterSer(name){ var $li = $('.dw-bf').find('div.dw-li'); $li.addClass('dw-v'); var nameArr = name.split(','); $.map(nameArr,function(item,index){ if(item.trim() == '普通人群'){ var arr = [2,3,6,7,8,9,10] $.map(arr,function(it,index){ $li.eq(it).removeClass('dw-v') }) } if(item.trim() == '老年人'){ var arr = [4,5] $.map(arr,function(it,index){ $li.eq(it).removeClass('dw-v') }) } if(item.trim() == '高血压' ||item.trim() == '糖尿病'||item.trim() == '贫困人口'||item.trim() == '计生特殊人群'||item.trim() == '重性精神疾病'||item.trim() == '残疾人'||item.trim() == '结核病' ){ var arr = [0] $.map(arr,function(it,index){ $li.eq(it).removeClass('dw-v') }) } if(item.trim() == '0-6岁儿童'){ var arr = [1,4] $.map(arr,function(it,index){ $li.eq(it).removeClass('dw-v') }) } if(item.trim() == '孕产妇'){ var arr = [1,5] $.map(arr,function(it,index){ $li.eq(it).removeClass('dw-v') }) } }) } //设置服务类型下拉 function fillServiceDropdown(data){ var $serviceSel = $('#selFuwu'), data = data.data, html=""; for(i=0; i'+data[i].name+'' } $serviceSel.html(html); $serviceSel.mobiscroll().select({ theme: 'ios', lang: 'zh', display: 'bottom', rows:6, placeholder:'请选择服务类型', onSelect: function ( valueText, inst) { // var vArr = valueText.split(','); //判断服务类型是否变更 $juminLabels.val("").attr("data-code",JSON.stringify({health: "",disease: "", custom: "" })); currService = inst._tempValue?inst._tempValue.join(','):''; }, onChange: function (event, inst) { filterSer(event) }, onShow: function (event, inst) { filterSer(inst) } }) } function validForm(){ if(!$('#agreement_checkbox').hasClass('checked')) { mui.toast("您还未接受签约协议"); return false; } if(!$.trim($doctorQytdInput.attr("data-code"))){ mui.toast("请选择签约团队!"); return false; } if($("#healthManagement input").val()==""){ mui.toast("请选择健康管理师!"); $("#btn_agree").attr("disabled",false); return false; } if(!currService){ mui.toast("请选择服务类型!"); return false; } var labelObj = $juminLabels.attr("data-code"); labelObj = JSON.parse(labelObj); if(!labelObj.health) { mui.toast("请选择居民标签!"); return false; } return true; } //分组选择 var currGroupCode;//分组 不要了! var currdiseaseCode;// 病种类型CODE var currfamilyDoctorCode;//家庭医生CODE var currfamilyDoctorName;//家庭医生名字 var currHealthManagement; var currHealthManagementname; function bindEvents(){ //选择医生 $("#doctor_zk input").on("click",function(){ mui.openWindow('../../huanzhe/html/hospital_qianyue.html', 'hospital_qianyue', { }); }); $('#healthManagement input').on('tap', function(){ mui.confirm('请先选择签约团队', "提示", ["确定"], function(){}); }) //选择分组 $("body").on("click","#li_group",function(){ mui.openWindow({ url:"xiaoxichuli_fzgl.html", id:"xiaoxichuli_fzgl.html" }) }); //同意、拒绝 var signUrl = "doctor/family_contract/sign"; //签约 var surrUrl = "doctor/family_contract/surrender"; //解约 $("#btn_agree").click(function() { //同意 if($("#btn_agree").attr("disabled")){ return false; } $("#btn_agree").attr("disabled",true); currHealthManagementName=$("#healthManagement input").val()//医生姓名 var patientIDcard=$("#idcard").html()//身份证 //console.log(currHealthManagementName) if(signStatus == 1 || signStatus == 8 || signStatus == 9) { var val = $("input").val().trim(); var isValid = validForm(); if(!isValid){ $("#btn_agree").attr("disabled",false); return; } var juminLabels = JSON.parse($juminLabels.attr("data-code")); sendPost(signUrl, { signType:signType, majorDoctor:$("#doctor_zk input").attr("data-code"), majorDoctorName:$("#doctor_zk input").val(), healthLabel: juminLabels.health, customLabel: juminLabels.custom, disease: juminLabels.disease, patientIDcard:patientIDcard, adminTeamCode: $doctorQytdInput.attr("data-code"), msgid: msgId, patient: patiCode, healthDoctor:$("#healthManagement input").attr("data-code"), healthDoctorName:$("#healthManagement input").val(), type: 1, expenses:$("#li_expenses input").attr("data-code"), group:$("#li_group input").attr("data-code"), //添加服务类型数据 sevId: currService }, function(){ $("#btn_agree").attr("disabled",false); mui.toast("系统异常!"); }, function(res) { $("#btn_agree").attr("disabled",false); if(res.status == 200) { mui.toast("签约成功!"); mui.fire(self.opener(), "updata"); var xxWv = plus.webview.getWebviewById("xiaoxi.html"); if(xxWv) { mui.fire(xxWv, "updateQy"); } var hzWv = plus.webview.getWebviewById("huanzhe.html"); if(hzWv) { mui.fire(hzWv, "update"); } var mainWv = plus.webview.getWebviewById("main"); if(mainWv) { mui.fire(mainWv, "xSxS"); } mui.later(function() { mui.back(); }, 500) }else if(res.status==-2||res.status==-3||res.status==-4){ mui.confirm(res.msg, "提示", ["我知道了"], function(){ mui.fire(self.opener(),"updata"); var xxWv = plus.webview.getWebviewById("xiaoxi.html"); if(xxWv) { mui.fire(xxWv, "updateQy"); } var hzWv = plus.webview.getWebviewById("huanzhe.html"); if(hzWv) { mui.fire(hzWv, "update"); } var mainWv = plus.webview.getWebviewById("main"); if(mainWv) { mui.fire(mainWv, "xSxS"); } mui.back(); }); } else { mui.toast(res.msg); } }); } else if(signStatus == 4) { console.log(msgId+" "+patiCode) sendPost(surrUrl, { msgid: msgId, patient: patiCode, healthLabel:"", adminTeamCode:0, type: 1 }, null, function(res) { $("#btn_agree").attr("disabled",false); // alert(JSON.stringify(res)) if(res.status == 200) { mui.toast("解约成功!"); mui.fire(self.opener(), "updata"); var xxWv = plus.webview.getWebviewById("xiaoxi.html"); if(xxWv) { mui.fire(xxWv, "updateQy"); } var hzWv = plus.webview.getWebviewById("huanzhe.html"); if(hzWv) { mui.fire(hzWv, "update"); } var mainWv = plus.webview.getWebviewById("main"); if(mainWv) { mui.fire(mainWv, "mainupdate"); } mui.later(function() { mui.back(); }, 500) } else { mui.toast(res.msg); } }); } }); $("#btn_refuse").click(function() { //拒绝 refuseReason = $('#refuseReason').val(); if($("#btn_refuse").attr("disabled")){ return false; } $("#btn_agree").attr("disabled",true); var patientIDcard=$("#idcard").html() if(signStatus == 1) { sendPost(signUrl, { patientIDcard:patientIDcard, // group: "", msgid: msgId, patient: patiCode, adminTeamCode:0, type: 2, refuseReason: refuseReason }, function(res){ alert("请求出错"); //alert(JSON.stringify(res)) }, function(res) { if(res.status == 200) { mui.toast("已拒绝签约!"); mui.fire(self.opener(), "updata"); var xxWv = plus.webview.getWebviewById("xiaoxi.html"); if(xxWv) { mui.fire(xxWv, "updateQy"); } var mainWv = plus.webview.getWebviewById("main"); if(mainWv) { mui.fire(mainWv, "mainupdate"); } mui.later(function() { mui.back(); }, 500) } else { mui.toast(res.msg); } }); } else if(signStatus == 4) { sendPost(surrUrl, { msgid: msgId, patient: patiCode, type: 2 }, null, function(res) { if(res.status == 200) { mui.toast("已拒绝解约!"); mui.fire(self.opener(), "updata"); var xxWv = plus.webview.getWebviewById("xiaoxi.html"); if(xxWv) { mui.fire(xxWv, "updateQy"); } var mainWv = plus.webview.getWebviewById("main"); if(mainWv) { mui.fire(mainWv, "mainupdate"); } mui.later(function() { mui.back(); }, 500) } else { mui.toast(res.msg); } }); } }); // 点击家庭医生签约协议(勾选框) $(document.body).on('click', '#agreement_checkbox', function() { $(this).toggleClass("checked"); }) // 选择居民标签 .on("click","#jumin_labels",function(){ var teamCode = $('#qytdNum').attr("data-code"); if($.trim(teamCode)) { //判断当前服务类型是否已经选择 if(!currService){ mui.confirm('请先选择服务类型', "提示", ["确定"], function(){}); return false; } mui.openWindow({ url:"../../huanzhe/html/disease-label-choose.html", id:"disease-label-choose", extras: { teamCode: teamCode, showData: $juminLabels.attr("data-code") || null, patientCode: patiCode, serviceCode: currService } }) } else { mui.confirm('请先选择签约团队', "提示", ["确定"], function(){ }); } }); window.addEventListener('getDoctor', function(event) { console.log(event.detail.name) $("#doctor_zk input").val(event.detail.name); $("#doctor_zk input").attr("data-code",event.detail.code); // console.log(event.detail.code); // console.log(event.detail.name); }); window.addEventListener("group", group); /*居民标签*/ window.addEventListener("setJuMinLabels", function setJuMinLabels(e) { var health = e.detail.health, disease = e.detail.disease, custom = e.detail.custom, labelName = e.detail.labelName; $juminLabels.val(labelName).attr("data-code",JSON.stringify({health: health,disease: disease, custom: custom })); }); $("textarea").on("input", function(){ var text = $(this).val().trim(), len = text.length; $("#count").text(len); }); //选择拒绝签约说明文本,直接将内容添加到textarea中 $("#explain").on('click', '.text-tag', function(){ var $this = $(this), text = $this.text(), tatext = $("textarea").val(); if($this.hasClass("active")){ $this.removeClass("active"); var a = tatext.split(text); tatext = a.join(""); $("textarea").val(tatext); $("#count").text(tatext.length); }else{ $this.addClass("active"); tatext += text; $("textarea").val(tatext); $("#count").text(tatext.length); } }); } function activHealthM(codes, names) { healthManagementCode = codes; healthManagementName = names; $('#healthManagement input[data-val=healthManagement]').mobiscroll({ theme: 'ios', lang: 'zh', customWheels: true, wheels: [ [{ keys: healthManagementCode, values: healthManagementName }] ], onSelect: function(valueText, inst) { var dd = eval("[" + valueText + "]"); var name=dd[0].values $(this).val(name); currHealthManagement = dd[0].keys; $('#healthManagement input[data-val=healthManagement]').attr("data-code",currHealthManagement); } }); }; function initData(type,res){ var data=res.data; console.log(JSON.stringify(data)) /*if(data.hasSanshi=="true"){ signType=type $(".no").show() //$("#healthManagement input").val(data.glsName).attr({"data-code":data.glsCode});//健康医生 }*/ }//判断是不是三师已经签约 回填 /*分组事件*/ function group(e) { var groupcode=e.detail.code var groupName=e.detail.name //console.log(groupName) $('#li_group input[data-val=li_group]').val(groupName).attr("data-code",groupcode) } //获取签约团队 function getQytd(res){ if(res.status == 200) { if(res.data.length == 0){ alert("查无签约团队"); return; } var teams = res.data, teamCodes=[], teamNames=[]; // 萃取数组对象中code、name,返回一个数组 teamCodes = _.pluck(teams, 'id'); // teamNames = _.pluck(teams, 'name'); for(var i = 0; i < teams.length; i++){ var signTeam; var signCount = teams[i].signCount; var signLimitNumber = teams[i].signLimitNumber; if(signCount >= signLimitNumber){ signTeam = teams[i].name + "(已达上限)"; }else{ signTeam = teams[i].name + "(已签约"+signCount+"人)"; } teamNames.push(signTeam); } qytdSelect(teamCodes, teamNames); } } //var $doctorQytdInput = $('#qytd input'); var $doctorQytdInput = $('#qytdNum'); // 设置团队下拉框 function qytdSelect(teamCodes, teamNames) { $doctorQytdInput.mobiscroll({ theme: 'ios', lang: 'zh', customWheels: true, wheels: [ [{ keys: teamCodes, values: teamNames }] ], onSelect: function(valueText, inst) { var valueTextZy = valueText.replace("", ""); var dd = eval("[" + valueTextZy + "]"), name=dd[0].values, currExpenses = dd[0].keys; $(this).html(name); $(this).removeClass("c-9e9e9e"); var isFilled = $(this).find("span").hasClass("filled"); if(isFilled){ $('#btn_agree').addClass("disabled").attr("disabled", true); }else{ $('#btn_agree').removeClass("disabled").attr("disabled", false); } if($(this).text().length>20){ $doctorQytdInput.css({textAlign:'left'}); }else{ $doctorQytdInput.css({textAlign:'right'}); } $doctorQytdInput.attr("data-code",currExpenses); $('#healthManagement input[data-val=healthManagement]').val("").attr("data-code","") getTeamMember(currExpenses); } }); if(teamCodes.length == 1){ setQytdSelect(teamCodes[0], teamNames[0]); getTeamMember(teamCodes[0]); } } function setQytdSelect(code, name) { // 获取全科医生下拉框mibiscroll实例 var mobiscroll = $doctorQytdInput.mobiscroll('getInst'); var valueText = "{keys:'"+code+"',values:'"+name+"'}"; mobiscroll.setVal([valueText]); $doctorQytdInput.html(name); if($doctorQytdInput.html(name).toString().length>=12){ $doctorQytdInput.css({textAlign:'left'}); }else{ $doctorQytdInput.css({textAlign:'right'}); } $doctorQytdInput.attr("data-code", code); } //获取团队成员 function getTeamMember(teamCode){ plus.nativeUI.showWaiting(); sendGet("/doctor/admin-teams/"+ teamCode + "/members", {}, null, function(res){ if(res.status == 200){ var jgs= [], jgCodes =[], jgNames = []; $.each(res.data, function(i, v) { if(v.level == 3 || v.level == 2) jgs.push(v); }); // 萃取数组对象中code、name,返回一个数组 jgCodes = _.pluck(jgs, 'code'); jgNames = _.pluck(jgs, 'name'); activHealthM(jgCodes, jgNames); } else mui.toast("获取团队成员失败!"); plus.nativeUI.closeWaiting(); }) }