<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="show_dialog = true">新增</el-button>

                        <el-button type="primary" icon="el-icon-edit-outline" size="small"
                                   @click="showEdit">修改</el-button>
                      <el-button type="primary" icon="el-icon-printer" size="small"
                                 @click="print">打印</el-button>
                        <el-button size="small" v-show="selectingRows.length > 0" type="danger"
                                   @click="deleteAction">删除</el-button>
                    </span>
        </div>
        <!--<div></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="inspection_table" :data="inspectionList"
                        border highlight-current-row @current-change="changeCurrentRecordTwo"
                        :row-class-name="tableRow"
              >
                <el-table-column type="selection" width="40" align="center"></el-table-column>
                <el-table-column label="检查项目" align="center">
                  <template slot-scope="scope">
                     {{scope.row.title}}
                  </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>阶段小结时间:{{getTime(editObj.record_time)}}</div>  
                <el-divider></el-divider>
                <div>阶段小结概要:</div>  
                <div>
                  <span>干体重:{{editObj.drg_weight}}</span>
                  <span>共透析:{{editObj.dialysis_count}}</span>
                  <span>HD:{{editObj.hd_count}}</span>
                  <br>
                  <span>HDF:{{editObj.hdf_count}}</span>
                  <span>HP:{{editObj.hp_count}}</span>
                  <span>其他:{{editObj.other_count}}</span>
                   <br>
                  <span>透析器:{{editObj.dialzer_apparatus}}</span>
                  <span>抗凝剂:{{editObj.anticoagulant}}</span>
                  <span>透析液:(钾:{{editObj.kalium}} 钙:{{editObj.autunite}} Na:{{editObj.natrium}})</span>
                  <br>
                  <span>每次透析（小时）:{{editObj.hour}}</span>
                  <span>透前体重（kg）:{{editObj.befor_weight}}</span>
                  <span>透后体重（kg）:{{editObj.after_weight}}</span>
                  <br>
                  <span>透前血压（mmHg):{{editObj.befor_pressure}}</span>
                  <span>透后血压（mmHg):{{editObj.after_pressure}}</span>
                </div>
                <el-divider></el-divider>
                <div>阶段小结总结:{{editObj.template_inspection_content}}</div>  
                <el-divider></el-divider>
                <div>阶段小结个体化透析方案:{{editObj.template_plan_content}}</div>  
                <div></div>
              </div>
            </el-col>
          </el-row>
        </div>
      </div>
     
      <el-dialog title="新增阶段小结" width="80%" top="5vh" :visible.sync="show_dialog">
        <div>
          <div class="new_record_form">
            <div class="cell clearfix">
              <el-form  :model="form" ref="form">
                <el-row :gutter="24">
                  <el-col :span="20">
                    <el-form-item label="阶段小结名称:">
                      <el-input v-model="form.title"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                 <el-row :gutter="24">
                  <el-col :span="8">
                    <el-form-item label="阶段小结时间:">
                        <el-date-picker
                            v-model="form.start_year"
                            type="year"
                            value-format="yyyy-MM-dd"
                            placeholder="选择年">
                        </el-date-picker>
                    </el-form-item> 
                  </el-col>
                  <el-col :span="8">
                    <el-form-item>
                      <el-radio-group v-model="form.radio">
                        <el-radio :label="1" >月份</el-radio>
                        <el-radio :label="2" >季度</el-radio>
                     </el-radio-group>
                    </el-form-item> 
                  </el-col>
                  
                  <el-col :span="8" v-if="form.radio == 1">
                    <el-form-item>
                      <el-date-picker
                        value-format="MM"
                        v-model="form.start_month"
                        type="month"
                        placeholder="选择月">
                      </el-date-picker>
                    </el-form-item> 
                  </el-col>
                  <el-col :span="8" v-if="form.radio == 2">
                    <el-form-item>
                       <el-select v-model="form.quarter" placeholder="请选择">
                        <el-option
                          v-for="item in timeType"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id">
                        </el-option>
                      </el-select>
                    </el-form-item> 
                  </el-col> 
                 </el-row>  
                
              </el-form>
            </div>

            <div class="cell clearfix" style="margin-top: 10px">
              <label class="title"><span class="name">阶段小结摘要</span> : </label>
              <el-form>
                  <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="干体重">
                      <el-input v-model="form.dry_weight"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="共透析(次)">
                      <el-input v-model="form.dialysis_count"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="HD(次)">
                      <el-input v-model="form.hd_count"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="HDF(次)">
                      <el-input v-model="form.hdf_count"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="HP(次)">
                      <el-input v-model="form.hp_count"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="其他(次)">
                      <el-input v-model="form.other_count"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                   <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="透析器">
                       <el-input v-model="form.dialzer_apparatus" @focus="showInnerDialog('7')"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="灌流器">
                        <el-input v-model="form.perfusion_apparatus" @focus="showInnerDialog('8')"></el-input>
                      </el-form-item>  
                    </el-col>

                    <el-col :span="8">
                     <el-form-item label="抗凝剂">
                      <!-- <el-input v-model="form.anticoagulant"></el-input> -->
                       <el-select v-model="form.anticoagulant" placeholder="请选择" style="width:100%;">
                          <el-option :key="0" label="请选择" :value="0"></el-option>
                          <el-option v-for="(item, index) in anticoagulantList" :label="item.name" :key="index + 'e'"
                           :value="item.id"></el-option>
                       </el-select>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                   <div>透析液</div>
                   <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="钾">
                      <el-input v-model="form.kalium"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="钙">
                      <el-input v-model="form.autunite"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="钠">
                      <el-input v-model="form.natrium"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                   <div>透析时长</div>
                   <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="时">
                      <el-input v-model="form.hour"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="分">
                      <el-input v-model="form.minute"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="透前体重(kg)">
                      <el-input v-model="form.befor_weight"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="透后体重(kg)">
                      <el-input v-model="form.after_weight"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                   <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="透前血压(mmHg)">
                      <el-input v-model="form.befor_pressure"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="透后血压(mmHg)">
                      <el-input v-model="form.after_pressure"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                 
                  <el-row>
                    <label class="title"><span class="name">阶段小结总结</span> : </label>
                     <el-select v-model="form.template_summary_id" placeholder="请选择" @change="changeSummary">
                        <el-option
                        v-for="item in summaryList"
                        :key="item.value"
                        :label="item.content"
                        :value="item.value">
                        </el-option>
                     </el-select>
                     <el-input tyep="text" v-model="form.template_summary_content"></el-input>
                  </el-row>
                  <el-row>
                    <label class="title"><span class="name">阶段小结个体化透析方案</span> : </label>
                     <el-select v-model="form.template_plan_id" placeholder="请选择" @change="changeTempalte">
                        <el-option
                        v-for="item in planList"
                        :key="item.value"
                        :label="item.content"
                        :value="item.value">
                        </el-option>
                     </el-select>
                     <el-input tyep="text" v-model="form.template_plan_content"></el-input>
                  </el-row>
                  <el-row>
                    <label class="title"><span class="name">阶段小结化验结果</span> : </label>
                    <el-button type="primary" @click="toInspection">选择检验检查</el-button>
                     <el-input tyep="text" v-model="form.template_inspection_content"></el-input>
                  </el-row>
                  <el-row>
                    <el-col :span="8">
                      <el-form-item label="记录医生">
                        <el-select v-model="form.admin_user_id" placeholder="请选择">
                            <el-option
                            v-for="item in docList"
                            :key="item.admin_user_id"
                            :label="item.user_name"
                            :value="item.admin_user_id">
                            </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="记录时间">
                         <el-date-picker
                            v-model="form.record_time"
                            type="datetime"
                            placeholder="选择日期时间">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                  </el-row>
              </el-form>
            </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="saveCreation()">保存
              </el-button>
            </div>
          </div>
        </div>
      </el-dialog>

      
      <!-- 编辑阶段小结 -->
       <el-dialog title="编辑阶段小结" width="80%" top="5vh" :visible.sync="edit_show_dialog">
        <div>
          <div class="new_record_form">
            <div class="cell clearfix">
              <el-form  :model="form" ref="form">
                <el-row :gutter="24">
                  <el-col :span="20">
                    <el-form-item label="阶段小结名称:">
                      <el-input v-model="form.title"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                 <el-row :gutter="24">
                  <el-col :span="8">
                    <el-form-item label="阶段小结时间:">
                        <el-date-picker
                            v-model="form.start_year"
                            type="year"
                            value-format="yyyy-MM-dd"
                            placeholder="选择年">
                        </el-date-picker>
                    </el-form-item> 
                  </el-col>
                  <el-col :span="8">
                    <el-form-item>
                      <el-radio-group v-model="form.radio">
                        <el-radio :label="1" >月份</el-radio>
                        <el-radio :label="2" >季度</el-radio>
                     </el-radio-group>
                    </el-form-item> 
                  </el-col>
                  
                  <el-col :span="8" v-if="form.radio == 1">
                    <el-form-item>
                      <el-date-picker
                        value-format="MM"
                        v-model="form.start_month"
                        type="month"
                        placeholder="选择月">
                      </el-date-picker>
                    </el-form-item> 
                  </el-col>
                  <el-col :span="8" v-if="form.radio == 2">
                    <el-form-item>
                       <el-select v-model="form.quarter" placeholder="请选择">
                        <el-option
                          v-for="item in timeType"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id">
                        </el-option>
                      </el-select>
                    </el-form-item> 
                  </el-col> 
                 </el-row>  
                
              </el-form>
            </div>

            <div class="cell clearfix" style="margin-top: 10px">
              <label class="title"><span class="name">阶段小结摘要</span> : </label>
              <el-form>
                  <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="干体重">
                      <el-input v-model="form.dry_weight"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="共透析(次)">
                      <el-input v-model="form.dialysis_count"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="HD(次)">
                      <el-input v-model="form.hd_count"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="HDF(次)">
                      <el-input v-model="form.hdf_count"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="HP(次)">
                      <el-input v-model="form.hp_count"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="其他(次)">
                      <el-input v-model="form.other_count"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                   <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="透析器">
                       <el-input v-model="form.dialzer_apparatus" @focus="showInnerDialog('7')"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="灌流器">
                        <el-input v-model="form.perfusion_apparatus" @focus="showInnerDialog('8')"></el-input>
                      </el-form-item>  
                    </el-col>

                    <el-col :span="8">
                     <el-form-item label="抗凝剂">
                      <!-- <el-input v-model="form.anticoagulant"></el-input> -->
                       <el-select v-model="form.anticoagulant" placeholder="请选择" style="width:100%;">
                          <el-option :key="0" label="请选择" :value="0"></el-option>
                          <el-option v-for="(item, index) in anticoagulantList" :label="item.name" :key="index + 'e'"
                           :value="item.id"></el-option>
                       </el-select>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                   <div>透析液</div>
                   <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="钾">
                      <el-input v-model="form.kalium"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="钙">
                      <el-input v-model="form.autunite"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="钠">
                      <el-input v-model="form.natrium"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                   <div>透析时长</div>
                   <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="时">
                      <el-input v-model="form.hour"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="分">
                      <el-input v-model="form.minute"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                  <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="透前体重(kg)">
                      <el-input v-model="form.befor_weight"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="透后体重(kg)">
                      <el-input v-model="form.after_weight"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                   <el-row :gutter="24">
                    <el-col :span="8">
                     <el-form-item label="透前血压(mmHg)">
                      <el-input v-model="form.befor_pressure"></el-input>
                     </el-form-item>  
                    </el-col>
                    <el-col :span="8">
                     <el-form-item label="透后血压(mmHg)">
                      <el-input v-model="form.after_pressure"></el-input>
                     </el-form-item>  
                    </el-col>
                  </el-row>
                 
                  <el-row>
                    <label class="title"><span class="name">阶段小结总结</span> : </label>
                     <el-select v-model="form.template_summary_id" placeholder="请选择" @change="changeSummaryOne">
                        <el-option
                        v-for="item in summaryList"
                        :key="item.value"
                        :label="item.content"
                        :value="item.value">
                        </el-option>
                     </el-select>
                     <el-input tyep="text" v-model="form.template_summary_content"></el-input>
                  </el-row>
                  <el-row>
                    <label class="title"><span class="name">阶段小结个体化透析方案</span> : </label>
                     <el-select v-model="form.template_plan_id" placeholder="请选择" @change="changeTempalte">
                        <el-option
                        v-for="item in planList"
                        :key="item.value"
                        :label="item.content"
                        :value="item.value">
                        </el-option>
                     </el-select>
                     <el-input tyep="text" v-model="form.template_plan_content"></el-input>
                  </el-row>
                  <el-row>
                    <label class="title"><span class="name">阶段小结化验结果</span> : </label>
                    <el-button type="primary" @click="toInspection">选择检验检查</el-button>
                     <el-input tyep="text" v-model="form.template_inspection_content"></el-input>
                  </el-row>
                  <el-row>
                    <el-col :span="8">
                      <el-form-item label="记录医生">
                        <el-select v-model="form.admin_user_id" placeholder="请选择">
                            <el-option
                            v-for="item in docList"
                            :key="item.admin_user_id"
                            :label="item.user_name"
                            :value="item.admin_user_id">
                            </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="记录时间">
                         <el-date-picker
                            v-model="form.record_time"
                            type="datetime"
                            placeholder="选择日期时间">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                  </el-row>
              </el-form>
            </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="editCreation()">保存
              </el-button>
            </div>
          </div>
        </div>
      </el-dialog>

       <el-dialog
        title="提示"
        :visible.sync="dialogVisibleInspection"
        width="80%"
        >
        <span>
          <el-form>
            <el-row>
              <el-form-item>
                <span>选择检验检查时间:</span>
                <div>
                  <el-form-item
                   label="年份:"
                   prop="startYear"
                   style="width:100%;"
                 >
                 <el-date-picker 
                    v-model="startYear" 
                    class="timePicker" 
                    type="month" 
                    placeholder=""
                    format="yyyy-MM" 
                    value-format="yyyy-MM">
	               </el-date-picker>
                 </el-form-item>
                 <!-- <el-form-item  label="月份:"
                   prop="startYear"
                   style="width:100%;">     
                  <el-date-picker
                    v-model="startMonth"
                    type="month"
                    format="MM"
                    value-format="MM"
                    placeholder="请选择">
                  </el-date-picker>  
                 </el-form-item> -->
                </div>
              </el-form-item>
            </el-row>
            <el-row>
               <span>选择检验检查项目:</span>
                 <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' }" :data="tableList"
                                border highlight-current-row @current-change="changeCurrentRecord"
                                @selection-change="selectionChangeOne"
                                :row-class-name="tableRow"
                                @row-click="onRowClick"
                                ref="single_table"
                      >
                        <el-table-column type="selection" width="40" align="center"></el-table-column>
                        <el-table-column label="检验项目" align="center">
                          <template slot-scope="scope">
                            {{scope.row.project_name}}
                          </template>
                        </el-table-column>
                      </el-table>
                    </el-col>
                    <el-col :span="14">
                      <div class="record_content_panel">
                        <el-table :header-cell-style="{
                          backgroundColor: 'rgb(245, 247, 250)',
                          color: '#606266'
                        }"
                        :row-style="{ color: '#303133' }" :data="tableData"
                                border highlight-current-row @current-change="didChangeCurrentRecord"
                                @selection-change="selectionChange"
                                :row-class-name="tableRow"
                                
                      >
                        <el-table-column label="检验项目" align="center">
                          <template slot-scope="scope">
                            {{scope.row.item_name}}
                          </template>
                        </el-table-column>
                        <el-table-column label="结果" align="center">
                          <template slot-scope="scope">
                           <span v-if="parseInt(scope.row.inspect_value) < parseInt(scope.row.range_min)">
                             {{scope.row.inspect_value}}↓
                          </span> 
                           <span v-if="parseInt(scope.row.inspect_value) > parseInt(scope.row.range_max)">
                             {{scope.row.inspect_value}}↑
                          </span> 
                          </template>
                        </el-table-column>
                        <el-table-column label="参考值" align="center">
                          <template slot-scope="scope">
                           {{scope.row.range_min}} ~  {{scope.row.range_max}}
                          </template>
                        </el-table-column>
                        <el-table-column label="单位" align="center">
                          <template slot-scope="scope">
                            {{scope.row.unit}}
                          </template>
                        </el-table-column>
                      </el-table>
                      </div>
                    </el-col>
                  </el-row>
                </div>
            </el-row>
          </el-form>

        </span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleInspection = false">取 消</el-button>
          <el-button type="primary" @click="toContent">确 定</el-button>
        </span>
      </el-dialog>
      
       
  

      <multi-select-box
        :propsForm="InnerDialogProps"
        v-on:dialog-comfirm="innerDialogComfirm"
        v-on:dialog-cancle="innerDialogCancle"
      ></multi-select-box>

    </div>
  </div>

  <!-- </div> -->
</template>

<script>
  import PatientSidebar from './components/PatientSidebar'
  import Editor from '@/components/Editor'
 
  import { getInitDataList,getInspectionMajorItem,getInspectionDetail,getInspectionItemList,saveCreation,getTemplateSummaryList,getTemplateSummaryDetail,UpdateTemplateSummary } 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'
  const moment = require('moment')
  export default {
    name: 'templateSummary',
    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,
        templates: this.$store.getters.configlist.course_disease,
        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:"",
          start_year:new Date(),
          start_month:new Date(),
          radio:1,
          quarter:1,
          dry_weight:"",
          dialysis_count:"",
          hd_count:"",
          hdf_count:"",
          hp_count:"",
          other_count:"",
          dialzer_apparatus:"",
          perfusion_apparatus:"",
          anticoagulant:"",
          kalium:"",
          autunite:"",
          natrium:"",
          houer:"",
          minute:"",
          befor_weight:"",
          after_weight:"",
          befor_pressure:"",
          after_pressure:"",
          template_summary_id:"",
          template_summary_content:"",
          template_plan_id:"",
          template_summary_content:"",
          template_inspection_id:0,
          template_inspection_content:"",
          admin_user_id:this.$store.getters.xt_user.user.id,
          record_time:new Date(),
          patient_id:"",
          start_time:"",
          end_time:"",
        },
        timeType:[
          {id:1,name:"第一季度"},
          {id:2,name:"第二季度"},
          {id:3,name:"第三季度"},
          {id:4,name:"第四季度"},
        ],
        options:[],
        dialogVisibleInspection:false,
        editDialogVisible:false,
        edit_show_dialog:false,
        InspectionMajor:[],
        other_start_time:"",
        startYear:new Date(),
        startMonth:(new Date().getMonth+1).toString(),
        tableList:[],
        tableData:[],
        inspectDataList:[],
        projectList:[],
        docList:[],
        inspectionList:[],
        editObj:{},
        anticoagulantList:[],
        dialyzerPerfusionApparatus:[],
        irrigations:[],
        dialyzerList:[],
        irrigationList:[],
        stockType:[],
        summaryList:[],
        planList:[],
      }
    },
    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)
      var anticoagulantsConfitOne = this.$store.getters.anticoagulants_confit
       const arrFour = []
        Object.keys(anticoagulantsConfitOne).map((item, index) => {
          if (index != 2) {
            arrFour.push(anticoagulantsConfitOne[item])
          }
        })

      this.anticoagulantList = arrFour
      console.log("抗凝剂量",this.anticoagulantList)
  
      this.getlist()
      this.getInspectionMajor()
      this.getTemplateSummaryList()
     
    },
    methods: {
      getTime(val) {
         if(val < 0){
           return ""
         }
         if(val == ""){
          return ""
         }else {
          return uParseTime(val, '{y}-{m}-{d}')
         }
      },
      showEdit(){
       
        this.getCurrentRecordDetailOne()
      },
      deleteAction(){

      },
      onRowClick(){

      },
      didChangeCurrentRecord(){

      },
      changeCurrentRecord(val){
        this.getInspectionDetai(val)
      },
      selectionChangeOne(val){
        console.log("val23232323",val)
       
        this.getInspectionItemList(val)
      },
      startTimeChange(){

      },
      endTimeChange(){

      },
      print(){
        this.$router.push({path:"/patient/patient/templateSummary/print?id="+this.form.id})
      },
      tableRow(){

      },
      getQuarter(year,quarter){
        var start_time = ""
        if(quarter == 1){
           
        }

        // DateTime dt = new DateTime();
        // switch (quarter)
        // {
        //     case "第一季度":
        //         dt = new DateTime(year, 1, 1);
        //         break;
        //     case "第二季度":
        //         dt = new DateTime(year, 4, 1);         
        //         break;
        //     case "第三季度":
        //         dt = new DateTime(year, 7, 1);           
        //         break;
        //     case "第四季度":
        //         dt = new DateTime(year, 10, 1);             
        //         break;

        // }

      },
      didSelectionChange(){

      },
      changeCurrentRecordTwo(val){
        this.form.id = val.id
        this.getCurrentRecordDetail(val.id)
      },
      changeCurrentRecordOne(){

      },
      getlist(){
        var params={
          start_year:this.getTime(this.form.start_year),
          start_month:this.getTime(this.form.start_month),
          quarter:this.form.quarter,
          patient_id:this.patient_id,
        }
        console.log("param222222",params)
        console.log(moment(moment(2020 + '-01-01').toDate()).quarter(2).format("YYYY-MM-DD"))
        getInitDataList(params).then(response=>{
          if(response.data.state == 1){
             var prescription_list =  response.data.data.prescription_list
             console.log("prescription_list",prescription_list)
           
             this.form.dialzer_apparatus = prescription_list.dialysis_dialyszers
             this.form.perfusion_apparatus = prescription_list.dialysis_irrigation
             this.form.anticoagulant = prescription_list.anticoagulant
             this.form.hour = prescription_list.dialysis_duration_hour
             this.form.minute = prescription_list.dialysis_duration_minute
             this.form.kalium = prescription_list.kalium
             this.form.natrium = prescription_list.sodium
             this.form.autunite = prescription_list.calcium
             var beforlist = response.data.data.beforlist
             console.log("beforlist",beforlist)
             this.form.befor_weight = beforlist.befor_weight
             this.form.dry_weight = beforlist.dry_weight
             var afterlist =  response.data.data.after_list
             console.log("afterlist",afterlist)
             this.form.after_weight = afterlist.weight_after
             this.form.after_pressure = afterlist.systolic_blood_pressure + "/"+afterlist.diastolic_blood_pressure
             this.form.befor_pressure = beforlist.systolic_blood_pressure +"/"+beforlist.diastolic_blood_pressure
             var modelist = response.data.data.modelist
             var docList = response.data.data.docList
             console.log("doctlist",docList)
             this.docList = docList
             var stockType = response.data.data.stockType
             var arr = []
            var arrTwo = []
            for(let i=0;i<stockType.length;i++){
              if(stockType[i].stock_attribute == 2){
                  arr.push(stockType[i])
              }
              if(stockType[i].stock_attribute == 3){
                  arrTwo.push(stockType[i])
              }
            }
            var dialyzator = []
            var irrigation = []
            for(let i=0;i<arr.length;i++){
              for(let j=0;j<arr[i].GoodInfo.length;j++){
                  dialyzator.push(arr[i].GoodInfo[j])
              }
            }
            this.dialyzerList = dialyzator
            console.log("arrtt2323232332232323",arrTwo)
            for(let i=0;i<arrTwo.length;i++){
              for(let j=0;j<arrTwo[i].GoodInfo.length;j++){
                  irrigation.push(arrTwo[i].GoodInfo[j])
              }
            }
            this.irrigationList = irrigation
            console.log("透析器233223",this.dialyzerList)
            console.log("灌流器323323223",this.irrigationList)
             var count = ""
             var total_count = 0
             for(let i=0;i<modelist.length;i++){
               total_count += modelist[i].count
              if(modelist[i].mode_id == 1){
                 this.form.hd_count = modelist[i].count
              }
              if(modelist[i].mode_id == 2){
                this.form.hdf_count =  modelist[i].count
              }
              if(modelist[i].mode_id == 4){
                this.form.hp_count = modelist[i].count
              }

              if(modelist[i].mode_id!=1&&modelist[i].mode_id!=2 && modelist[i].mode_id!=4){
                  count += modelist[i].count
              }

             }
             this.form.other_count = count
             this.form.dialysis_count = total_count
             console.log("modelist",modelist)
             var summaryList = response.data.data.summaryList
             console.log("summaryList",summaryList)
             this.summaryList = summaryList
             var planList = response.data.data.planList
             console.log("planlist",planList)
             this.planList = planList
          }
       })
      },
      toInspection(){
        
        this.dialogVisibleInspection = true
      },

      //获取大项数据来源
      getInspectionMajor(){
          var params = {
            other_start_time:this.getTime(this.startYear),
            patient_id:this.patient_id,
          }
        console.log("params",params)
        getInspectionMajorItem(params).then(response=>{
          if(response.data.state == 1){
            var list = response.data.data.list
            console.log("list23232323",list)
            this.tableList = list
            // this.$refs.single_table.setCurrentRow(this.tableList[0])
          }
        })
      },
      //获取小项的值
      getInspectionDetai(val){
        var params = {
          project_id:val.project_id,
          patient_id:val.patient_id,
          inspect_date:val.inspect_date,
        }
        console.log("param2233233223",params)
       getInspectionDetail(params).then(response=>{
          if(response.data.state ==1){
            var list = response.data.data.list
            console.log("详情222",list)
            this.tableData = list
          }
       })
      },
      selectionChange(val){
        console.log("val233223",val)
        selectionChange().then(response=>{

        })
      },
      getInspectionItemList(val){
       
       for(let i=0;i<val.length;i++){
        this.projectList.push(val[i].project_id)
        this.inspectDataList.push(val[i].inspect_date)
      }
    
      },
      toContent(){
      
         var str = this.projectList.join(",")
         var inspe_date = this.inspectDataList.join(",")
         var params = {
           ids:str,
           inspect_date:inspe_date,
           patient_id:this.patient_id,
         }
         console.log("params",params)
        getInspectionItemList(params).then(response=>{
           if(response.data.state == 1){
             var list = response.data.data.list
             console.log("选择检验检查",list)
             var str = ""
             for(let i=0;i<list.length;i++){
               str += (list[i].item_name + ":" + list[i].inspect_value+"<br>")
             }
           
             this.form.template_inspection_content = str
            this.dialogVisibleInspection = false
            this.projectList = []
            this.inspectDataList = []
           }
        })  
      },
      saveCreation(){
        console.log("hh2h32232332",this.form.title)
         var params = {
            title:this.form.title,
            dry_weight:parseInt(this.form.dry_weight),
            dialysis_count:parseInt(this.form.dialysis_count),
            hd_count:parseInt(this.form.hd_count),
            hdf_count:parseInt(this.form.hdf_count),
            hp_count:parseInt(this.form.hp_count),
            other_count:parseInt(this.form.other_count),
            dialzer_apparatus:this.form.dialzer_apparatus,
            perfusion_apparatus:this.form.perfusion_apparatus,
            anticoagulant:this.form.anticoagulant,
            kalium:parseInt(this.form.kalium),
            autunite:parseInt(this.form.autunite),
            natrium:parseInt(this.form.natrium),
            hour:parseInt(this.form.hour),
            minute:parseInt(this.form.minute),
            befor_weight:parseInt(this.form.befor_weight),
            after_weight:parseInt(this.form.after_weight),
            befor_pressure:parseInt(this.form.befor_pressure),
            template_summary_content:this.form.template_summary_content,
            template_plan_content:this.form.template_plan_content,
            template_inspection_content:this.form.template_inspection_content,
            admin_user_id:this.form.admin_user_id,
            record_time:this.form.record_time,
            after_pressure:this.form.after_pressure,
            template_summary_id:this.form.template_summary_id,
            template_summary_content:this.form.template_summary_content,
            template_plan_id:this.form.template_plan_id,
            template_inspection_id:this.form.template_inspection_id,
            patient_id:this.patient_id,
         }
         console.log("parawm232323223",params)
        saveCreation(params).then(response=>{
           if(response.data.state ==1){
             var summary =  response.data.data.summary
             console.log("summary",summary)
             this.$message.success("保存成功!");
             this.show_dialog = false
             this.form.title = ""
             this.form.dry_weight = ""
             this.form.dialysis_count =""
             this.form.hd_count= ""
             this.form.hdf_count = ""
             this.form.hp_count = ""
             this.form.other_count =""
             this.form.dialzer_apparatus = ""
             this.form.perfusion_apparatus = ""
             this.form.anticoagulant  = ""
             this.form.kalium = ""
             this.form.autunite = ""
             this.form.natrium = ""
             this.form.hour =""
             this.form.minute = ""
             this.form.befor_weight = ""
             this.form.after_weight = ""
             this.form.befor_pressure = ""
             this.form.template_summary_content = ""
             this.form.template_plan_content = ""
             this.form.template_inspection_content = ""
             this.form.admin_user_id = ""
             this.form.record_time = ""
             this.from.after_pressure = ""
             this.form.template_summary_id = ""
             this.form.template_plan_id = ""
             this.form.template_inspection_id = ""
           }
        })
      },
      getTemplateSummaryList(){
          var params = {
            patient_id:this.patient_id
          }
        getTemplateSummaryList(params).then(response=>{
           if(response.data.state ==1){
              var list = response.data.data.list
              this.inspectionList = list
              this.$refs.inspection_table.setCurrentRow(this.inspectionList[0])
              this.getCurrentRecordDetail(this.inspectionList[0].id)
           }
        })
      },
      getCurrentRecordDetail(id){
          var params = {
            id:id
          }
         getTemplateSummaryDetail(params).then(response=>{
           if(response.data.state == 1){
              var list = response.data.data.list
              console.log("🔎3232322323232332",list)
              this.editObj = list

           }
        })
      },
      getTime(val) {
         if(val < 0){
           return ""
         }
         if(val == ""){
          return ""
         }else {
          return uParseTime(val, '{y}-{m}-{d}')
         }
      },
     showInnerDialog: function(val) {
        this.InnerDialogProps.visibility = true
        switch (val) {
           case '7': // 透析器

            for(let i=0;i<this.dialyzerList.length;i++){
               this.dialyzerList[i].name = this.dialyzerList[i].specification_name
            }
            this.InnerDialogProps.values = this.dialyzerList
            this.InnerDialogProps.titles = '透析器'
            this.InnerDialogProps.type = 'dialyzers'
            this.InnerDialogProps.selected = this.form.dialzer_apparatus
            this.InnerDialogProps.isShowTextArea = false
            break
           case '8':
           for(let i=0;i<this.irrigationList.length;i++){
             this.irrigationList[i].name = this.irrigationList[i].specification_name
           }
            this.InnerDialogProps.values = this.irrigationList
            this.InnerDialogProps.titles = '灌流器'
            this.InnerDialogProps.type = 'irrigations'
            this.InnerDialogProps.selected = this.form.perfusion_apparatus
            this.InnerDialogProps.isShowTextArea = false
            break
        }
      },
      innerDialogComfirm: function(val) {
        this.InnerDialogProps.visibility = false
        switch (val.type) {
          case 'dialyzers':
           this.form.dialzer_apparatus = val.value.join(',')
          break
          case 'irrigations':
           this.form.perfusion_apparatus = val.value.join(',')
          break
        }
      },
     innerDialogCancle: function() {
        this.InnerDialogProps.visibility = false
      },
      getCurrentRecordDetailOne(){
         var params = {
            id:this.form.id
          }
         getTemplateSummaryDetail(params).then(response=>{
           if(response.data.state == 1){
              var list = response.data.data.list
              console.log("详情22333223",list)
              this.edit_show_dialog = true
              this.form.title = list.title
              this.form.id = list.id
              this.form.admin_user_id = list.admin_user_id
              this.form.after_pressure = list.after_pressure
              this.form.after_weight = list.after_weight
              this.form.anticoagulant = list.anticoagulant
              this.form.autunite = list.autunite
              this.form.befor_pressure = list.befor_pressure
              this.form.befor_weight = list.befor_weight
              this.form.dialysis_count = list.dialysis_count
              this.form.dialzer_apparatus = list.dialzer_apparatus
              this.form.dry_weight = list.dry_weight
               this.form.hd_count= list.hd_count
               this.form.hdf_count= list.hdf_count
               this.form.hour = list.hour
               this.form.hp_count = list.hp_count
               this.form.kalium= list.kalium
               this.form.minute = list.minute
               this.form.natrium =list.natrium
               this.form.perfusion_apparatus= list.perfusion_apparatus
               this.form.record_time = this.getTime(list.record_time)
               this.form.template_inspection_content = list.template_inspection_content
               this.form.template_inspection_id = list.template_inspection_id
               this.form.template_plan_content = list.template_plan_content
               this.form.template_summary_content =list.template_summary_content
               this.form.template_summary_id = list.template_summary_id
           }
        })  
      },
      changeSummary(){
       for(let i=0;i<this.summaryList.length;i++){
         if(this.form.template_summary_id == this.summaryList[i].value){
            this.form.template_summary_content = this.summaryList[i].content
         }
       }
      },
      changeSummaryOne(){
       for(let i=0;i<this.summaryList.length;i++){
         if(this.form.template_summary_id == this.summaryList[i].value){
            this.form.template_summary_content = this.summaryList[i].content
         }
       }
      },
     changeTempalte(){
       for(let i=0;i<this.planList.length;i++){
         if(this.form.template_plan_id == this.planList[i].value){
           this.form.template_plan_content = this.planList[i].content
         }
       }
     },
     editCreation(){
        var params = {
            id:this.form.id,
            title:this.form.title,
            dry_weight:parseInt(this.form.dry_weight),
            dialysis_count:parseInt(this.form.dialysis_count),
            hd_count:parseInt(this.form.hd_count),
            hdf_count:parseInt(this.form.hdf_count),
            hp_count:parseInt(this.form.hp_count),
            other_count:parseInt(this.form.other_count),
            dialzer_apparatus:this.form.dialzer_apparatus,
            perfusion_apparatus:this.form.perfusion_apparatus,
            anticoagulant:this.form.anticoagulant,
            kalium:parseInt(this.form.kalium),
            autunite:parseInt(this.form.autunite),
            natrium:parseInt(this.form.natrium),
            hour:parseInt(this.form.hour),
            minute:parseInt(this.form.minute),
            befor_weight:parseInt(this.form.befor_weight),
            after_weight:parseInt(this.form.after_weight),
            befor_pressure:parseInt(this.form.befor_pressure),
            template_summary_content:this.form.template_summary_content,
            template_plan_content:this.form.template_plan_content,
            template_inspection_content:this.form.template_inspection_content,
            admin_user_id:this.form.admin_user_id,
            record_time:this.form.record_time,
            after_pressure:this.form.after_pressure,
            template_summary_id:this.form.template_summary_id,
            template_summary_content:this.form.template_summary_content,
            template_plan_id:this.form.template_plan_id,
            template_inspection_id:this.form.template_inspection_id,
            patient_id:this.patient_id,
         }
         console.log("parawm232323223",params)

        UpdateTemplateSummary(params).then(response=>{
          if(response.data.state == 1){
            var list = response.data.data.list
            this.$message.success("保存成功")
            this.edit_show_dialog = false
          }
        })
     }
    },
  //  watch: {
  //   inspectionList: function() {
  //     this.$nextTick(function() {
  //       this.$refs.inspection_table.setCurrentRow(this.inspectionList[0])
  //     })
  //   },
   
  //  },
  }
</script>

<style rel="stylesheet/css" lang="scss" scoped>
  .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;
}
</style>
