<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<title>点名加急-查看</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
		<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
		<link rel="stylesheet" href="../../assets/layui/css/layui.css" />
		<link rel="stylesheet" href="../../assets/css/webuploader.css" />
		<link rel="stylesheet" href="../../assets/css/public.css" />
		<script>
            parent.el();
		</script>
	</head>
	<body>
		
		<div class="c-box">
			<div class="f-box">
				<!--导航-->
				<div id="crumbs">
					<ul>
						<li><a href="../../home.html">首页</a></li>
						<li><a href="applicationList.html">申请列表</a></li>
						<li><a class="active">病历查看</a></li>
					</ul>
				</div>
				<div id="viewBox">
					<div id="printBox">
						<blockquote class="layui-elem-quote" style="margin-bottom: 15px;">
							<ul class="view-h">
								<li class="f-left">
									<span><i class="layui-icon">&#xe612;</i></span>
									<span>{{consulatation.patientsName}}</span>
								</li>
								<li class="f-left">
									<span>性别：</span>
									<span>{{consulatation.patientsSex}}</span>
								</li>
								<li class="f-left">
									<span>年龄：</span>
									<span>{{consulatation.age}}</span>
								</li>
							</ul>
						</blockquote>
						<fieldset class="details-list layui-elem-field layui-field-title">
						  <legend><img src="../../assets/images/xinxi-ico.png" />&nbsp;详细信息</legend>
						  <div class="layui-field-box">
							<ul class="layui-row">
								<li class="layui-col-xs6 layui-col-sm6 layui-col-md4">
									<span>会诊单位：</span>
									<span>{{consulatation.hosp}}</span>
								</li>
								<li class="layui-col-xs6 layui-col-sm6 layui-col-md4">
									<span>申请医师：</span>
									<span>{{consulatation.applyName}}</span>
								</li>
								<li class="layui-col-xs6 layui-col-sm6 layui-col-md4">
									<span>系统病历号：</span>
									<span>{{consulatation.sysNo}}</span>
								</li>
								<li class="layui-col-xs6 layui-col-sm6 layui-col-md4">
									<span>301就诊ID：</span>
									<span>{{consulatation.originaNo}}</span>
								</li>
								<li class="layui-col-xs6 layui-col-sm6 layui-col-md4">
									<span>申请科室：</span>
									<span>{{consulatation.applicationDepartment}}</span>
								</li>
								<li class="layui-col-xs4 layui-col-sm12 layui-col-md4">
									<span>申请医院：</span>
									<span>{{consulatation.applicationInstitution}}</span>
								</li>
								<li class="layui-col-xs6 layui-col-sm6 layui-col-md4">
									<span>会诊联系电话：</span>
									<span>{{consulatation.doctorTel}}</span>
								</li>
								<li class="layui-col-xs4 layui-col-sm12 layui-col-md4">
									<span>检查时间：</span>
									<span>{{consulatation.checkTime}}</span>
								</li>
								<li class="layui-col-xs6 layui-col-sm6 layui-col-md4">
									<span>民族：</span>
									<span>{{consulatation.patientsNational}}</span>
								</li>
								<li class="layui-col-xs6 layui-col-sm6 layui-col-md4">
									<span>婚否：</span>
									<span>{{consulatation.patientsMaritalStatus}}</span>
								</li>
								<li class="layui-col-xs6 layui-col-sm6 layui-col-md4">
									<span>会诊类型：</span>
									<span>{{consulatation.consultationCategory=='y'?'预约':consulatation.consultationCategory=='v'?'视频':'书面'}}</span>
								</li>
								<li class="layui-col-xs4 layui-col-sm12 layui-col-md4">
									<span>会诊类别：</span>
									<span>{{consulatation.type==1?'初诊':'复诊'}}</span>
								</li>
								<li class="layui-col-xs6 layui-col-sm6 layui-col-md4">
									<span>申请类别：</span>
									<span>{{consulatation.category=='n'?'普通':'加急'}}</span>
								</li>
								<li class="layui-col-xs4 layui-col-sm12 layui-col-md4">
									<span>职业：</span>
									<span></span>
								</li>
							</ul>
						  </div>
						</fieldset>
						<fieldset class="details-list layui-elem-field layui-field-title">
						  <legend><img src="../../assets/images/bingli-icon.png" />&nbsp;病历信息</legend>
						  <div class="layui-field-box">
							<ul class="layui-row medicalRecord">
								<li class="layui-col-xs12 layui-col-sm12 layui-col-md12">
									<span class="f-left">病历摘要：</span>
									<span class="f-left">{{consulatation.historySummary}}</span>
								</li>
								<li class="layui-col-xs12 layui-col-sm12 layui-col-md12">
									<span class="f-left">既往史：</span>
									<span class="f-left">{{consulatation.formerlyIllness}}</span>
								</li>
								<li class="layui-col-xs12 layui-col-sm12 layui-col-md12">
									<span class="f-left">过敏史：</span>
									<span class="f-left">{{consulatation.allergy}}</span>
								</li>
								<li class="layui-col-xs12 layui-col-sm12 layui-col-md12">
									<span class="f-left">家族史：</span>
									<span class="f-left">{{consulatation.familyHistory}}</span>
								</li>
								<li class="layui-col-xs12 layui-col-sm12 layui-col-md12">
									<span class="f-left">初步诊断：</span>
									<span class="f-left">{{consulatation.primaryDiagnosis}}</span>
								</li>
								<li class="layui-col-xs12 layui-col-sm12 layui-col-md12">
									<span class="f-left">治疗意见：</span>
									<span class="f-left">{{consulatation.therapyAdvice}}</span>
								</li>
								<li class="layui-col-xs12 layui-col-sm12 layui-col-md12">
									<span class="f-left">会诊目的：</span>
									<span class="f-left">{{consulatation.purpose}}</span>
								</li>
							</ul>
						  </div>
						</fieldset>
					</div>
					<fieldset  class="details-list layui-elem-field layui-field-title">
					  <legend style="margin-bottom: 10px;"><img src="../../assets/images/fujian-icon.png" />&nbsp;附件列表</legend>
					  <div class="layui-field-box">
					  	<div class="layui-upload">
						  <button type="button" v-on:click="openFileUpload" class="layui-btn layui-btn-normal" id="fileList">补充材料</button>
						  <span id="specification">[附件上传规范]</span>
						  </div>
			              <div class="layui-upload-list">
						   	 <table class="layui-table">
						      <thead>
						        <tr>
						        	<th>序号</th>
						        	<th>文件名称</th>
						        	<th>文件类型</th>
						        	<th>操作</th>
						        </tr>
						      </thead>
						      <tbody>
							  	<tr v-for="(m,index) in consulatation.maffixSet">
									<td>{{index+1}}</td>
									<td>{{m.realFileName}}</td>
									<td>{{m.docType}}</td>
									<td><a class="layui-btn layui-btn-xs" v-if="suffix(m.realFileName)" v-on:click="checkImg(m)">查看</a></td>
								</tr>
							  </tbody>
						     </table>
						  </div>
					  </div>
					</fieldset>
					<fieldset v-if="dicomList.length" class="details-list layui-elem-field layui-field-title">
						<legend style="margin-bottom: 10px;"><img src="../../assets/images/yinxiang-icon.png" />&nbsp;影像资料</legend>
						<div class="layui-field-box">
							<table class="layui-table">
								<thead>
								<tr>
									<th>序号</th>
									<th>文件名称</th>
									<th>操作</th>
								</tr>
								</thead>
								<tbody>
									<tr v-for="(d,index) in dicomList">
										<td>{{index+1}}</td>
										<td>{{d.fileName}}</td>
										<td><a  class="layui-btn layui-btn-xs dicomCheck" v-bind:stuuid="d.stuuid">查看</a></td>
									</tr>
								</tbody>
							</table>
						</div>
					</fieldset>
					<fieldset v-if="consulatation.status==6 || consulatation.status==8" class="details-list layui-elem-field layui-field-title">
					  <legend style="margin-bottom: 10px;"><img src="../../assets/images/zhenduan-icon.png" />&nbsp;诊断结果</legend>
		              <div class="layui-field-box">
					  	  <ul class="layui-row medicalRecord">
						    <li class="layui-col-xs12 layui-col-sm12 layui-col-md12">
						    	<span class="f-left">专家回复：</span>
						    	<span class="f-left">{{consulatation.expertReturn}}</span>
						    </li>
					  	  </ul>
			              <div class="layui-upload-list">
						   	 <table class="layui-table">
						      <thead>
						        <tr>
						        	<th>序号</th>
						        	<th>文件名称</th>
						        	<th>操作</th>
						        </tr>
						      </thead>
						      <tbody>
							  		<tr v-for="(ra,index) in ReplayAffix">
										<td>{{index+1}}</td>
										<td>{{ra.docType}}</td>
										<td><a class="layui-btn layui-btn-xs" v-on:click="checkReplayAff(ra)">查看</a>
											<a class="layui-btn layui-btn-danger layui-btn-xs" v-on:click="downCase(ra)">下载</a></td>
									</tr>
							  </tbody>
						     </table>
						  </div>
					  </div>
					</fieldset>

				</div>
				<div class="formBtn">
					<button class="layui-btn layui-btn-warm" onclick="printPreview()">打印</button>
				</div>
		    </div>
		</div>
		
		<!--参考文件上传-->
		<div id="specificationFile-box">
			<div class="layui-form">
				<div class="layui-form-item">
					<label class="layui-form-label">文件组名称</label>
					<div class="layui-input-block" style="width: 424px;">
						<input type="text" class="layui-input" v-model="fileGroup" id="fileGroup">
					</div>
				</div>

				<div v-for="(file,index) in files" class="layui-form-item" >
					<label class="layui-input-inline layui-form-label">{{file.fileType}}</label>
					<div class="layui-input-inline">
						<p class="layui-input">{{file.file.name}}</p>
					</div>
					<div v-on:click="files.splice(index, 1)" class="layui-input-inline">
						<label class="layui-btn layui-btn-danger">删除</label>
					</div>
				</div>

				<div class="layui-form-item" id="specificationCon">
					<div class="layui-input-inline" style="width: 115px;">
						<select name="fileIndex" lay-filter="fileType" v-model="fileType">
							<option>CT</option>
							<option>MRI</option>
							<option>X光片</option>
							<option>B超</option>
							<option>ECG</option>
							<option>化验单</option>
						</select>
					</div>
					<div class="layui-input-inline">
						<p id="fileName0" class="layui-input"></p>
					</div>
					<div class="layui-input-inline">
						<label id="specificationBtn" for="file" class="layui-btn layui-btn-normal">选择文件</label>
						<input v-on:change="fileInputChange" type="file" style="display: none;" id="file" multiple />
					</div>
				</div>
				<hr />
				<div class="layui-form-item" id="sumUp">
					<p></p>
					<button id="specificationBtn-go" class="layui-btn" v-on:click="fileUpload">开始上传</button>
				</div>
			</div>
		</div>

		<div id="printer" style="display: none;">
			<ul>
				<li v-for="p in printerList" v-on:click="print">{{p.name}}</li>
			</ul>
		</div>


		<script type="text/javascript" src="../../assets/js/jquery-1.8.3.js" ></script>
		<script type="text/javascript" src="../../assets/js/util.js" ></script>
		<script type="text/javascript" src="../../assets/layui/layui.js" ></script>
		<script type="text/javascript" src="../../assets/js/webuploader.js" ></script>
		<script src="../../../node_modules/vue/dist/vue.js"></script>
		<script>
			var element;
            layui.use(['upload','table','layer','element'], function(){
                var table = layui.table;
                var upload = layui.upload;
                var layer = layui.layer;
                element = layui.element

            })
            const url = parent.require('electron').remote.require('./url.config').url
			const {ipcRenderer} = parent.require('electron');
            var app = new Vue({
                el:'#viewBox',
                data:{
                    caseTitle:'',
                    dicomList:[],
                    ReplayAffix:[],
                    consulatation:{
                        patientsName:'',
                        patientsSex:'',
                        hosp:'',
                        applicationDepartment:'',
                        outpatientId:'',
                        consultationCategory:'',
                        id:'',
                        sysNo:'',
                        applicationInstitution:'',
                        type:'',
                        age:'',
                        originaNo:'',
                        idCard:'',
                        patientsEmail:'',
                        applyName:'',
                        statures:'',
                        weight:'',
                        patientsNational:'',
                        patientsMaritalStatus:'',
                        medicalTreatment:'',
                        patientsTel:'',
                        doctorTel:'',
                        localHospitalConTel:'',
                        historySummary:'',
                        formerlyIllness:'',
                        allergy:'',
                        familyHistory:'',
                        primaryDiagnosis:'',
                        therapyAdvice:'',
                        purpose:'',
                        maffixSet:[],
                        expertReturn:''
                    }
                },
				methods:{
                    checkReplayAff:function(ra){
                        console.info(ra)
                        layer.photos({
                            photos: {
                                "title": "", //相册标题
                                "id": 123, //相册id
                                "start": 0, //初始显示的图片序号，默认0
                                "data": [   //相册包含的图片，数组格式
                                    {
                                        "alt": ra.docType,
                                        "pid": ra.id, //图片id
                                        "src": ra.fileUrl, //原图地址
                                        "thumb": ra.fileUrl //缩略图地址
                                    }
                                ]
                            } //格式见API文档手册页
                            ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
                        });
					},
                    checkImg:function(file){
//                        var file = this.affixList[index];
                        layer.photos({
                            photos: {
                                "title": "", //相册标题
                                "id": 123, //相册id
                                "start": 0, //初始显示的图片序号，默认0
                                "data": [   //相册包含的图片，数组格式
                                    {
                                        "alt": file.realFileName,
                                        "pid": file.id, //图片id
                                        "src": file.fileUrl, //原图地址
                                        "thumb": file.fileUrl //缩略图地址
                                    }
                                ]
                            } //格式见API文档手册页
                            ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
                        });
                    },
                    suffix:function(value){
                        // 后缀获取
                        var suffix = '';
                        // 获取类型结果
                        var result = '';
                        try {
                            var flieArr = value.split('.');
                            suffix = flieArr[flieArr.length - 1];
                        } catch (err) {
                            suffix = '';
                        }
                        if (!suffix) {
                            result = false;
                            return result;
                        }
                        // 图片格式
                        var imglist = ['png', 'jpg', 'jpeg', 'bmp', 'gif'];
                        result = imglist.some(function (item) {
                            return item == suffix;
                        });
                        return result;
                    },
                    openFileUpload:function(){
                        layer.open({
                            type: 1,
                            title:'参考文件上传',
                            area: ['600px', 'auto'], //宽高
                            content: $('#specificationFile-box')
                        });
					},
                    downCase(ra){
                        console.info(ra.fileUrl)
                        ipcRenderer.send('download',ra.fileUrl);
                    }
				}
            })

			var printerVue = new Vue({
				el:'#printer',
				data:{
                    printerList:[],
					printer:''
				},
				methods:{
                    print:function(e){
                        var li = e.target;
                        this.printer = $(li).text();
                        var printhtml = $('#printBox').html();
                        const webview = parent.document.querySelector('#printWebview')
                        webview.send('webview-print-render',printhtml )
						layer.closeAll();
					},
					getPrinterList:function(){
                        var list = ipcRenderer.sendSync('print-getList', 'aa');
                        return list;
					}
				},
				created:function(){
                    this.printerList = this.getPrinterList()
                },

			})

            var fileVue = new Vue({
                el:'#specificationFile-box',
                data:{
                    files:[],
                    fileType:'CT',
                    fileGroup:''
                },
                methods:{
                    fileInputChange:function(e){
                        var input = e.target;
                        for(let i=0;i<input.files.length;i++){
                            this.files.push({
                                fileType:this.fileType,
                                file:input.files[i]
                            });
                        }
                    },
                    fileUpload:function(){
                        if(this.files.length==0){
                            return ;
                        }
                        if(!this.fileGroup){
                            return ;
                        }
                        layer.open({
                            title: '正在上传中'
                            ,btn:[]
                            ,closeBtn: 0
                            ,content: '<div class="layui-progress" lay-filter="demo" lay-showPercent="yes">'+
                            '<div id="progress" class="layui-progress-bar" lay-percent="0%"></div>'+
                            '</div>'
                        });

                        var formData = new FormData();
                        for(let i=0;i<this.files.length;i++){
                            formData.append(this.files[i].fileType, this.files[i].file);
                        }
                        formData.append('fileGroup', this.fileGroup);
                        formData.append('sysNo', app.consulatation.sysNo);
                        formData.append('consultationCategory', app.consulatation.consultationCategory);
                        formData.append('buchong', '2');
                        $.ajax({
                            url: url+'client/consultationMaterial',
                            type: 'POST',
                            cache: false,
                            data: formData,
                            processData: false,
                            contentType: false,
                            xhr: function () {//这里是计算上传进度
                                var myXhr = $.ajaxSettings.xhr();
                                if (myXhr.upload) {
                                    myXhr.upload.addEventListener('progress', function (e) {
                                        if (e.lengthComputable) {
                                            var percent = Math.floor(e.loaded / e.total * 100);
                                            element.progress('demo',  percent + '%');
                                        }
                                    }, false);
                                }
                                return myXhr;
                            },
                            success:function(result) {
                                if (result.status==1) {
                                    app.consulatation.maffixSet = result.data
                                    fileVue.files = [];
                                    layer.closeAll();
                                }
                            }
                        })
                    }
                }
            })

            $(function () {
                const webview = parent.document.querySelector('#printWebview')
                webview.addEventListener('ipc-message', (event) => {
                    if (event.channel === 'webview-print-do') {

                        var status = ipcRenderer.sendSync('print-start', printerVue.printer);
                        if(!status){
                            console.info('打印机异常')
                            return ;
						}
                        webview.print({ silent: true, printBackground: true, deviceName: printerVue.printer },
                            (data) => {
                                console.log("webview success", data);
                                if(data){
                                    layer.msg('打印完成')
								}
                            })

                    }
                })
            })

            var consultationId = getUrlParam('consultationId'),again =getUrlParam('expertId');
            $.ajax({
                url: url+'client/lookDeatileByMember',
                data : {
                    consultationId:consultationId
                    ,expertId:''
                },
                type: 'post',
                dataType: 'json',
                success: function(data){
                    if(data.status=='1'){
						app.ReplayAffix = data.ReplayAffix
						app.dicomList = data.dicomList
                        app.dicomList = data.dicomList
                        for(var key in data.consultation){
                            app.consulatation[key] = data.consultation[key]

                        }
                    }
                }
            })



            const shell = parent.require('electron').shell
            $("body").on('click','.dicomCheck',function(event){
                event.preventDefault()
				var stuuid = $(this).attr("stuuid")
                shell.openExternal("http://202.106.159.95:8088?&user=cc&pswd=dd&stuuid="+stuuid)
            })

		</script>

		<script>

            function printPreview() {
                layer.open({
					title:'请选择打印机',
					type:1,
					content:$("#printer")
				})
            }
			  
		</script>

	</body>
</html>
