mui.plusReady(function(){
var docInfo = JSON.parse(plus.storage.getItem("docInfo")),
self = plus.webview.currentWebview(),
teamCode = self.teamCode?self.teamCode:'',
info= self.infoStr?JSON.parse(self.infoStr):'',
isLeader;
var $patiInfo = $('#patient-info');
var strOriginalData;//认证专用
var prescriptionCode = info?info.code:self.prescriptionCode;
//判断是否为该团队团队长
if(docInfo.isLeader && teamCode == docInfo.adminTeamCode){
isLeader = 1;
}else{
isLeader=0
}
queryData();
bindEvent();
function queryData(){
plus.nativeUI.showWaiting();
var params ={
code:prescriptionCode,
type:isLeader
}
sendPost("doctor/prescriptionInfo/getContinuedPrescriptionAsDoctor",params, function(){
plus.nativeUI.closeWaiting();
mui.toast("请求失败");
}, function(res){
plus.nativeUI.closeWaiting();
if(res.status == 200){
strOriginalData = res.data;
var html = template('pati_tmp',{data:res.data,isLeader:isLeader})
$patiInfo.html(html);
//判断团队长
if(isLeader){
$('.layer-res').show();
if(res.data.prescription.status == 0){
$('.header-link').show();
$('.header-link2').hide();
}else if(res.data.prescription.status == 2 ||res.data.prescription.status == 3){
$('.header-link2').show();
$('.header-link').hide();
}
//加载插件
if(res.data.prescription.status == 0 || res.data.prescription.status == 31){
$('.os-main').css('padding-bottom','147px')
selectFee();
selectHome();
selectResult();
nopassReason();
}else{
$('.os-main').css('padding-bottom','10px')
}
}
}else{
mui.toast("获取数据失败");
}
},'get')
}
function bindEvent(){
//选择调整平台
$(".header-link").on('tap', function(){
mui('#sheet1').popover('toggle');
})
//防止在调整中,再次请求接口
$(".header-link2").on('tap', function(){
mui.openWindow({
id: "change-chufang1",
url: "change-chufang1.html",
waiting:{autoShow:false},
extras: {
prescriptionCode:prescriptionCode,
state:strOriginalData.prescription.status
}
})
})
$('.j-change-method').click(function(){
var $this = $(this)
mui('#sheet1').popover('toggle');
if($this.index()==1){
mui.openWindow({
id: "change-chufang1",
url: "change-chufang1.html",
waiting:{autoShow:false},
extras: {
state:strOriginalData.prescription.status,
prescriptionCode:prescriptionCode,
jwHospital:strOriginalData.prescription.jwHospital,
jwDoctorCode:strOriginalData.prescription.jwDoctorCode
}
})
}else{
nextPage();
}
})
function nextPage(){
var usefulMsg = {};
usefulMsg.prescriptionCode = prescriptionCode;
usefulMsg.diagnosis = strOriginalData.diagnosis;
usefulMsg.prescriptionInfo = strOriginalData.prescriptionInfo;
mui.openWindow({
id: "change-chufang2",
url: "change-chufang2.html",
extras: {
jsonStr:usefulMsg
}
})
}
//调整处方
$patiInfo.on('click','#changeMethod',function(){
nextPage()
})
//不通过原因
$patiInfo.on('click','.nopass-list li',function(){
var $this = $(this)
if($this.hasClass('active')){
$this.removeClass('active')
}else{
$this.addClass('active')
}
fillWord()
})
function fillWord(){
var str=''
$.map($('.nopass-list li.active'),function(o,i){
str += $('.nopass-list li.active').eq(i).text()+',';
})
$('#textarea').val(str.substr(0,str.length-1))
}
$patiInfo.on('click','#old-data',function(){
mui.openWindow({
id: "chufangxiangqing",
url: "chufangxiangqing.html",
extras: {
code:strOriginalData.prescription.jwCode,
patient:strOriginalData.prescription.patient
}
})
})
//跳转订单
$patiInfo.on('click','#booking',function(){
mui.openWindow({
id: "dingdangenzong",
url: "dingdangenzong.html",
extras: {
prescriptionCode:prescriptionCode,
teamCode:teamCode
}
})
})
$patiInfo.on('click','#history_msg',function(){
var $this = $(this)
mui.openWindow({
id: "juminxufangjilu",
url: "juminxufangjilu.html",
extras: {
patiCode:strOriginalData.prescription.patient,
teamCode:teamCode,
patiName:strOriginalData.prescription.patientName
}
})
})
//回答居民
$('.layer-res').click(function(){
if(strOriginalData.prescription.status == 100){
mui.openWindow({
id: "xufangzixunxiangqing",
url: "xufangzixunxiangqing.html",
extras: {
sessionId:strOriginalData.prescription.patient+'_'+strOriginalData.prescription.consult+'_'+8,
sessionName:strOriginalData.prescription.patientName,
sessionTime:checkDate(strOriginalData.prescription.createTime),
patiCode:strOriginalData.prescription.patient,
status:2,
type:8
}
})
}else{
mui.openWindow({
id: "xufangzixun.html",
url: "../../message/html/xufangzixun.html",
extras: {
type:8,
sessionId:strOriginalData.prescription.patient+'_'+strOriginalData.prescription.consult+'_'+8,
sessionName:strOriginalData.prescription.patientName
}
})
}
})
//提交审核
$patiInfo.on('click','#confirm',function(){
if($('#showResult').attr('data-id')){
if($('#showResult').attr('data-id')==2){
if($('#textarea').val().trim()){
passingReview();
}else{
mui.toast('请填写不通过原因')
}
}else if($('#doctorHome').attr('data-id') && $('#feeCheck').attr('data-id')){
nextDo();
}else{
mui.toast('请完善续方审核')
}
}else{
mui.toast('请完善续方审核')
}
})
function nextDo(){
plus.nativeUI.showWaiting();
sendPost("doctor/isAuthentication",{}, function(){
plus.nativeUI.closeWaiting();
mui.toast("请求失败");
}, function(res){
if(res.status == 200){
plus.nativeUI.closeWaiting();
if(res.data.type != 4){
dialog({
content: '您暂未安装CA证书,无法进行续方审核,点击前往安装',
okValue: '前往安装',
cancelValue: '取消',
cancel: function () {
return;
},
ok: function() {
mui.openWindow({
id: "cazhengshu",
url: "cazhengshu.html",
waiting:{autoShow:false},
extras: {
code:res.data.type
}
})
}
}).showModal();
}else{
$('#doctorName').html(docInfo.name)
$('.layer-bg').show();
}
}else{
plus.nativeUI.closeWaiting();
mui.toast("请求证书信息失败");
}
},'get')
}
//输入密码
var psw = 0;
var $li = $('#password').find('li');
$('.number-pad').on('tap','li',function(){
var $this = $(this)
if(!$this.hasClass('no')){
if(!$this.hasClass('del')){
if(psw <=5){
var $one = $li.eq(psw);
$one.addClass('active');
$one.attr('data-val',$this.text().trim());
psw++;
}else{
mui.toast('请点击确定')
}
}else{
if(psw >=1){
psw--;
var $one = $li.eq(psw);
$one.removeClass('active');
$one.attr('data-val','');
}
}
}else{
if(psw ==6){
submitContent()
}
}
})
//时间格式
function checkDate(d) {
var t = new Date(d);
var month = (t.getMonth() + 1) < 10 ? '0' + (t.getMonth() + 1) : (t.getMonth() + 1);
var day = t.getDate() < 10 ? '0' + t.getDate() : t.getDate();
return month+day
}
//提取密码
function takePassword(){
var str = '';
$li.each(function(){
str += $(this).attr('data-val');
})
return str
}
//忘记密码
$('#forget').click(function(){
mui.openWindow({
id: "shenfenrenzheng",
url: "shenfenrenzheng.html",
waiting:{autoShow:false}
})
})
//取消
$('.layer-bg').click(function(){
cancel();
})
$('.xufang-num').click(function(e){ e.stopPropagation() })
$('#cancel').click(function(){
cancel();
})
function cancel(){
$('.layer-bg').hide();
psw = 0;
$li.removeClass('active');
$li.attr('data-val','');
}
function submitContent(){
plus.nativeUI.showWaiting();
var imporMsg = {};
imporMsg.prescription = {};
imporMsg.prescription.jwCode = strOriginalData.prescription.jwCode;
imporMsg.prescription.patientName = strOriginalData.prescription.patientName;
imporMsg.prescription.doctorName = strOriginalData.prescription.doctorName;
imporMsg.prescription.diagnosis = strOriginalData.diagnosis;
var arr=[]
_.map(strOriginalData.prescriptionInfo,function(item){
var obj = _.pick(item, 'drugCode','drugName','jwSubCode','physicAmount','physicAmountUnit','physicAmountUnitName');
arr.push(obj)
})
imporMsg.prescription.prescriptionInfo = arr;
var params ={
strRealNameSoftCertCalledPasswd:takePassword(),
strOriginalData:JSON.stringify(imporMsg),
prescriptionCode:prescriptionCode
}
sendPost("doctor/requestRealNameSoftCertAndSign",params, function(){
plus.nativeUI.closeWaiting();
mui.toast("请求失败");
}, function(res){
if(res.status==200){
if(res.data){
cancel()
passingReview()
}else{
plus.nativeUI.closeWaiting();
mui.toast(res.msg)
}
}else{
plus.nativeUI.closeWaiting();
mui.toast("用户不存在或密码错误")
psw = 0;
$li.removeClass('active');
$li.attr('data-val','');
}
})
}
function passingReview(){
plus.nativeUI.showWaiting();
//不通过CODE
var reasonCode=[];
$.map($('.nopass-list li.active'),function(o,i){
reasonCode.push($('.nopass-list li.active').eq(i).attr('data-code'))
})
var datas = {
code:prescriptionCode,
registerFee:$('#feeCheck').attr('data-name'),
rateTypeCode:$('#feeCheck').attr('data-id'),
dept:$('#doctorHome').attr('data-id'),
reason:$('#textarea').val(),
reasonCode:reasonCode.join(','),
state:$('#showResult').attr('data-id')
}
sendPost("doctor/prescriptionInfo/reviewPrescription",datas, function(){
plus.nativeUI.closeWaiting();
mui.toast("提交审核超时")
},function(res){
plus.nativeUI.closeWaiting();
if(res.status == 200){
if(res.data){
refreshHz()
if($('#showResult').attr('data-id') == 1){
dialog({
content: '提交审核成功,记得去完成该居民的随访哦',
okValue: '好的',
ok: function() {
mui.back()
}
}).showModal();
}else{
mui.toast('提交成功')
setTimeout(function(){
mui.back()
},500)
}
}else{
refreshHz()
mui.toast("开方失败")
}
}else{
mui.toast("提交审核失败")
}
})
}
}
template.helper('setStatus',function(o){
if(o == -5){return '线下取消'}
if(o == -4){return '线下退费'}
if(o == -3){ return '续方取消(24小时未支付)' }
if(o == -2){ return '续方取消(居民主动取消)' }
if(o == -1){ return '审核未通过' }
if(o == 0 || o == 10){ return '审核中' }
if(o == 2){ return '调整中' }
if(o == 3){ return '调整成功/待ca认证' }
if(o == 4){ return '调整失败' }
if(o == 20){ return '药师审核中' }
if(o == 21){ return '药师审核失败' }
if(o == 30){ return '开方中' }
if(o == 31){ return '开方失败' }
if(o == 40 || o == 41){ return '待支付' }
if(o == 50){ return '配药中' }
if(o == 60){ return '等待领药' }
if(o == 61 || o == 62 || o == 65 || o == 69){ return '配送中' }
if(o == 100){ return '已完成' }
})
template.helper('setReview',function(o){
if(o == 0){ return '审核中' }
if(o == 1){ return '审核通过' }
if(o == -1){ return '审核未通过' }
if(o == -2){ return '审核无效' }
})
template.helper('setPrescription',function(array){
var arr=[];
$.map(array,function(item,index){
arr.push(item.name)
})
return arr.join(',')
})
template.helper('setRestTime',function(minDate,sDate){
var now = getNowDate();
var createDate = sDate.split(' ');
var diff = getDays(createDate[0],now);
if(diff'+(minDate-diff)+'天'
}else{
return '已用完'
}
})
//相隔几天
function getDays(sDate,eDate){
var oDate1;
var oDate2;
var iDays;
oDate1= sDate.split("-");
oDate2= eDate.split("-");
var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2]);
var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2]);
iDays = parseInt(Math.abs(strDateE - strDateS ) / 1000 / 60 / 60 /24)
return iDays ;
}
//现在时间
function getNowDate() {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
return year + '-' + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day);
}
//费用下拉
function selectFee(){
var data={
jwHospital:strOriginalData.prescription.jwHospital,
jwDoctorCode:strOriginalData.prescription.jwDoctorCode
}
sendPost("doctor/prescriptionInfo/getRegisterRee",data, function(){
mui.toast("请求失败");
}, function(res){
if(res.status == 200){
var result = res.data;
var html = '';
$.map(result,function(item,index){
if(item.registerType == strOriginalData.prescription.jwGisterTypeCode){
html += '';
}else{
html += '';
}
})
$('#feeCheck').html(html);
$('#feeCheck').mobiscroll().select({
theme: 'ios',
lang: 'zh',
display: 'bottom',
placeholder:'请按医生级别选择诊查费用',
rows:4,
onSelect: function ( valueText, inst) {
$('#feeCheck').attr('data-id',inst._tempValue)
$('#feeCheck').attr('data-name',valueText.split(' ')[1])
}
})
}
},'get')
}
// 科室下拉
function selectHome(){
var data={
jwHospital:strOriginalData.prescription.jwHospital,
jwDoctorCode:strOriginalData.prescription.jwDoctorCode
}
sendPost("doctor/prescriptionInfo/getDeptList",data, function(){
mui.toast("请求失败");
}, function(res){
if(res.status == 200){
var result = res.data;
var html = '';
$.map(result,function(item,index){
if(item.deptCode ==strOriginalData.prescription.jwDeptCode){
html += '';
}else{
html += '';
}
})
$('#doctorHome').html(html);
$('#doctorHome').mobiscroll().select({
theme: 'ios',
lang: 'zh',
display: 'bottom',
placeholder:'请选择您所在科室',
rows:4,
onSelect: function ( valueText, inst) {
$('#doctorHome').attr('data-id',inst._tempValue)
}
})
}
},'get')
}
//审核下拉
function selectResult(){
$('#showResult').mobiscroll().select({
theme: 'ios',
lang: 'zh',
display: 'bottom',
placeholder:'请选择审核结果',
rows:4,
onSelect: function ( valueText, inst) {
$('#showResult').attr('data-id',inst._tempValue)
if(inst._tempValue ==2){
$('#nopass').show()
$('#feeList').hide()
$('#homeList').hide()
}else if(inst._tempValue ==1){
$('#nopass').hide()
$('#feeList').show()
$('#homeList').show()
}else{
$('#nopass').hide()
$('#feeList').hide()
$('#homeList').hide()
}
$('.os-main').css('padding-bottom',$('.xf-position').height()+10)
}
})
}
//不通过原因
function nopassReason(){
sendPost("doctor/prescriptionInfo/getReasonByType",{type:0}, function(){
mui.toast("请求失败");
}, function(res){
if(res.status = 200){
var str=""
$.map(res.data,function(o,i){
str += ''+o.value+''
})
$('.nopass-list').html(str)
}
},'get')
}
function reloadPageData(){
queryData()
}
window.addEventListener("refreshXufang", function(){
reloadPageData()
})
function refreshHz(){
var page = plus.webview.getWebviewById("xufangguanli");
if(page){
mui.fire(page, "refreshXufang");
}
var page1 = plus.webview.getWebviewById("juminxufangjilu");
if(page1){
mui.fire(page1, "refreshXufang");
}
var page2 = plus.webview.getWebviewById("xufangxiangqing");
if(page2){
mui.fire(page2, "refreshXufang");
}
var page3 = plus.webview.getWebviewById("xufangxiaoxi");
if(page3){
mui.fire(page3, "refreshPage");
}
var page4 = plus.webview.getWebviewById("xufangzixun");
if(page4){
mui.fire(page4, "refreshPage");
}
}
})