<template>
  <div class="patient-container">
    <patient-sidebar :id="patient_id" defaultActive="1-9"></patient-sidebar>
    <div v-loading="loading">
      <div class="patient-app-container advice-container app-container">

        <div>
                    <span style="margin-left: 10px;float:right;">
                        <el-button type="primary" icon="el-icon-circle-plus-outline" size="small"
                                   @click="addAction">新增</el-button>

                        <el-button type="primary" icon="el-icon-edit-outline" size="small"
                                   @click="toEdit">修改</el-button>
                      <el-button type="primary" icon="el-icon-printer" size="small"
                                 @click="print">打印</el-button>
                      <el-button size="small"  type="danger" @click="deleteAction">删除</el-button>
                    </span>
        </div>
      
        <div class="cell clearfix">
          <label class="title"><span class="name">日期查询</span> : </label>
          <el-date-picker v-model="start_time" prefix-icon="el-icon-date" :editable="false" style="width: 196px;"
                          type="date" placeholder="选择日期时间" align="right" format="yyyy-MM-dd"
                          value-format="yyyy-MM-dd" @change="startTimeChange"></el-date-picker>
          <span class="">-</span>
          <el-date-picker v-model="end_time" prefix-icon="el-icon-date" :editable="false" style="width: 196px;"
                          type="date" placeholder="选择日期时间" align="right" format="yyyy-MM-dd"
                          value-format="yyyy-MM-dd" @change="endTimeChange"></el-date-picker>
        </div>
        <div class="record">
          <el-row :gutter="15">
            <el-col :span="10">
              <el-table :header-cell-style="{
                  backgroundColor: 'rgb(245, 247, 250)',
                  color: '#606266'
                }"
                :row-style="{ color: '#303133' }" ref="monthlyPlanTable" :data="tableData"
                        border highlight-current-row @current-change="changeCurrentRecordTwo"
                        @selection-change="selectSummary"
                        :row-class-name="tableRow"
              >
                <el-table-column type="selection" width="60" align="center"></el-table-column>
                <el-table-column label="标题" align="center">
                  <template slot-scope="scope">
                    {{scope.row.title}}
                  </template>
                </el-table-column>
                <el-table-column label="记录日期" align="center">
                  <template slot-scope="scope">
                    {{getTime(scope.row.record_date)}}
                  </template>
                </el-table-column>
                <el-table-column label="住院医师" align="center">
                  <template slot-scope="scope">
                    {{getDoctor(scope.row.doctor)}}
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
            <el-col :span="14">
              <div class="record_content_panel">
                <div style="background-color:rgb(245, 247, 250)" class="title">出院小结内容</div>
                <div style="padding:10px;border-bottom:1px solid #DCDFE6;">标题:
                   {{hosDetail.title}}
                </div>
            
                 <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">入院时间:
                   <span v-if="hosDetail.admission_time > 0">{{getTime(hosDetail.admission_time)?getTime(hosDetail.admission_time):""}}</span> 
                 </div>
                <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">出院时间:
                   <span v-if="hosDetail.discharge_time > 0">{{getTime(hosDetail.discharge_time)}}</span>
                </div>
                <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">上级医师签名:
                   {{getDoctor(hosDetail.dean_id)}}
                </div>
                <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">住院医师签名:
                   {{getDoctor(hosDetail.doctor)}}
                </div>
                <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">记录日期:
                  <span v-if="hosDetail.record_date > 0">{{getTime(hosDetail.record_date)}}</span> 
                </div>
                <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">病案号:
                   {{hosDetail.sick_personnel}}
                </div>
                 <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">X线:
                   {{hosDetail.xray}}
                </div>
                 <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">CT:
                   {{hosDetail.connecticut}}
                 </div>
                  <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">MRI:
                   {{hosDetail.nuclear_magnetic_resonance}}
                 </div>
                  <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">超声:
                   {{hosDetail.ultrasound}}
                 </div>
                 <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">病理:
                   {{hosDetail.pathology}}
                 </div>
                 <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">入院诊断:
                   <span v-html="hosDetail.admitting_diagnosis"></span> 
                 </div>
                  <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">出院诊断:
                   <span v-html="hosDetail.discharge_diagnosis"></span>
                 </div>
                 <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">入院时病情:
                   <span v-html="hosDetail.diagnosis_admission"></span>
                 </div>
                 <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">诊断经过:
                   <span v-html="hosDetail.treatment"></span> 
                 </div>
                 <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">出院时病情:
                   <span v-html="hosDetail.illness_discharge"></span> 
                 </div>
                 <div style="padding:10px;border-bottom:1px solid #DCDFE6;line-height:20px;">出院医嘱:
                    <span v-html="hosDetail.discharge_advice"></span>
                 </div>
               
              </div>
            </el-col>
          </el-row>
        </div>
      </div>

  
     
      <el-dialog title="新增出院小结" width="60%" top="5vh" :visible.sync="show_dialog">
        <div>
          <div class="new_record_form">
            <div class="cell clearfix">
              <label class="title"><span class="name">标题</span> : </label>
               <el-input v-model="form.title" style="width:200px"></el-input>
            
             
              <label class="title"><span class="name">入院时间</span> : </label>
              <el-date-picker v-model="form.admission_time" 
                    prefix-icon="el-icon-date" 
                    style="width: 200px;"
                    type="date" placeholder="选择日期时间" align="right" format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd">
              </el-date-picker>

            
              <label class="title"><span class="name">出院时间</span> : </label>
              <el-date-picker v-model="form.discharge_time"
                    prefix-icon="el-icon-date" 
                    style="width: 200px;"
                    type="date" placeholder="选择日期时间" align="right" format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd">
              </el-date-picker>

            
            </div>
            <div  class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">上级医师签名</span>:</label>
               <el-select v-model="form.dean" placeholder="请选择">
                  <el-option
                  v-for="item in doctorList"
                  :key="item.admin_user_id"
                  :label="item.user_name"
                  :value="item.admin_user_id">
                  </el-option>
              </el-select>
              <label class="title"><span class="name">住院医师签名</span>:</label>
              <el-select v-model="form.doctor" placeholder="请选择">
                  <el-option
                  v-for="item in doctorList"
                  :key="item.admin_user_id"
                  :label="item.user_name"
                  :value="item.admin_user_id">
                  </el-option>
              </el-select>    
              <label class="title"><span class="name">记录日期</span> : </label>
              <el-date-picker v-model="form.record_date"
                    prefix-icon="el-icon-date" 
                    style="width: 200px;"
                    type="date" placeholder="选择日期时间" align="right" format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd">
              </el-date-picker>   
            </div>
            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">病案号</span> : </label>
              <el-input v-model="form.sick_personnel" style="width:200px"></el-input>
            
              <label class="title"><span class="name">X线</span> : </label>
              <el-input v-model="form.xray" style="width:200px"></el-input>

              <label class="title"><span class="name">CT</span> : </label>
              <el-input v-model="form.connecticut" style="width:200px"></el-input>
            </div>

            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">MRI</span> : </label>
              <el-input v-model="form.nuclear_magnetic_resonance" style="width:200px"></el-input>
            
              <label class="title"><span class="name">超声</span> : </label>
              <el-input v-model="form.ultrasound" style="width:200px"></el-input>

              <label class="title"><span class="name">病理</span> : </label>
              <el-input v-model="form.pathology" style="width:200px"></el-input>
            </div>
            
            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">入院诊断</span> : </label>
                <el-select v-model="form.admitting_diagnosis_id" placeholder="可选择病程模板" @change="changeAmittDiagnosis">
                  <el-option v-for="(option, index) in templates" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>
                
                 <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editor"
                              id="editors"
                              style="width: 800px"
                              v-bind:r_content="form.admitting_diagnosis">
                      </editor>
                    </keep-alive>
                </div>
            </div>

            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">出院诊断</span> : </label>
                <el-select v-model="form.discharge_diagnosis_id" placeholder="可选择病程模板" @change="changeDischargeDiagnosis">
                  <el-option v-for="(option, index) in templatesOne" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>

               <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editorOne"
                              id="editorsOne"
                              style="width: 800px"
                              v-bind:r_content="form.discharge_diagnosis">
                      </editor>
                    </keep-alive>
                </div>

            </div>

             <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">入院时病情</span> : </label>
                <el-select v-model="form.diagnosis_admission_id" placeholder="可选择病程模板" @change="changeDiagnosisAdmission">
                  <el-option v-for="(option, index) in templatesTwo" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>

                <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editorTwo"
                              id="editorTwo"
                              style="width: 800px"
                              v-bind:r_content="form.diagnosis_admission">
                      </editor>
                    </keep-alive>
                </div>
            </div>

            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">诊断经过</span> : </label>
                <el-select v-model="form.treatment_id" placeholder="可选择病程模板" @change="changeTreatment">
                  <el-option v-for="(option, index) in templatesThree" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>

               <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editorFour"
                              id="editorsFour"
                              style="width: 800px"
                              v-bind:r_content="form.treatment">
                      </editor>
                    </keep-alive>
                </div>

            </div>

            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">出院时病情</span> : </label>
                <el-select v-model="form.illness_discharge_id" placeholder="可选择病程模板" @change="changeillnessDisCharge">
                  <el-option v-for="(option, index) in templatesFour" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>

               <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editorFive"
                              id="editorFive"
                              style="width: 800px"
                              v-bind:r_content="form.illness_discharge">
                      </editor>
                    </keep-alive>
                </div>
            </div>

            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">出院医嘱</span> : </label>
                <el-select v-model="form.discharge_advice_id" placeholder="可选择病程模板" @change="changeDischargeAdvice">
                  <el-option v-for="(option, index) in templatesFive" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>

                <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editorSix"
                              id="editorSix"
                              style="width: 800px"
                              v-bind:r_content="form.discharge_advice">
                      </editor>
                    </keep-alive>
                </div>
            </div>
         
            <div style="text-align: right; padding-right: 0px; padding-top: 10px; padding-bottom: 10px;">
              <el-button @click="show_dialog = false">取消</el-button>
              <el-button type="primary"
                         @click="createAction" :loading="uploading_new_record">保存
              </el-button>
            </div>
          </div>
        </div>
      </el-dialog>
      
      <el-dialog title="编辑出院小结" width="60%" top="5vh" :visible.sync="edit_show_dialog">
        <div>
          <div class="new_record_form">
            <div class="cell clearfix">
              <label class="title"><span class="name">标题</span> : </label>
               <el-input v-model="form.title" style="width:200px"></el-input>
            
             
              <label class="title"><span class="name">入院时间</span> : </label>
              <el-date-picker v-model="form.admission_time" 
                    prefix-icon="el-icon-date" 
                    style="width: 200px;"
                    type="date" placeholder="选择日期时间" align="right" format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd">
              </el-date-picker>

            
              <label class="title"><span class="name">出院时间</span> : </label>
              <el-date-picker v-model="form.discharge_time"
                    prefix-icon="el-icon-date" 
                    style="width: 200px;"
                    type="date" placeholder="选择日期时间" align="right" format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd">
              </el-date-picker>

            
            </div>
            <div  class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">上级医师签名</span>:</label>
               <el-select v-model="form.dean" placeholder="请选择">
                  <el-option
                  v-for="item in doctorList"
                  :key="item.admin_user_id"
                  :label="item.user_name"
                  :value="item.admin_user_id">
                  </el-option>
              </el-select>
              <label class="title"><span class="name">住院医师签名</span>:</label>
              <el-select v-model="form.doctor" placeholder="请选择">
                  <el-option
                  v-for="item in doctorList"
                  :key="item.admin_user_id"
                  :label="item.user_name"
                  :value="item.admin_user_id">
                  </el-option>
              </el-select>    
              <label class="title"><span class="name">记录日期</span> : </label>
              <el-date-picker v-model="form.record_date"
                    prefix-icon="el-icon-date" 
                    style="width: 200px;"
                    type="date" placeholder="选择日期时间" align="right" format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd">
              </el-date-picker>   
            </div>
            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">病案号:</span> : </label>
              <el-input v-model="form.sick_personnel" style="width:200px"></el-input>
            
              <label class="title"><span class="name">X线</span> : </label>
              <el-input v-model="form.xray" style="width:200px"></el-input>

              <label class="title"><span class="name">CT</span> : </label>
              <el-input v-model="form.connecticut" style="width:200px"></el-input>
            </div>

            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">MRI</span> : </label>
              <el-input v-model="form.nuclear_magnetic_resonance" style="width:200px"></el-input>
            
              <label class="title"><span class="name">超声</span> : </label>
              <el-input v-model="form.ultrasound" style="width:200px"></el-input>

              <label class="title"><span class="name">病理</span> : </label>
              <el-input v-model="form.pathology" style="width:200px"></el-input>
            </div>
            
            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">入院诊断</span> : </label>
                <el-select v-model="form.admitting_diagnosis_id" placeholder="可选择病程模板" @change="changeAmittDiagnosis">
                  <el-option v-for="(option, index) in templates" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>
                
                 <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editorTen"
                              id="editorTen"
                              style="width: 800px"
                              v-bind:r_content="form.admitting_diagnosis">
                      </editor>
                    </keep-alive>
                </div>
            </div>

            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">出院诊断</span> : </label>
                <el-select v-model="form.discharge_diagnosis_id" placeholder="可选择病程模板" @change="changeDischargeDiagnosis">
                  <el-option v-for="(option, index) in templatesOne" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>

               <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editorSeven"
                              id="editorSeven"
                              style="width: 800px"
                              v-bind:r_content="form.discharge_diagnosis">
                      </editor>
                    </keep-alive>
                </div>

            </div>

             <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">入院时病情</span> : </label>
                <el-select v-model="form.diagnosis_admission_id" placeholder="可选择病程模板" @change="changeDiagnosisAdmission">
                  <el-option v-for="(option, index) in templatesTwo" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>

                <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editorSixty"
                              id="editorSixty"
                              style="width: 800px"
                              v-bind:r_content="form.diagnosis_admission">
                      </editor>
                    </keep-alive>
                </div>
            </div>

            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">诊断经过</span> : </label>
                <el-select v-model="form.treatment_id" placeholder="可选择病程模板" @change="changeTreatment">
                  <el-option v-for="(option, index) in templatesThree" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>

               <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editorNight"
                              id="editorNight"
                              style="width: 800px"
                              v-bind:r_content="form.treatment">
                      </editor>
                    </keep-alive>
                </div>

            </div>

            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">出院时病情</span> : </label>
                <el-select v-model="form.illness_discharge_id" placeholder="可选择病程模板" @change="changeillnessDisCharge">
                  <el-option v-for="(option, index) in templatesFour" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>

               <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editorThirty"
                              id="editorThirty"
                              style="width: 800px"
                              v-bind:r_content="form.illness_discharge">
                      </editor>
                    </keep-alive>
                </div>
            </div>

            <div class="cell clearfix" style="margin-top:10px">
              <label class="title"><span class="name">出院医嘱</span> : </label>
                <el-select v-model="form.discharge_advice_id" placeholder="可选择病程模板" @change="changeDischargeAdvice">
                  <el-option v-for="(option, index) in templatesFive" :key="index" :label="option.title"
                            :value="option.content"></el-option>
                </el-select>

                <div class="textarea_panel">
                    <keep-alive>
                      <editor ref="editorTwelve"
                              id="editorTwelve"
                              style="width: 800px"
                              v-bind:r_content="form.discharge_advice">
                      </editor>
                    </keep-alive>
                </div>
            </div>
         
            <div style="text-align: right; padding-right: 0px; padding-top: 10px; padding-bottom: 10px;">
              <el-button @click="edit_show_dialog = false">取消</el-button>
              <el-button type="primary"
                         @click="updateAction">保存
              </el-button>
            </div>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
  import PatientSidebar from './components/PatientSidebar'
  import Editor from '@/components/Editor'

  import { createHospitalSummary,getHospitalSummaryList,getHospitalSummaryDetail,updateHospitalSummary,deleteHospitalSummary,getPatientInfo } from '@/api/patient'
  import { parseTime } from '@/utils'
  import BreadCrumb from '@/xt_pages/components/bread-crumb'
  import { uParseTime } from '@/utils/tools'
  import { getDataConfig } from '@/utils/data'
  import multiSelectBox from '../dialysis/details/dialog/MultiSelectBox'
 import MsgTip from '../dialysis/details/dialog/MsgTip'
  import { getAllDoctorList } from "@/api/device"
  const moment = require('moment')
  export default {
    name: 'hospitalSummary',
    components: {
      PatientSidebar,
      BreadCrumb,
      Editor,
      MsgTip,
      multiSelectBox,
    },
    data() {
      return {
        InnerDialogProps: {
          values: [],
          visibility: false,
          isShowTextArea: true,
          customContent: '',
          titles: '',
          type: '' // 不同弹框类型，用来匹配数据
        },
        loading: false,
        title: '',
        patient_id: 0,
        date: [],
        start_time: '',
        end_time: '',
        course_of_disease_time: '',
        records: [],
        doctors: [],
        current_select_record: null,
        show_dialog: false,
        show_edit_dialog: false,
        uploading_new_record: false,
        edit_show_dialog:false,
        templates: this.$store.getters.configlist.admitting_diagnosis,
        templatesOne:this.$store.getters.configlist.discharge_diagnosis,
        templatesTwo:this.$store.getters.configlist.diagnosis_admission,
        templatesThree:this.$store.getters.configlist.treatment,
        templatesFour:this.$store.getters.configlist.illness_discharge,
        templatesFive:this.$store.getters.configlist.discharge_advice,
        select_template: '',
        new_content: '',
        edit_new_content: '',
        edit_course_of_disease_time: '',
        selectingRows: [],
        table_current_index: -1,
        edit_current_id: 0,
        edit_title: '',
        value:'',
        form:{
          id:0,
          title:"",
          admission_time:this.getTime(new Date()),
          discharge_time:this.getTime(new Date()),
          sick_personnel:"",
          xray:"",
          admitting_diagnosis_id:"",
          admitting_diagnosis:"",
          discharge_diagnosis_id:"",
          discharge_diagnosis:"",
          treatment:"",
          treatment_id:"",
          diagnosis_admission_id:"",
          diagnosis_admission:"",
          illness_discharge_id:"",
          illness_discharge:"",
          dean:"",
          doctor:"",
          record_date:this.getTime(new Date()),
          discharge_advice_id:"",
          discharge_advice:"",
          connecticut:"",
          nuclear_magnetic_resonance:"",
          ultrasound:"",
          pathology:"",
          record_time:"",
        },
       tableData:[],
       docList:[],
       doctorList:[],
       hosDetail:{},
       ids:"",
       patient:{},
      }
    },
    created() {
     
      this.patient_id = this.$route.params && this.$route.params.id

      var now = new Date()
      this.date = [now.getTime() - (7 * 24 * 60 * 60 * 1000), now.getTime()]

      var nowDate = new Date()
      var nowYear = nowDate.getFullYear()
      var nowMonth = nowDate.getMonth() + 1

      var nowDay = nowDate.getDate()
      this.end_time =
        nowYear +
        '-' +
        (nowMonth < 10 ? '0' + nowMonth : nowMonth) +
        '-' +
        (nowDay < 10 ? '0' + nowDay : nowDay)
      nowDate.setMonth(nowDate.getMonth() - 1)
      nowYear = nowDate.getFullYear()
      nowMonth = nowDate.getMonth() + 1
      nowDay = nowDate.getDate()
      this.start_time =
        nowYear +
        '-' +
        (nowMonth < 10 ? '0' + nowMonth : nowMonth) +
        '-' +
        (nowDay < 10 ? '0' + nowDay : nowDay)
      this.other_start_time = nowYear +'-' +(nowMonth < 10 ? '0' + nowMonth : nowMonth) +'-' + (nowDay < 10 ? '0' + nowDay : nowDay)
      
     this.getAllDoctorList()
     this.getlist()
     this.getPatientSummaryById()
    },
    methods: {
      getTime(val) {
       if(val == "" || val == undefined){
          return ""
         }else {
          return uParseTime(val, '{y}-{m}-{d}')
         }
      },

      startTimeChange(val){
       
       this.start_time = val
       this.getlist()
      },
      endTimeChange(val){
       this.end_time = val
       this.getlist()
      },
      print(){
        this.$router.push({path:"/patient/patient/hospitalSummary/print?id="+this.form.id+"&patient_id="+this.patient_id})
      },
      tableRow(){

       },
      changeCurrentRecordTwo(row){
       
        this.form.id = 0
        if(row!=null){
          this.form.id = row.id 
          this.getHospitalSummaryDetail(row.id)
        }
      },
      selectSummary(row){
        var arr = []
        for(let i=0;i<row.length;i++){
          arr.push(row[i].id)
        }
       var ids = arr.join(",")
       this.ids = ids
      },
      changeAmittDiagnosis(content){
        
        this.form.admitting_diagnosis = content
      },
      changeDischargeDiagnosis(content){
       
         this.form.discharge_diagnosis = content
      },
      changeDiagnosisAdmission(content){
      
       this.form.diagnosis_admission = content
      },
      changeTreatment(content){
       
        this.form.treatment = content
      },
      changeillnessDisCharge(content){
      
        this.form.illness_discharge = content
      },
      changeDischargeAdvice(content){
      
        this.form.discharge_advice = content
      },
      createAction(){
       
         var admitting_diagnosis_id = ""
         var discharge_diagnosis_id = ""
         var diagnosis_admission_id = ""
         var treatment_id = ""
         var illness_discharge_id=""
         var discharge_advice_id= ""
         
         if(this.templates!=undefined){
            for(let i=0;i<this.templates.length;i++){
            if(this.form.admitting_diagnosis_id == this.templates[i].content){
            
                admitting_diagnosis_id = this.templates[i].title
              }
          }
         }
       
         if(this.templatesOne!=undefined){
          for(let i=0;i<this.templatesOne.length;i++){
           if(this.form.discharge_diagnosis_id == this.templatesOne[i].content){
              discharge_diagnosis_id = this.templatesOne[i].title
            }
          }
         }
         
         if(this.templatesTwo!=undefined){
          for(let i=0;i<this.templatesTwo.length;i++){
            if(this.form.diagnosis_admission_id == this.templatesTwo[i].content){
                diagnosis_admission_id = this.templatesTwo[i].title
              }
          }
         }
        
        if(this.templatesThree!=undefined){
         for(let i=0;i<this.templatesThree.length;i++){
           if(this.form.treatment_id == this.templatesThree[i].content){
              treatment_id = this.templatesThree[i].title
            }
         }
        }
        
        if(this.templatesFour!=undefined){
          for(let i=0;i<this.templatesFour.length;i++){
           if(this.form.illness_discharge_id == this.templatesFour[i].content){
              illness_discharge_id = this.templatesFour[i].title
            }
         }
        }
         
        if(this.templatesFive!=undefined){
         for(let i=0;i<this.templatesFive.length;i++){
           if(this.form.discharge_advice_id == this.templatesFive[i].content){
              discharge_advice_id = this.templatesFive[i].title
            }
         }
        }

       
         if(this.form.doctor == ""){
            this.form.doctor = 0
         }
         if(this.form.dean == ""){
           this.form.dean = 0
         }
        
         var params = {
          patient_id:parseInt(this.patient_id),
          title:this.form.title,
          admission_time:this.form.admission_time,
          discharge_time:this.form.discharge_time,
          sick_personnel:this.form.sick_personnel,
          xray:this.form.xray,
          admitting_diagnosis_id:admitting_diagnosis_id,
          admitting_diagnosis:this.$refs.editor.content,
          discharge_diagnosis:this.$refs.editorOne.content,
          discharge_diagnosis_id:discharge_diagnosis_id,
          diagnosis_admission_id:diagnosis_admission_id,
          diagnosis_admission:this.$refs.editorTwo.content,
          illness_discharge:this.$refs.editorFive.content,
          illness_discharge_id:illness_discharge_id,
          discharge_advice_id:discharge_advice_id,
          discharge_advice:this.$refs.editorSix.content,
          treatment_id:treatment_id,
          treatment:this.$refs.editorFour.content,
          dean:this.form.dean,
          doctor:this.form.doctor,
          record_date:this.form.record_date,
          connecticut:this.form.connecticut,
          nuclear_magnetic_resonance:this.form.nuclear_magnetic_resonance,
          ultrasound:this.form.ultrasound,
          pathology:this.form.pathology,
         }
  
        
         createHospitalSummary(params).then(response=>{
            if(response.data.state == 1){
              var list = response.data.data.list
              this.form.title = ""
              this.form.sick_personnel = ""
              this.form.xray = ""
              this.form.admitting_diagnosis = ""
              this.form.discharge_diagnosis = ""
              this.form.diagnosis_admission = ""
              this.form.illness_discharge = ""
              this.form.discharge_advice = ""
              this.form.treatment = ""
              this.form.connecticut = ""
              this.form.nuclear_magnetic_resonance = ""
              this.form.ultrasound = ""
              this.form.pathology = ""
              this.form.admitting_diagnosis_id = ""
              this.form.discharge_diagnosis_id = ""
              this.form.illness_discharge_id = ""
              this.form.discharge_advice_id  =""
              this.form.treatment_id = ""
              this.$message.success("保存成功!")
              this.show_dialog = false
              this.getlist()
            }
         })
      },
      getAllDoctorList(){
       getAllDoctorList().then(response=>{
          if(response.data.state == 1){
            var list = response.data.data.list

            this.doctorList = list
          }
       })
      },
      getTime(val) {
         if(val == ""){
          return ""
         }else {
          return uParseTime(val, '{y}-{m}-{d}')
         }
      },

      getlist(){
          var params = {
            start_time:this.start_time,
            end_time:this.end_time,
            patient_id:parseInt(this.patient_id),
          }
        getHospitalSummaryList(params).then(response=>{
           if(response.data.state ==1){
             var list =  response.data.data.list
             this.tableData = list
           }
        })
      },
      getDoctor(id){
        var name = ""
        for(let i=0;i<this.doctorList.length;i++){
          if(id == this.doctorList[i].admin_user_id){
             name = this.doctorList[i].user_name
          }
        }
        return name
      },
      getHospitalSummaryDetail(id){
        getHospitalSummaryDetail(id).then(response=>{
           if(response.data.state == 1){
             var detail = response.data.data.detail
            
             this.hosDetail = detail
           }
        })
      },
      getHospitalSummaryDetailOne(id){
        getHospitalSummaryDetail(id).then(response=>{
           if(response.data.state == 1){
             var detail = response.data.data.detail
  
             if(detail.doctor == 0){
               this.form.doctor = ""
             }
             if(detail.dean == 0){
               this.form.dean = ""
             }
             this.form.id = detail.id
             this.form.title = detail.title
             this.form.patient_id = detail.patient_id
             this.form.admission_time = this.getTime(detail.admission_time)
             this.form.discharge_time = this.getTime(detail.discharge_time)
             this.form.sick_personnel = detail.sick_personnel
             this.form.xray = detail.xray
             this.form.connecticut = detail.connecticut
             this.form.nuclear_magnetic_resonance = detail.nuclear_magnetic_resonance
             this.form.ultrasound = detail.ultrasound
             this.form.pathology = detail.pathology
             this.form.admitting_diagnosis_id = detail.admitting_diagnosis_id
             this.form.admitting_diagnosis = detail.admitting_diagnosis
             this.form.discharge_diagnosis = detail.discharge_diagnosis
           
             this.form.discharge_diagnosis_id = detail.discharge_diagnosis_id
             this.form.diagnosis_admission_id = detail.diagnosis_admission_id
             this.form.diagnosis_admission = detail.diagnosis_admission
       
             this.form.treatment_id = detail.treatment_id
             this.form.treatment = detail.treatment
             this.form.illness_discharge_id = detail.illness_discharge_id
             this.form.illness_discharge = detail.illness_discharge
             this.form.discharge_advice_id = detail.discharge_advice_id
             this.form.discharge_advice = detail.discharge_advice
             this.form.record_time = this.getTime(detail.record_time)
             this.form.record_date = this.getTime(detail.record_date)
             this.form.dean = detail.dean_id
             this.form.doctor = detail.doctor
             this.edit_show_dialog = true
           }
        })
      },
      toEdit(){
        this.getHospitalSummaryDetailOne(this.form.id)
      },
      updateAction(){
         var admitting_diagnosis_id = this.form.admitting_diagnosis_id
         var discharge_diagnosis_id = this.form.discharge_diagnosis_id
         var diagnosis_admission_id = this.form.diagnosis_admission_id
         var treatment_id = this.form.treatment_id
         var illness_discharge_id= this.form.illness_discharge_id
         var discharge_advice_id= this.form.discharge_advice_id

         if(this.templates!=undefined){
            for(let i=0;i<this.templates.length;i++){
            if(this.form.admitting_diagnosis_id == this.templates[i].content){
            
                admitting_diagnosis_id = this.templates[i].title
              }
          }
         }
        
        
         if(this.templatesOne!=undefined){
          for(let i=0;i<this.templatesOne.length;i++){
           if(this.form.discharge_diagnosis_id == this.templatesOne[i].content){
              discharge_diagnosis_id = this.templatesOne[i].title
            }
          }
         }
   
         if(this.templatesTwo!=undefined){
          for(let i=0;i<this.templatesTwo.length;i++){
            if(this.form.diagnosis_admission_id == this.templatesTwo[i].content){
                diagnosis_admission_id = this.templatesTwo[i].title
              }
          }
         }
        
        if(this.templatesThree!=undefined){
           for(let i=0;i<this.templatesThree.length;i++){
           if(this.form.treatment_id == this.templatesThree[i].content){
              treatment_id = this.templatesThree[i].title
            }
         }
        }
   
        if(this.templatesFour!=undefined){
            for(let i=0;i<this.templatesFour.length;i++){
           if(this.form.illness_discharge_id == this.templatesFour[i].content){
              illness_discharge_id = this.templatesFour[i].title
            }
         }
        }

       if(this.templatesFive!=undefined){
         for(let i=0;i<this.templatesFive.length;i++){
           if(this.form.discharge_advice_id == this.templatesFive[i].content){
              discharge_advice_id = this.templatesFive[i].title
            }
         }
       }
    

      
        if(this.form.doctor == ""){
            this.form.doctor = 0
         }
         if(this.form.dean == ""){
           this.form.dean = 0
         }
        var admitting_diagnosis = ""
        var discharge_diagnosis = ""
        var diagnosis_admission = ""
        var discharge_advice = ""
        var treatment = ""
        var illness_discharge = ""
        if(this.$refs.editorTen.content == ""){
            admitting_diagnosis = this.form.admitting_diagnosis
         }else{
            admitting_diagnosis = this.$refs.editorTen.content
         }
         if(this.$refs.editorSeven.content== ""){
            discharge_diagnosis = this.form.discharge_diagnosis
         }else{
           discharge_diagnosis = this.$refs.editorSeven.content
         }

         if(this.$refs.editorSixty.content == ""){
            diagnosis_admission = this.form.diagnosis_admission
         }else{
           diagnosis_admission = this.$refs.editorSixty.content 
         }
         
         if(this.$refs.editorThirty.content == ""){
            illness_discharge = this.form.illness_discharge
         }else{
           illness_discharge = this.$refs.editorThirty.content
         }

         if(this.$refs.editorTwelve.content == ""){
            discharge_advice = this.form.discharge_advice
         }else{
            discharge_advice = this.$refs.editorTwelve.content
         }

         if(this.$refs.editorNight.content == ""){
            treatment = this.form.treatment
         }else{
            treatment = this.$refs.editorNight.content
         }
         var params = {
          id:this.form.id,
          patient_id:parseInt(this.patient_id),
          title:this.form.title,
          admission_time:this.form.admission_time,
          discharge_time:this.form.discharge_time,
          sick_personnel:this.form.sick_personnel,
          xray:this.form.xray,
          admitting_diagnosis_id:admitting_diagnosis_id,
          admitting_diagnosis:admitting_diagnosis,
          discharge_diagnosis:discharge_diagnosis,
          discharge_diagnosis_id:discharge_diagnosis_id,
          diagnosis_admission_id:diagnosis_admission_id,
          diagnosis_admission:diagnosis_admission,
          illness_discharge:illness_discharge,
          illness_discharge_id:illness_discharge_id,
          discharge_advice_id:discharge_advice_id,
          discharge_advice:discharge_advice,
          treatment_id:treatment_id,
          treatment:treatment,
          dean:this.form.dean,
          doctor:this.form.doctor,
          record_date:this.getTime(this.form.record_date),
          connecticut:this.form.connecticut,
          nuclear_magnetic_resonance:this.form.nuclear_magnetic_resonance,
          ultrasound:this.form.ultrasound,
          pathology:this.form.pathology,
          record_date:this.form.record_date,
         }
      
   
        updateHospitalSummary(params).then(response=>{
          if(response.data.state == 1){
            var detail = response.data.data.detail
            this.edit_show_dialog = false
            // this.$refs.monthlyPlanTable.setCurrentRow(detail)
            this.getlist()
          }
        }) 
      },
      deleteAction(){
          if(this.ids.length == 0){
            this.$message.error("请勾选需要删除的数据")
            return false
          }
          this.$confirm('确认删除吗?', '删除', {
            confirmButtonText: '确 定',
            cancelButtonText: '取 消',
            type: 'warning'
         }).then(() => {
            var params = {
              ids:this.ids,
            }
            deleteHospitalSummary(params).then(response => {
              if (response.data.state == 1) {
                  var msg = response.data.data.msg
                  this.getlist()
                  this.$message.success("删除成功")
              } else {
                  this.$message.error("删除失败")
              }
            })
          }).catch(() => {
          }) 
      },
      addAction(){
        this.form.title = ""
        this.form.sick_personnel = ""
        this.form.xray = ""
        this.form.admitting_diagnosis = ""
        this.form.discharge_diagnosis = ""
        this.form.diagnosis_admission = ""
        this.form.illness_discharge = ""
        this.form.discharge_advice = ""
        this.form.treatment = ""
        this.form.connecticut = ""
        this.form.nuclear_magnetic_resonance = ""
        this.form.ultrasound = ""
        this.form.pathology = ""
        this.form.admitting_diagnosis_id = ""
        this.form.discharge_diagnosis_id = ""
        this.form.illness_discharge_id = ""
        this.form.discharge_advice_id  =""
        this.form.treatment_id = "" 
        this.form.dean = ""
        this.form.doctor = ""
        this.form.admission_time = this.getTime(new Date())
        this.form.admission_time = this.getTime(new Date()),
        this.form.discharge_time = this.getTime(new Date()),
        this.form.sick_personnel = this.patient.dialysis_no
        this.show_dialog = true
      },
      getPatientSummaryById(){
        var params = {
          patient_id:this.patient_id,
        }
        getPatientInfo(params).then(response=>{
          if(response.data.state == 1){
            var patient = response.data.data.patient
            this.patient = patient
          
          }
        })
      }
    },
    watch: {
      tableData: function() {
        this.$nextTick(function() {
          this.$refs.monthlyPlanTable.setCurrentRow(this.tableData[0])
        })
      }
    },
  
    
  }
</script>

<style rel="stylesheet/css" lang="scss" scoped>
  .borderBox{
    border: 1px solid #DCDFE6;
    padding: 10px;
    margin-top: 10px;
    border-radius: 4px;
    p{
      font-weight: bold;
      font-size: 20px;
      margin: 10px 0;
    }
  }
  .container {
    margin-left: 180px;
    padding: 20px;
    background: #fff;
    min-height: calc(100vh - 173px);
    margin-bottom: 15px;

  .record {
    padding-top: 20px;
  }

  }
  .record_content_panel {
    border-width: 1px;
    border-style: solid;
    border-color: #ebeef5;
    min-height: 200px;

  .title {
    font-size: 14px;
    font-weight: 500;
    color: #909399;
    line-height: 44px;
    height: 44px;
    text-align: center;
    border-bottom-width: 1px;
    border-bottom-style: solid;
    border-bottom-color: #ebeef5;
  }

  .content {
    padding: 12px 15px;
    font-size: 15px;
    color: gray;
    line-height: 22px;
  }

  }

  .new_record_form {

  /*/ / padding: 10 px, 25 px;*/

  .textarea_panel {
    margin-top: 10px;
  }

  }
</style>
<style>
.el-table td,
.el-table th.is-leaf,
.el-table--border,
.el-table--group {
  border-color: #d0d3da;
}
.el-table--border::after,
.el-table--group::after,
.el-table::before {
  background-color: #d0d3da;
}
.el-select-dropdown {
  max-width: 1000px !important;
}
</style>
