<template>
  <div>
    <div v-loading="loading">
      <div class="Dialog" v-show="listPanel">
        <div class="DialogTit">
          <span class="iconfont" @click="close()">&#xe6e9;</span>
          <h1 class="name">透析监测</h1>
          <span class="success">&nbsp;</span>
        </div>
        <div><span>上机时间:{{getTimes(dialysis_order.start_time)}}</span></div>
        <div style="width:100%;background: #fff;">
          <div class="yzNav" style="width:80%">
            <span :class="{ forbid: is_has_create != true }" @click="openForm()">新增监测</span>
            <span
              :class="{ forbid: is_has_modify != true && is_has_modify_other != true }"
              @click="openEidtForm()"
            >修改监测</span>
            <span
              :class="{ forbid: is_has_del != true && is_has_del_other != true }"
              @click="deleteForm()"
            >删除监测</span>
          </div>
        </div>
        <div class="DialogContent choose" id="dialogTop">
          <div style="width:100%;overflow:hildden;">
            <table class="table newMonitTable" style>
              <tr @click="selectRow(-1, null)">
                <th v-if="isShow('监测时间')" width="60px">时间</th>
                <th v-if="isShow('血压')" width="60px"> 血压 <br />(mmHg) </th>
                <th v-if="isShow('脉搏')" width="50px"> 脉搏 <br />(次/分) </th>
                <th v-if="isShow('体温')" width="40px"> 体温 <br />(℃) </th>
                <th v-if="isShow('呼吸频率')" width="60px"> 呼吸频率 <br />(次/分) </th>
                <th v-if="isShow('血流量')" width="60px"> 血流量 <br />(ml/min) </th>
                <th width="76px"> 静脉压/动脉压 <br />({{monitorRecords[0]&&monitorRecords[0]['venous_pressure_type'] == 2 ? 'kpa' : 'mmHg'}}) </th>
                <th v-if="isShow('跨膜压')" width="60px"> 跨膜压 <br />({{monitorRecords[0]&&monitorRecords[0]['transmembrane_pressure_type'] == 2 ? 'kpa' : 'mmHg'}}) </th>
                <th v-if="isShow('超滤量') && (template_id ==6 || template_id == 10 || template_id == 11 || template_id == 12 || template_id == 13 || template_id == 17 || template_id == 18 || template_id == 19 || template_id == 20 || template_id == 21 || template_id == 22 || template_id == 23 || template_id == 24 || template_id == 26 || org_id == 9555 || template_id == 27 || template_id == 29 || template_id == 30 || template_id == 31 || template_id == 32 || template_id == 34 || template_id == 35 || template_id == 9  || template_id == 47 || template_id == 48  || template_id == 53  || template_id == 54)" width="50px" > 超滤量 <br />(ml) </th>
                <th v-if="isShow('超滤量') && template_id !=6 && template_id !=10 && template_id !=11 && template_id !=12 && template_id !=13 && template_id !=17 && template_id !=18 && template_id !=19 && template_id !=20 && template_id !=21 && template_id !=22 && template_id !=23 && template_id !=24 && template_id !=26 && org_id !=9555 && template_id!=27 && template_id!=29 && template_id!=30 && template_id!=31 && template_id !=9 && template_id!=32 && template_id!=34 && template_id!=35 && template_id!=47  && template_id!=48 && template_id!=53 && template_id!=54" width="50px" > 超滤量 <br />(L) </th>
                <th v-if="isShow('钠浓度')" width="60px"> 钠浓度 <br />(mmol/L) </th>
                <th v-if="isShow('透析液温度')" width="60px"> 透析液温度 <br />(℃) </th>
                <th v-if="isShow('置换率') && (template_id ==6 || template_id == 10 || template_id == 11 || template_id == 20 || template_id == 26 || template_id == 29 || template_id == 47 || template_id == 48 || template_id == 54)" width="50px" > 置换率 <br />(ml/min) </th>
                <th v-if="isShow('置换率') && template_id !=6 && template_id !=10 && template_id != 11 && template_id != 20 && template_id != 26 && template_id != 29  && template_id != 47 && template_id != 48 && template_id != 54" width="50px"  > 置换率 <br />(L/h) </th>
                <th v-if="isShow('置换量') && ((template_id ==6 && org_id != 9919) || template_id ==10 ||template_id ==11 ||template_id ==20 ||template_id ==26 ||template_id ==29 ||template_id ==47 ||template_id ==53 ||template_id ==54)" width="50px" > 置换量 <br />(ml) </th>
                <th v-if="isShow('置换量') && ((template_id !=6 || org_id == 9919) && template_id !=10 && template_id !=11 && template_id !=20 && template_id !=26 && template_id !=29  && template_id !=47 && template_id !=53 && template_id !=54)" width="50px" > 置换量 <br />(L) </th>
                <th v-if="isShow('SpO₂')  && template_id !=6 && template_id !=10 && template_id !=11" width="40px" > SpO₂ <br />(%) </th>
                <th v-if="isShow('电导度')" width="50px"> 电导度 <br />(mS/cm) </th>
                <th v-if="isShow('置换液流量')" width="50px"> 置换液流量 <br /><span v-if="template_id !=27">(ml/h)</span><span v-if="template_id ==27 || template_id ==29">(ml/min)</span> </th>
                <th v-if="isShow('透析液流量')" width="50px"> 透析液流量 <br />(ml/h) </th>
                <th v-if="isShow('超滤率') && (template_id ==6 || template_id == 10 || template_id == 11 || template_id == 12 || template_id == 13 || template_id == 17 || template_id == 18 || template_id == 19 || template_id == 20 || template_id == 21 || template_id == 22 || template_id == 23 || template_id == 24 || template_id == 26 || template_id == 31 || template_id == 34 || template_id == 35 || template_id == 47 || template_id == 48 || template_id == 53  || template_id == 54)" width="50px"> 超滤率 <br />(ml/h) </th>
                <th v-if="isShow('超滤率') && template_id !=6 && template_id !=10 && template_id !=11 && template_id !=12 && template_id !=13 && template_id !=17 && template_id !=18 && template_id !=19 && template_id !=20 && template_id !=21 && template_id !=22 && template_id !=23 && template_id !=24 && template_id !=26 && template_id !=31 && template_id !=34 && template_id !=35 && template_id !=47 && template_id !=48 && template_id !=53 && template_id !=54" width="50px"> 超滤率 <br />(L/h) </th>
                <th v-if="isShow('肝素用量余量')" width="60px"> 肝素用量余量 <br />(ml) </th>
                <th v-if="isShow('肝素量')" width="60px"> 肝素量 <br />(mg) </th>
                <th v-if="isShow('抗凝剂')" width="60px">抗凝剂</th>
                <th v-if="isShow('KT/V') && org_id == 9987" width="60px">KT/V</th>
                <th v-if="isShow('病情变化')" width="92px">病情变化</th>
                <th v-if="isShow('处理')" width="92px">处理</th>
                <th v-if="isShow('结果')" width="92px">结果</th>
              </tr>
              <tr v-for="(item,index) in monitorRecords" :key="index" :value="item.value" @click="selectRow(index, item)" :class="index==currentIndex?rowClass:''" >
                <td v-if="isShow('监测时间')">{{parseTime(item.operate_time, '{y}-{m}-{d} {h}:{i}')}}</td>
                <td v-if="isShow('血压')" >{{item.systolic_blood_pressure?item.systolic_blood_pressure:''}}/{{item.diastolic_blood_pressure?item.diastolic_blood_pressure:''}}</td>
                <td v-if="isShow('脉搏')">{{item.pulse_frequency?item.pulse_frequency:''}}</td>
                <td v-if="isShow('体温')">{{item.temperature?item.temperature:''}}</td>
                <td v-if="isShow('呼吸频率')">{{item.breathing_rate?item.breathing_rate:''}}</td>
                <td v-if="isShow('血流量')">{{item.blood_flow_volume?item.blood_flow_volume:''}}</td>
                <td> {{item.venous_pressure?item.venous_pressure:''}}/{{item.arterial_pressure?item.arterial_pressure:''}}</td>
                <td v-if="isShow('跨膜压')" >{{item.transmembrane_pressure?item.transmembrane_pressure:''}}</td>
                <td v-if="isShow('超滤量')" >{{item.ultrafiltration_volume?item.ultrafiltration_volume:''}}</td>
                <td v-if="isShow('钠浓度')">{{item.sodium_concentration?item.sodium_concentration:''}}</td>
                <td v-if="isShow('透析液温度')" >{{item.dialysate_temperature?item.dialysate_temperature:''}}</td>
                <td v-if="isShow('置换率')">{{item.replacement_rate?item.replacement_rate:''}}</td>
                <td v-if="isShow('置换量')" >{{item.displacement_quantity?item.displacement_quantity:''}}</td>
                <td v-if="isShow('SpO₂') && template_id != 6 && template_id != 10  && template_id != 11" >{{item.blood_oxygen_saturation?item.blood_oxygen_saturation:'/'}}</td>
                <td v-if="isShow('电导度')">{{item.conductivity?item.conductivity:''}}</td>
                <td v-if="isShow('置换液流量')" >{{item.displacement_flow_quantity?item.displacement_flow_quantity:''}}</td>
                <td v-if="isShow('透析液流量')" >{{item.dialysate_flow?item.dialysate_flow:''}}</td>
                <td v-if="isShow('超滤率')" >{{item.ultrafiltration_rate?item.ultrafiltration_rate:''}}</td>
                <td v-if="isShow('肝素用量余量')">{{item.heparin?item.heparin:''}}</td>
                <td v-if="isShow('肝素量')">{{item.heparin_amount?item.heparin_amount:''}}</td>
                <td v-if="isShow('抗凝剂')">
                   <span v-if="item.monitor_anticoagulant == 0"></span>
                   <span v-if="item.monitor_anticoagulant == 1">无肝素</span>
                   <span v-if="item.monitor_anticoagulant == 2">普通肝素</span>
                   <span v-if="item.monitor_anticoagulant == 3">低分子肝素</span>
                   <span v-if="item.monitor_anticoagulant == 4">阿加曲班</span>
                   <span v-if="item.monitor_anticoagulant == 5">枸橼酸钠</span>
                   <span v-if="item.monitor_anticoagulant == 6">低分子肝素钙</span>
                   <span v-if="item.monitor_anticoagulant == 7">低分子肝素钠</span>
                   <span v-if="item.monitor_anticoagulant == 8">依诺肝素</span>
                   <span v-if="item.monitor_anticoagulant == 9">达肝素</span>
                   <span v-if="item.monitor_anticoagulant == 12">无抗凝剂</span>
                  <span v-if="item.monitor_anticoagulant_value!=''">({{item.monitor_anticoagulant_value}})</span>
                </td>
                <td v-if="isShow('KT/V') && org_id == 9987">{{item.ktv?item.ktv:''}}</td>
                <td v-if="isShow('病情变化')">{{item.symptom}}</td>
                <td v-if="isShow('处理')">{{item.dispose}}</td>
                <td v-if="isShow('结果')">{{item.result}}</td>
              </tr>
            </table>
          </div>
        </div>
      </div>
      <div class="Dialog" v-show="formPanel">
        <div class="DialogTit">
          <div class="back" @click="formPanel=false;listPanel=true;">
            <span class="iconfont">&#xe720;</span>返回
          </div>
          <h1 class="name">{{formTitle}}</h1>
          <span class="success" v-if="form.id>0" @click="submitEditAction()">保存</span>
          <span class="success" v-else @click="submitAction()">保存</span>
        </div>
        <div class="DialogContent choose">
          <div class="content" style="overflow:hidden;" ref="int">
            <div class="cell" v-if="isShow('监测时间')">
              <label>监测时间</label>
              <input
                type="text"
                class="inputBox"
                @click="chooseTime()"
                v-on:change="timechange()"
                :value="parseTime(this.form.operate_time, '{y}-{m}-{d} {h}:{i}')"
                readonly
              />
            </div>
            <div class="cell" v-if="isShow('收缩压')">
              <label>收缩压(mmHg)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.systolic_bp"
                @keydown='changeFocus'
              />
            </div>
            <div class="cell" v-if="isShow('舒张压')">
              <label>舒张压(mmHg)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.diastolic_bp"
                @keydown='changeFocus'
              />
            </div>
            <div class="cell" v-if="isShow('脉搏')">
              <label>脉搏(次/分)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.pulse_frequency"
                @keydown='changeFocus'
              />
            </div>
            <div class="cell" v-if="isShow('体温')">
              <label>体温(℃)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.temperature"
                @keydown='changeFocus'
              />
            </div>
            <div class="cell" v-if="isShow('呼吸频率')">
              <label>呼吸频率(次/分)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.breathing_rated"
                @keydown='changeFocus'
              />
            </div>
            <div class="cell" v-if="isShow('血流量')">
              <label>血流量(ml/min)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.blood_flow_volume"
                @keydown='changeFocus'
              />
            </div>
             <div class="cell" v-if="isShow('动脉压')">
              <label>动脉压({{form.arterial_pressure_type == 2 ? 'kpa': 'mmHg'}})</label>
              <input
                type="number"
                @focus="inputFocus"

                class="inputBox"
                v-model="form.arterial_pressure"
                style="width:60%"
                @keydown='changeFocus'
              />
              <button
                class="typeButton"
                style="width:30%;padding: 0.18rem 0; color: #fff; background: #409eff;border-radius:5px"
                @click="venousPressureChangeThree"
              >切换</button>
            </div>
            <div class="cell" v-if="isShow('静脉压')">
              <label>静脉压({{form.venous_pressure_type == 2 ? 'kpa': 'mmHg'}})</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.venous_pressure"
                style="width:60%"
                @keydown='changeFocus'
              />
              <button
                class="typeButton"
                style="width:30%;padding: 0.18rem 0; color: #fff; background: #409eff;border-radius:5px"
                @click="venousPressureChangeOne"
              >切换</button>
            </div>
            <div class="cell" v-if="isShow('跨膜压')">
              <label>跨膜压({{form.transmembrane_pressure_type == 2 ? 'kpa': 'mmHg'}})</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.transmembrane_pressure"
                style="width:60%"
                @keydown='changeFocus'
              />
              <button
                class="typeButton"
                style="width:30%;padding: 0.18rem 0; color: #fff; background: #409eff;border-radius:5px"
                @click="venousPressureChangeTwo"
              >切换</button>
            </div>
            <div class="cell" v-if="isShow('超滤量')">
              <label v-if="template_id == 6 || template_id == 10 || template_id == 11 || template_id == 12 || template_id == 13 || template_id == 17 || template_id == 18 || template_id == 19 || template_id == 20 || template_id == 21 || template_id == 22 || template_id == 23 || template_id == 24 || template_id == 26 || org_id == 9555 || template_id == 27 || template_id == 29 || template_id == 30 || template_id == 31 || template_id == 9 || template_id == 32 || template_id == 34 || template_id == 35 || template_id == 47 || template_id == 53 || template_id == 54 || template_id == 60" >超滤量(ml)</label>
              <label v-else>超滤量(L)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.ultrafiltration_volume"
                @keydown='changeFocus'
              />
            </div>
            <div class="cell" v-if="isShow('超滤率')">
              <label v-if="template_id == 6 || template_id == 10 || template_id == 11 || template_id == 13 || template_id == 17 || template_id == 18 || template_id == 19 || template_id == 20 || template_id == 21 || template_id == 22 || template_id == 23 || template_id == 24 || template_id == 26 || template_id == 29 || template_id == 30 || template_id == 31 || template_id == 32 || template_id == 34 || template_id == 35 || template_id == 47  || template_id == 53  || template_id == 54">超滤率(ml/h)</label>
              <label v-else>超滤率(L/h)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.ultrafiltration_rate"
                @keydown='changeFocus'
              />
            </div>
            <div class="cell" v-if="isShow('钠浓度')">
              <label>钠浓度(mmol/L)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.sodium_concentration"
                @keydown='changeFocus'
              />
            </div>

           <div class="cell" v-if="isShow('电导度')">
              <label>电导度(mS/cm)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.conductivity"
                @keydown='changeFocus'
              />
            </div>
            <div class="cell" v-if="isShow('透析液温度')">
              <label>透析液温度(℃)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.dialysate_temperature"
                @keydown='changeFocus'
              />
            </div>

            <div class="cell" v-if="isShow('置换率')">
              <label v-if="template_id == 6 || template_id == 10 || template_id == 11 || template_id == 20 || template_id == 26 || template_id == 29 || template_id == 47 || template_id == 53 || template_id == 54">置换率(ml/min)</label>
              <label v-else>置换率(L/h)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.replacement_rate"
                @keydown='changeFocus'
              />
            </div>
            <div class="cell" v-if="isShow('置换量')">
              <label v-if="(template_id == 6 || template_id == 10 || template_id == 11 || template_id == 20 || template_id == 26 || template_id == 29 || template_id == 47 || template_id == 53 || template_id == 54) && org_id != 9919 ">置换量(ml)</label>
              <label v-else>置换量(L)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.displacement_quantity"
                @keydown='changeFocus'
              />
            </div>
            <div class="cell" v-if="isShow('SpO₂')">
              <label v-if="template_id == 6 || template_id == 10 || template_id == 11 || template_id == 21">SpO₂(%)</label>
              <label v-else>SpO₂(L)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.blood_oxygen_saturation"
                @keydown='changeFocus'
              />
            </div>

           <div class="cell" v-if="isShow('血糖')">
              <label>血糖(mmol/L)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.blood_sugar"
                @keydown='changeFocus'
              />
            </div>

            <div class="cell" v-if="isShow('置换液流量')">
              <label>置换液流量<span v-if="template_id != 27">(ml/h)</span><span v-if="template_id == 27 || template_id == 29">(ml/min)</span></label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.displacement_flow_quantity"
                @keydown='changeFocus'
              />
            </div>

            <div class="cell" v-if="isShow('透析液流量')">
              <label>透析液流量(ml/h)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.dialysate_flow"
                @keydown='changeFocus'
              />
            </div>

            <div class="cell" v-if="isShow('肝素用量余量')">
              <label>肝素用量余量(ml)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.heparin"
                @keydown='changeFocus'
              />
            </div>

            <div class="cell" v-if="isShow('肝素量')">
              <label>肝素量(mg)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.heparin_amount"
                @keydown='changeFocus'
              />
            </div>

           <div @click="showSubMenu('anticoagulant')" class="cell" ref="anticoagulant" v-if="isShow('抗凝剂')">
            <label class="name" for="knj">抗凝剂</label>
              <input
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.monitor_anticoagulant"
                @keydown='changeFocus'
              />
          </div>

            <div class="cell" v-if="isShow('抗凝剂')">
              <label></label>
              <input
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.monitor_anticoagulant_value"
                @keydown='changeFocus'
              />
            </div>

           <div class="cell" v-if="isShow('脱水')">
              <label>脱水(L)</label>
              <input
                type="number"
                @focus="inputFocus"
                onclick="this.select();"
                class="inputBox"
                v-model="form.dehydration"
                @keydown='changeFocus'
              />
            </div>

            <div class="cell width" v-if="isShow('KT/V')">
              <label>KT/V(在线)</label>
              <!-- <input type="text" class="inputBox" v-model="form.ktv"> -->
              <textarea
                @focus="inputFocus"
                class="inputBox"
                style="width: 100%;"
                :rows="4"
                v-model="form.ktv"
              ></textarea>
            </div>

            <div class="cell width" v-if="isShow('URR')">
              <label>URR</label>
              <!-- <input type="text" class="inputBox" v-model="form.ktv"> -->
              <textarea
                @focus="inputFocus"
                class="inputBox"
                style="width: 100%;"
                :rows="4"
                v-model="form.urr"
              ></textarea>
            </div>
            <div class="cell width" v-if="isShow('病情变化')">
              <label>病情变化</label>
              <input
                type="text"
                class="inputBox"
                style="width: 100%;margin-bottom:5px;"
                v-model="form.symptom"
                readonly
                placeholder="选择 "
                @click="showSubMenu('symptom')"
              />
              <textarea
                @focus="inputFocus"
                class="inputBox"
                style="width: 100%;"
                :rows="4"
                v-model="form.symptom"
              ></textarea>
            </div>
            <div class="cell width" v-if="isShow('处理')">
              <label>处理</label>
              <!-- <input type="text" class="inputBox" v-model="form.dispose"> -->
              <input
                type="text"
                class="inputBox"
                style="width: 100%;margin-bottom:5px;"
                v-model="form.dispose"
                readonly
                placeholder="选择"
                @click="showSubMenu('dispose')"
              />
              <textarea
                @focus="inputFocus"
                class="inputBox"
                style="width: 100%;"
                :rows="4"
                v-model="form.dispose"
              ></textarea>
            </div>
            <div class="cell width" v-if="isShow('结果')">
              <label>结果</label>
              <!-- <input type="text" class="inputBox" v-model="form.result"> -->
              <input
                type="text"
                class="inputBox"
                style="width: 100%;margin-bottom:5px;"
                v-model="form.result"
                readonly
                placeholder="选择"
                @click="showSubMenu('result')"
              />
              <textarea
                @focus="lastInputFocus"
                @blur="lastInputBlur"
                class="inputBox"
                style="width: 100%;"
                :rows="4"
                v-model="form.result"
              ></textarea>
            </div>

            <div class="cell width">
              <label>监测人：</label>
              <span class="doctor">{{ form.creator ? getDoctorName(form.creator) : doctor}}</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <mt-datetime-picker ref="picker" type="datetime" @confirm="handleConfirm" v-model="pickertime"></mt-datetime-picker>

    <check-box-sub-menu
      :visibility="visibility"
      v-on:menu-cancle="menuCancle"
      v-on:menu-comfirm="menuComfirm"
      :propsForm="propForm"
    ></check-box-sub-menu>
  </div>
</template>
<script>
import { addMonitorRecord, deleteMonitorRecord, editMonitorRecord, GetMonitor, GetMonitorToday } from '@/api/dialysis'
import { parseTime } from '@/utils'
import { Dialog, Toast } from 'vant'
import CheckBoxSubMenu from './subMenu/checkBoxSubMenu'
import { getDataConfig } from '@/utils/data'

import request from '@/utils/request'

export default {
  name: 'MonitDialog',

  props: {
    monitor_records: {
      type: Array
    },
    patient: {
      type: Object
    },
    order: {
      type: Object
    },
    last_monitor_record: {
      type: Object
    },
    dialysis_order: {
      type: Object
    }
  },
  data () {
    return {
      is_has_create: true,
      is_has_modify: true,
      is_has_modify_other: true,
      is_has_del: true,
      is_has_del_other: true,
      creator: 0,
      loading: false,
      formTitle: '新增监测',
      formPanel: false,
      listPanel: true,
      tableDate: [],
      monitorRecords: this.monitor_records,
      pickertime: new Date(),
      monitor_time_str: '',
      // monitor_date_str: "",
      currentIndex: -1,
      currentRow: null,
      rowClass: 'row-class-active',
      template_id: 0,
      visibility: false,
      today_last_monitor_record: {},
      propForm: {
        title: '',
        list: [],
        optionList: [],
        isMultiple: 2,
        result: [], // 选中的值
        type: 1, // 用来区分不同子菜单，方便对返回值进行赋值
        selectId: 0
      },

      form: {
        // patient_id: 0,
        // order_id: 0,
        monitor_date: 0,
        // monitor_time: "00:00",
        operate_time: 0,
        pulse_frequency: '', // 脉率
        breathing_rated: '', // 呼吸频率
        systolic_bp: '', // 收缩压
        diastolic_bp: '', // 舒张压
        blood_flow_volume: '', // 血流量
        venous_pressure: '', // 静脉压
        venous_pressure_type: 1, // 静脉压类型
        arterial_pressure: '', // 动脉压
        arterial_pressure_type: 1, // 动脉压类型
        transmembrane_pressure: '', // 跨膜压
        transmembrane_pressure_type: 1, // 跨膜压类型
        ultrafiltration_rate: '', // 超滤率
        ultrafiltration_volume: '', // 超滤量
        sodium_concentration: '', // 钠浓度
        dialysate_temperature: '', // 透析液温度
        temperature: '', // 体温
        replacement_rate: '', // 置换率
        displacement_quantity: '', // 置换量
        conductivity: '',
        displacement_flow_quantity: '',
        ktv: '', // KT/V(在线)
        symptom: '', // 症状
        dispose: '', // 处理
        result: '', // 结果,
        blood_oxygen_saturation: '',
        monitoring_nurse: this.$store.getters.user.admin.id, // 监测人
        creator: 0,
        heparin: '',
        dialysate_flow: '',
        urr: '',
        blood_sugar: '',
        monitor_anticoagulant: '',
        monitor_anticoagulant_value: '',
        heparin_amount: '', // 肝素量
        dehydration: ''
      },
      doctor: this.$store.getters.user.user.user_name,
      value: 0,
      valueOne: 0,
      valueTwo: 0,
      anticoagulantsConfit: {}
    }
  },
  created () {
    this.getPermission()
    var date = this.$route.query && this.$route.query.date
    this.template_id = this.$store.getters.user.template_info.template_id
    this.org_id = this.$store.getters.user.template_info.org_id


    this.form.monitor_date = date
    this.form.operate_time = this.pickertime.getTime()
    console.log('监测时间', this.form.operate_time)

    this.anticoagulantsConfit = this.$store.getters.anticoagulants_confit
    console.log('抗凝剂', this.anticoagulantsConfit)
  },
  methods: {
    timechange () {
      debugger
    },
    venousPressureChange (type) {
      if (type == 1) {
        this.form.venous_pressure_ = Math.ceil(Math.round(this.form.venous_pressure * 7.5))
      } else if (type == 2) {
        this.form.transmembrane_pressure = Math.ceil(Math.round(this.form.transmembrane_pressure * 7.5))
      } else {
        this.form.arterial_pressure = Math.ceil(Math.round(this.form.arterial_pressure * 7.5))
      }
    },
    venousPressureChangeOne () {
      if (this.form.venous_pressure_type == 1) {
        this.form.venous_pressure_type = 2
      } else {
        this.form.venous_pressure_type = 1
      }
    },
    venousPressureChangeTwo () {
      if (this.form.transmembrane_pressure_type == 1) {
        this.form.transmembrane_pressure_type = 2
      } else {
        this.form.transmembrane_pressure_type = 1
      }

    },
    venousPressureChangeThree () {
      if (this.form.arterial_pressure_type == 1) {
        this.form.arterial_pressure_type = 2
      } else {
        this.form.arterial_pressure_type = 1
      }
    },
    isShow (name) {
      var filedList = this.$store.getters.user.fileds

      for (let i = 0; i < filedList.length; i++) {
        if (filedList[i].module == 4 && filedList[i].filed_name_cn == name && filedList[i].is_show == 1) {
          return true
        }
      }
      return false
    },
    getLastRecordTody () {
      let params = {
        patient_id: this.patient.id
      }

      GetMonitorToday(params).then(rs => {
        var resp = rs.data.data

        this.today_last_monitor_record = resp.monitor

        // this.form.operate_time = Date.parse(new Date())
        this.form.operate_time = resp.monitor.operate_time ? (resp.monitor.operate_time + 3600) * 1000 : Date.parse(new Date())
        this.form.pulse_frequency = '' // this.last_monitor_record.pulse_frequency;
        this.form.systolic_bp = '' // this.last_monitor_record.systolic_blood_pressure;
        this.form.diastolic_bp = '' // this.last_monitor_record.diastolic_blood_pressure;
        this.form.blood_flow_volume = resp.monitor.blood_flow_volume ? resp.monitor.blood_flow_volume : ''
        if (this.template_id == 34) {
          this.form.venous_pressure = resp.monitor.venous_pressure ? resp.monitor.venous_pressure : ''
        } else {
          this.form.venous_pressure = '' // this.last_monitor_record.venous_pressure;
        }

        this.form.venous_pressure_type = resp.monitor.venous_pressure_type ? resp.monitor.venous_pressure_type : 1 // this.last_monitor_record.venous_pressure;
        if (this.template_id == 17) {
          this.form.arterial_pressure = '-'
        } else {
          // this.form.arterial_pressure = '' // this.last_monitor_record.arterial_pressure;
          this.form.arterial_pressure = resp.monitor.arterial_pressure ? resp.monitor.arterial_pressure : '' // this.last_monitor_record.arterial_pressure;
        }
        this.form.arterial_pressure_type = resp.monitor.arterial_pressure_type ? resp.monitor.arterial_pressure_type : 1
        if (this.template_id == 34) {
          this.form.transmembrane_pressure = resp.monitor.transmembrane_pressure ? resp.monitor.transmembrane_pressure : ''
        } else {
          this.form.transmembrane_pressure = ''
        }
        // this.last_monitor_record.transmembrane_pressure;
        this.form.transmembrane_pressure_type = resp.monitor.transmembrane_pressure_type ? resp.monitor.transmembrane_pressure_type : 1
        this.form.id = -1

        this.form.ultrafiltration_rate = resp.monitor.ultrafiltration_rate ? resp.monitor.ultrafiltration_rate : ''
        this.form.ultrafiltration_volume = resp.monitor.ultrafiltration_volume ? resp.monitor.ultrafiltration_volume : ''
        this.form.sodium_concentration = resp.monitor.sodium_concentration ? resp.monitor.sodium_concentration : ''
        this.form.dialysate_temperature = resp.monitor.dialysate_temperature ? resp.monitor.dialysate_temperature : ''
        this.form.replacement_rate = resp.monitor.replacement_rate ? resp.monitor.replacement_rate : ''
        this.form.heparin = resp.monitor.heparin ? resp.monitor.heparin : ''
        this.form.dialysate_flow = resp.monitor.dialysate_flow ? resp.monitor.dialysate_flow : ''
        this.form.displacement_quantity = resp.monitor.displacement_quantity ? resp.monitor.displacement_quantity : '' // this.last_monitor_record.displacement_quantity;
        this.form.conductivity = ''
        this.form.displacement_flow_quantity = resp.monitor.displacement_flow_quantity ? resp.monitor.displacement_flow_quantity : ''
        this.form.ktv = resp.monitor.ktv ? resp.monitor.ktv : '' // this.last_monitor_record.ktv;
        this.form.symptom = '' // this.last_monitor_record.symptom;
        this.form.dispose = '' // this.last_monitor_record.dispose;
        this.form.result = '' // this.last_monitor_record.result;
        this.form.blood_oxygen_saturation = resp.monitor.blood_oxygen_saturation ? resp.monitor.blood_oxygen_saturation : ''

        this.form.breathing_rated = resp.monitor.breathing_rate ? resp.monitor.breathing_rate : ''
        this.form.temperature = resp.monitor.temperature ? resp.monitor.temperature : ''
        this.form.urr = resp.monitor.urr ? resp.monitor.urr : ''
        this.form.conductivity = resp.monitor.conductivity ? resp.monitor.conductivity : ''
      })
    },

    getLastRecord () {
      let params = {
        patient_id: this.patient.id
      }
      GetMonitor(params).then(rs => {
        var resp = rs.data
        if (resp.state == 1) {
          var monitor = resp.data.monitor
          if (monitor.systolic_blood_pressure == 0) {
            this.form.systolic_bp = ''
          } else {
            this.form.systolic_bp = monitor.systolic_blood_pressure
          }

          if (monitor.diastolic_blood_pressure == 0) {
            this.form.diastolic_bp = ''
          } else {
            this.form.diastolic_bp = monitor.diastolic_blood_pressure
          }

          if (monitor.pulse_frequency == 0) {
            this.form.pulse_frequency = ''
          } else {
            this.form.pulse_frequency = monitor.pulse_frequency
          }

          if (monitor.breathing_rate == 0) {
            this.form.breathing_rated = ''
          } else {
            this.form.breathing_rated = monitor.breathing_rate
          }

          if (monitor.blood_flow_volume == 0) {
            this.form.blood_flow_volume = ''
          } else {
            this.form.blood_flow_volume = monitor.blood_flow_volume
          }

          if (monitor.venous_pressure == 0) {
            this.form.venous_pressure = ''
          } else {
            this.form.venous_pressure = monitor.venous_pressure
          }

          this.form.venous_pressure_type = monitor.venous_pressure_type ? monitor.venous_pressure_type : 1

          if (monitor.arterial_pressure == 0) {
            this.form.arterial_pressure = ''
          } else {
            this.form.arterial_pressure = monitor.arterial_pressure
          }

          this.form.arterial_pressure_type = monitor.arterial_pressure_type ? monitor.arterial_pressure_type : 1

          if (monitor.transmembrane_pressure == 0) {
            this.form.transmembrane_pressure = ''
          } else {
            this.form.transmembrane_pressure = monitor.transmembrane_pressure
          }
          this.form.transmembrane_pressure_type = monitor.transmembrane_pressure_type ? monitor.transmembrane_pressure_type : 1

          if (monitor.ultrafiltration_rate == 0) {
            this.form.ultrafiltration_rate = ''
          } else {
            this.form.ultrafiltration_rate = monitor.ultrafiltration_rate
          }

          if (monitor.ultrafiltration_volume == 0) {
            this.form.ultrafiltration_volume = ''
          } else {
            this.form.ultrafiltration_volume = monitor.ultrafiltration_volume
          }

          if (monitor.sodium_concentration == 0) {
            this.form.sodium_concentration = ''
          } else {
            this.form.sodium_concentration = monitor.sodium_concentration
          }

          if (monitor.dialysate_temperature == 0) {
            this.form.dialysate_temperature = ''
          } else {
            this.form.dialysate_temperature = monitor.dialysate_temperature
          }

          if (monitor.temperature == 0) {
            this.form.temperature = ''
          } else {
            this.form.temperature = monitor.temperature
          }

          if (monitor.replacement_rate == 0) {
            this.form.replacement_rate = ''
          } else {
            this.form.replacement_rate = monitor.replacement_rate
          }

          if (monitor.displacement_quantity == 0) {
            this.form.displacement_quantity = ''
          } else {
            this.form.displacement_quantity = monitor.displacement_quantity
          }

          if (monitor.conductivity == 0) {
            this.form.conductivity = ''
          } else {
            this.form.conductivity = monitor.conductivity
          }

          if (monitor.displacement_flow_quantity == 0) {
            this.form.displacement_flow_quantity = ''
          } else {
            this.form.displacement_flow_quantity =
              monitor.displacement_flow_quantity
          }

          if (monitor.heparin == 0) {
            this.form.heparin = ''
          } else {
            this.form.heparin = monitor.heparin
          }

          if (monitor.dialysate_flow == 0) {
            this.form.dialysate_flow = ''
          } else {
            this.form.dialysate_flow = monitor.dialysate_flow
          }

          this.form.ktv = monitor.ktv
          this.fomr.urr = monitor.urr
          this.form.symptom = monitor.symptom
          this.form.dispose = monitor.dispose
          this.form.result = monitor.result
          this.form.monitor_anticoagulant_value = monitor.monitor_anticoagulant_value
          this.form.monitor_anticoagulant = monitor.monitor_anticoagulant
          this.form.operate_time = new Date(
            monitor.operate_time * 1000
          ).getTime()
          this.form.id = -1
        }
      })
    },
    selectRow (index, row) {
      if (row != null) {
        this.creator = row.creator
      }
      this.currentIndex = index
      this.currentRow = row
    },

    inputFocus: function (event) {
      var input = event.target
      setTimeout(function () {
        input.parentNode.scrollIntoView()
      }, 0)

    },
    lastInputFocus: function (event) {
      var input = event.target
      setTimeout(function () {
        input.style.marginBottom = '2rem'
        input.parentNode.scrollIntoView()
      }, 0)
    },
    lastInputBlur: function (event) {
      var input = event.target
      setTimeout(function () {
        input.style.marginBottom = ''
      }, 0)
    },
    close: function () {
      this.$emit('close')
    },
    setRecords (records) {
      this.monitorRecords = records
    },
    parseTime (time, layout) {
      return parseTime(time, layout)
    },
    addRecords (records) {
      this.tableDate.push(...records)
    },
    deleteForm () {
      if (this.currentIndex < 0 || this.currentRow == null) {
        Toast.fail('请先选择要删除的记录')
        return false
      }

      Dialog.confirm({
        title: '删除监测记录',
        message: '是否删除该监测记录'
      })
        .then(() => {
          let params = {
            record_id: this.currentRow.id,
            patient_id: this.patient.id,
            mode: '4'
          }

          if (
            this.$store.getters.user.admin.id != this.creator &&
            this.creator != 0
          ) {
            params.mode = '5'
          }
          deleteMonitorRecord(params).then(rs => {
            var resp = rs.data
            if (resp.state == 1) {
              var recordId = resp.data.record_id
              this.$emit('did_delete_monitor', recordId)
              Toast.success('删除成功')
            } else {
              Toast.fail(resp.msg)
            }
          })
        })
        .catch(() => {})
    },
    handleConfirm (time) {
      this.form.operate_time = time.getTime()

    },
    handleTime (time) {
      var year = time.getFullYear()
      var month = time.getMonth() + 1
      var day = time.getDate()
      var hour = time.getHours()
      var minute = time.getMinutes()
      if (month < 10) {
        month = '0' + month
      }
      if (day < 10) {
        day = '0' + day
      }
      if (hour < 10) {
        hour = '0' + hour
      }
      if (minute < 10) {
        minute = '0' + minute
      }
      return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':00'
    },
    chooseTime () {
      this.$refs.picker.open()
    },
    openEidtForm () {
      if (this.currentIndex < 0 || this.currentRow == null) {
        Toast.fail('请先选择要修改的记录')
        return false
      }
      this.formTitle = '修改监测'
      this.formPanel = true
      this.listPanel = false
      // console.log("this.currentRow", this.currentRow);
      var input = this.$refs.int
      setTimeout(function () {
        input.scrollIntoView()
      }, 0)

      if (this.currentRow.systolic_blood_pressure == 0) {
        this.form.systolic_bp = ''
      } else {
        this.form.systolic_bp = this.currentRow.systolic_blood_pressure
      }

      if (this.currentRow.diastolic_blood_pressure == 0) {
        this.form.diastolic_bp = ''
      } else {
        this.form.diastolic_bp = this.currentRow.diastolic_blood_pressure
      }

      if (this.currentRow.pulse_frequency == 0) {
        this.form.pulse_frequency = ''
      } else {
        this.form.pulse_frequency = this.currentRow.pulse_frequency
      }

      if (this.currentRow.breathing_rate == 0) {
        this.form.breathing_rated = ''
      } else {
        this.form.breathing_rated = this.currentRow.breathing_rate
      }

      if (this.currentRow.blood_flow_volume == 0) {
        this.form.blood_flow_volume = ''
      } else {
        this.form.blood_flow_volume = this.currentRow.blood_flow_volume
      }

      if (this.currentRow.venous_pressure == 0) {
        this.form.venous_pressure = ''
      } else {
        this.form.venous_pressure = this.currentRow.venous_pressure
      }

      this.form.venous_pressure_type = this.currentRow.venous_pressure_type ? this.currentRow.venous_pressure_type : 1

      if (this.currentRow.arterial_pressure == 0) {
        this.form.arterial_pressure = ''
      } else {
        this.form.arterial_pressure = this.currentRow.arterial_pressure
      }

      this.form.arterial_pressure_type = this.currentRow.arterial_pressure_type ? this.currentRow.arterial_pressure_type : 1

      if (this.currentRow.transmembrane_pressure == 0) {
        this.form.transmembrane_pressure = ''
      } else {
        this.form.transmembrane_pressure = this.currentRow.transmembrane_pressure
      }

      this.form.transmembrane_pressure_type = this.currentRow.transmembrane_pressure_type ? this.currentRow.transmembrane_pressure_type : 1

      if (this.currentRow.ultrafiltration_rate == 0) {
        this.form.ultrafiltration_rate = ''
      } else {
        this.form.ultrafiltration_rate = this.currentRow.ultrafiltration_rate
      }

      if (this.currentRow.ultrafiltration_volume == 0) {
        this.form.ultrafiltration_volume = ''
      } else {
        this.form.ultrafiltration_volume = this.currentRow.ultrafiltration_volume
      }

      if (this.currentRow.sodium_concentration == 0) {
        this.form.sodium_concentration = ''
      } else {
        this.form.sodium_concentration = this.currentRow.sodium_concentration
      }

      if (this.currentRow.dialysate_temperature == 0) {
        this.form.dialysate_temperature = ''
      } else {
        this.form.dialysate_temperature = this.currentRow.dialysate_temperature
      }

      if (this.currentRow.temperature == 0) {
        this.form.temperature = ''
      } else {
        this.form.temperature = this.currentRow.temperature
      }

      if (this.currentRow.replacement_rate == 0) {
        this.form.replacement_rate = ''
      } else {
        this.form.replacement_rate = this.currentRow.replacement_rate
      }

      if (this.currentRow.displacement_quantity == 0) {
        this.form.displacement_quantity = ''
      } else {
        this.form.displacement_quantity = this.currentRow.displacement_quantity
      }

      if (this.currentRow.conductivity == 0) {
        this.form.conductivity = ''
      } else {
        this.form.conductivity = this.currentRow.conductivity
      }

      if (this.currentRow.displacement_flow_quantity == 0) {
        this.form.displacement_flow_quantity = ''
      } else {
        this.form.displacement_flow_quantity = this.currentRow.displacement_flow_quantity
      }

      if (this.currentRow.heparin == 0) {
        this.form.heparin = ''
      } else {
        this.form.heparin = this.currentRow.heparin
      }

      if (this.currentRow.dialysate_flow == 0) {
        this.form.dialysate_flow = ''
      } else {
        this.form.dialysate_flow = this.currentRow.dialysate_flow
      }

      if (this.currentRow.ktv == 0) {
        this.form.ktv = ''
      } else {
        this.form.ktv = this.currentRow.ktv
      }
      if (this.currentRow.urr == '') {
        this.form.urr = ''
      } else {
        this.form.urr = this.currentRow.urr
      }

      if (this.currentRow.blood_sugar == '') {
        this.form.blood_sugar = ''
      } else {
        this.form.blood_sugar = this.currentRow.blood_sugar
      }

      this.form.blood_oxygen_saturation = this.currentRow.blood_oxygen_saturation
      this.form.symptom = this.currentRow.symptom
      this.form.dispose = this.currentRow.dispose
      this.form.result = this.currentRow.result
      this.form.id = this.currentRow.id
      this.form.operate_time = this.currentRow.operate_time * 1000
      this.form.creator = this.currentRow.creator

      this.form.monitor_anticoagulant = this.GetAnticoagulantById(this.currentRow.monitor_anticoagulant)
      this.form.monitor_anticoagulant_value = this.currentRow.monitor_anticoagulant_value

    },
    openForm () {
      if (this.is_has_create == false) {
        Toast.fail('你没有新增监测的权限')
        return false
      }
      this.formTitle = '新增监测'
      this.formPanel = true
      this.listPanel = false
      // if(this.monitor_time_str == "") {

      var input = this.$refs.int
      setTimeout(function () {
        input.scrollIntoView()
      }, 0)

      var date = this.$route.query && this.$route.query.date
      date *= 1000
      var newDate = new Date(date)

      var y = newDate.getFullYear()
      var m = newDate.getMonth() + 1
      var d = newDate.getDate()
      var record_date = y + '/' + (m < 10 ? '0' + m : m) + '/' + (d < 10 ? '0' + d : d)
      this.form.monitor_date = new Date(record_date + ' 00:00:00').getTime() / 1000
      var nowTime = new Date()

      this.getLastRecordTody()

      // }
    },
    submitEditAction: function () {
      this.loading = true
      Toast.loading({ forbidClick: true, duration: 0 })
      var params = {}
      var monitor_id = ''
      for (let keys in this.anticoagulantsConfit) {
        if (this.anticoagulantsConfit[keys].name == this.form.monitor_anticoagulant) {
          monitor_id = this.anticoagulantsConfit[keys].id
        }
      }
      console.log('monitor_id', monitor_id)

      params.patient_id = this.patient.id
      params.order_id = this.order == null ? 0 : this.order.id
      params.date = this.form.monitor_date
      // params.time = this.form.monitor_time;
      params.operate_time = parseInt(this.form.operate_time / 1000)
      params.pulse_frequency = this.form.pulse_frequency
      params.breathing_rated = this.form.breathing_rated
      params.systolic_bp = this.form.systolic_bp
      params.diastolic_bp = this.form.diastolic_bp
      params.blood_flow_volume = this.form.blood_flow_volume
      params.venous_pressure = this.form.venous_pressure
      params.venous_pressure_type = this.form.venous_pressure_type
      params.arterial_pressure = this.form.arterial_pressure
      params.arterial_pressure_type = this.form.arterial_pressure_type
      params.transmembrane_pressure = this.form.transmembrane_pressure
      params.transmembrane_pressure_type = this.form.transmembrane_pressure_type
      params.ultrafiltration_rate = this.form.ultrafiltration_rate
      params.ultrafiltration_volume = this.form.ultrafiltration_volume
      params.sodium_concentration = this.form.sodium_concentration
      params.dialysate_temperature = this.form.dialysate_temperature
      params.temperature = this.form.temperature
      params.replacement_rate = this.form.replacement_rate
      params.displacement_quantity = this.form.displacement_quantity
      params.ktv = this.form.ktv
      params.conductivity = this.form.conductivity
      params.symptom = this.form.symptom
      params.heparin = this.form.heparin
      params.dialysate_flow = this.form.dialysate_flow

      params.dispose = this.form.dispose
      params.result = this.form.result
      params.monitoring_nurse = this.form.monitoring_nurse
      params.displacement_flow_quantity = this.form.displacement_flow_quantity
      params.blood_oxygen_saturation = this.form.blood_oxygen_saturation
      params.id = this.form.id
      params.mode = '2'
      params.urr = this.form.urr
      params.blood_sugar = this.form.blood_sugar
      params.monitor_anticoagulant = monitor_id
      params.monitor_anticoagulant_value = this.form.monitor_anticoagulant_value
      params.heparin_amount = this.form.heparin_amount
      if (
        this.form.creator != this.$store.getters.user.admin.id &&
        this.form.creator != 0
      ) {
        params.mode = '3'
      }
      editMonitorRecord(params)
        .then(rs => {
          var resp = rs.data
          if (resp.state == 1) {
            this.loading = false

            var monitor = resp.data.monitor

            this.$emit('did_edit_monitor', monitor)
            //
            Toast.success('修改成功')
            this.selectRow(-1, null)
            this.form.pulse_frequency = ''
            this.form.breathing_rated = ''
            this.form.systolic_bp = ''
            this.form.diastolic_bp = ''
            this.form.blood_flow_volume = ''
            this.form.venous_pressure = ''
            this.form.arterial_pressure = ''
            this.form.transmembrane_pressure = ''
            this.form.ultrafiltration_rate = ''
            this.form.ultrafiltration_volume = ''
            this.form.sodium_concentration = ''
            this.form.dialysate_temperature = ''
            this.form.temperature = ''
            this.form.replacement_rate = ''
            this.form.displacement_quantity = ''
            this.form.ktv = ''
            this.form.blood_oxygen_saturation = ''
            this.form.symptom = ''
            this.form.dispose = ''
            this.form.result = ''
            this.form.conductivity = ''
            this.form.displacement_flow_quantity = ''
            this.form.heparin = ''
            this.form.dialysate_flow = ''
            this.form.urr = ''
            this.form.blood_sugar = ''

            this.form.creator = 0
            this.form.id = -1
            this.formPanel = false
            this.listPanel = true
            this.form.monitor_anticoagulant_value = ''
            this.form.monitor_anticoagulant = ''
            this.form.heparin_amount = ''
           
          } else {
            this.loading = false
            Toast.fail(resp.msg)
          }
        })
        .catch(error => {
          Toast.fail(error.toString())
        })
    },
    submitAction: function () {
      this.loading = true
      Toast.loading({ forbidClick: true, duration: 0 })
      var params = {}
      var monitor_id = ''
      for (let keys in this.anticoagulantsConfit) {
        if (this.anticoagulantsConfit[keys].name == this.form.monitor_anticoagulant) {
          monitor_id = this.anticoagulantsConfit[keys].id
        }
      }
      console.log('monitor_id', monitor_id)

      params.patient_id = this.patient.id
      params.order_id = this.order == null ? 0 : this.order.id
      params.date = this.form.monitor_date
      params.operate_time = parseInt(this.form.operate_time / 1000)
      params.pulse_frequency = this.form.pulse_frequency
      params.breathing_rated = this.form.breathing_rated
      params.systolic_bp = this.form.systolic_bp
      params.diastolic_bp = this.form.diastolic_bp
      params.blood_flow_volume = this.form.blood_flow_volume
      params.venous_pressure = this.form.venous_pressure
      params.venous_pressure_type = this.form.venous_pressure_type
      params.arterial_pressure = this.form.arterial_pressure
      params.arterial_pressure_type = this.form.arterial_pressure_type
      params.transmembrane_pressure = this.form.transmembrane_pressure
      params.transmembrane_pressure_type = this.form.transmembrane_pressure_type
      params.ultrafiltration_rate = this.form.ultrafiltration_rate
      params.ultrafiltration_volume = this.form.ultrafiltration_volume
      params.sodium_concentration = this.form.sodium_concentration
      params.dialysate_temperature = this.form.dialysate_temperature
      params.temperature = this.form.temperature
      params.replacement_rate = this.form.replacement_rate
      params.displacement_quantity = this.form.displacement_quantity
      params.conductivity = this.form.conductivity
      params.displacement_flow_quantity = this.form.displacement_flow_quantity
      params.blood_oxygen_saturation = this.form.blood_oxygen_saturation
      params.heparin = this.form.heparin
      params.dialysate_flow = this.form.dialysate_flow

      params.ktv = this.form.ktv
      params.urr = this.form.urr
      params.blood_sugar = this.form.blood_sugar
      params.symptom = this.form.symptom
      params.dispose = this.form.dispose
      params.result = this.form.result
      params.monitoring_nurse = this.form.monitoring_nurse
      params.mode = '1'
      params.monitor_anticoagulant = monitor_id
      params.monitor_anticoagulant_value = this.form.monitor_anticoagulant_value
      params.heparin_amount = this.from.heparin_amount
      addMonitorRecord(params)
        .then(rs => {
          var resp = rs.data
          if (resp.state == 1) {
            this.loading = false

            var monitor = resp.data.monitor
            this.$emit('did_add_monitor', monitor)

            this.form.pulse_frequency = ''
            this.form.breathing_rated = ''
            this.form.systolic_bp = ''
            this.form.diastolic_bp = ''
            this.form.blood_flow_volume = ''
            this.form.venous_pressure = ''
            this.form.arterial_pressure = ''
            this.form.transmembrane_pressure = ''
            this.form.ultrafiltration_rate = ''
            this.form.ultrafiltration_volume = ''
            this.form.sodium_concentration = ''
            this.form.dialysate_temperature = ''
            this.form.temperature = ''
            this.form.replacement_rate = ''
            this.form.displacement_quantity = ''
            this.form.ktv = ''
            this.form.symptom = ''
            this.form.dispose = ''
            this.form.result = ''
            this.form.conductivity = ''
            this.form.displacement_flow_quantity = ''
            this.form.heparin = ''
            this.form.dialysate_flow = ''
            this.form.urr = ''
            this.form.blood_sugar = ''
            this.form.monitor_anticoagulant = ''
            this.form.monitor_anticoagulant_value = ''
            this.form.heparin_amount = ''
            // this.last_monitor_record.sodium_concentration =
            //   monitor.sodium_concentration
            // this.last_monitor_record.dialysate_temperature =
            //   monitor.dialysate_temperature

            Toast.success('新增成功')
            this.formPanel = false
            this.listPanel = true
          } else {
            this.loading = false
            Toast.fail(resp.msg)
          }
        })
        .catch(err => {
          this.loading = false
          Toast.fail(err)
        })
    },
    showSubMenu: function (val) {
      switch (val) {
        case 'symptom':
          this.propForm.type = 1
          this.formPanel = false
          this.propForm.title = '病情变化'
          this.visibility = true
          this.propForm.list = getDataConfig('hemodialysis', 'symptoms')
          this.propForm.optionList = []
          this.propForm.isMultiple = 2
          if (this.form.symptom.length > 0) {
            this.propForm.result = this.form.symptom.split(',')
          } else {
            this.propForm.result = []
          }
          break

        case 'dispose':
          this.propForm.type = 2
          this.formPanel = false
          this.propForm.title = '处理'
          this.visibility = true
          this.propForm.list = getDataConfig('hemodialysis', 'deals')
          this.propForm.optionList = []
          this.propForm.isMultiple = 2
          if (this.form.dispose.length > 0) {
            this.propForm.result = this.form.dispose.split(',')
          } else {
            this.propForm.result = []
          }
          break

        case 'result':
          this.propForm.type = 3
          this.formPanel = false
          this.propForm.title = '结果'
          this.visibility = true
          this.propForm.list = getDataConfig('hemodialysis', 'results')
          this.propForm.optionList = []
          this.propForm.isMultiple = 2
          if (this.form.result.length > 0) {
            this.propForm.result = this.form.result.split(',')
          } else {
            this.propForm.result = []
          }
          break

        case 'anticoagulant':

          this.propForm.type = 4
          this.isShowDialog = false
          this.propForm.title = '抗疑剂'
          this.formPanel = false
          this.visibility = true

          this.propForm.list = []
          this.propForm.optionList = this.anticoagulantsConfit
          this.propForm.isMultiple = 1
          this.propForm.selectId = this.form.monitor_anticoagulant
          this.propForm.click_ref = 'anticoagulant'
          break
      }
    },
    menuCancle: function () {
      this.visibility = false
      this.formPanel = true
    },
    menuComfirm: function (val) {
      this.visibility = false
      this.formPanel = true
      switch (val.type) {
        case 1:
          this.form.symptom = val.result.join(',')
          break
        case 2:
          this.form.dispose = val.result.join(',')
          break
        case 3:
          this.form.result = val.result.join(',')
          break
        case 4:
          this.form.monitor_anticoagulant = this.GetAnticoagulantById(val.selectId)
      }
    },
    open: function () {
      this.listPanel = true
      this.formPanel = false
      this.visibility = false
      this.$refs.picker.close()
      var dialogTop = document.querySelector('#dialogTop')
      if (dialogTop != null) {
        this.$nextTick(() => {
          dialogTop.scrollTop = 0
        })
      }
    },
    parseTime: function (time, format) {
      return parseTime(time, format)
    },
    quickSort (arr, name, snum) {
      // 如果数组<=1,则直接返回
      if (arr.length <= 1) {
        return arr
      }
      var pivotIndex = Math.floor(arr.length / 2)
      // 找基准，并把基准从原数组删除
      var pivot = arr.splice(pivotIndex, 1)[0]
      var middleNum = pivot[name]
      // 定义左右数组
      var left = []
      var right = []
      // 比基准小的放在left，比基准大的放在right
      if (snum) {
        for (var i = 0; i < arr.length; i++) {
          if (arr[i][name] <= middleNum) {
            left.push(arr[i])
          } else {
            right.push(arr[i])
          }
        }
      } else {
        for (var i = 0; i < arr.length; i++) {
          if (arr[i][name] <= middleNum) {
            left.push(arr[i])
          } else {
            right.push(arr[i])
          }
        }
      }
      // 递归,返回所需数组
      return this.quickSort(left, name, snum).concat(
        [pivot],
        this.quickSort(right, name, snum)
      )
    },
    getPermission () {
      request
        .get('/m/api/permission/get', {
          params: {
            create_url: '/m/api/monitor/add?mode=1',
            modify_url: '/m/api/monitor/edit?mode=2',
            modify_other_url: '/m/api/monitor/edit?mode=3',
            del_url: '/m/api/monitor/delete?mode=4',
            del_other_url: '/m/api/monitor/delete?mode=5',
            module: 7
          }
        })
        .then(res => {
          console.log(res)
          // console.log("监测",this.record)
          if (res.data.state == 0) {
            this.hasPermission = false
          } else if (res.data.state == 1) {
            this.is_has_create = res.data.data.is_has_create
            this.is_has_modify = res.data.data.is_has_modify
            this.is_has_modify_other = res.data.data.is_has_modify_other
            this.is_has_del = res.data.data.is_has_del
            this.is_has_del_other = res.data.data.is_has_del_other
          }
        })
    },
    changeFocus (e) {
      var inputGroup = document.getElementsByTagName('input')
      var inputGroupArr = Array.from(document.getElementsByTagName('input'))
      var iGlength = inputGroupArr.length
      var e = event || e
      // console.log(inputGroupArr.indexOf(e.srcElement));
      var idx = inputGroupArr.indexOf(e.srcElement)
      // console.log(e,e.keyCode,e.srcElement,e.which);
      if (e.keyCode == 13 || e.which == 13) {
        // e.which = 9;
        // e.charCode = 9;
        // e.code = "tab";
        // 并不能实现
        // if(idx == iGlength - 1){//表明已经是最后一个输入框
        //     if(confirm('确认提交吗？')){
        //         document.getElementsByTagName("form")[0].submit();
        //     }
        // }else{
        inputGroup[idx + 1].focus()
      }
      // e.preventDefault();
    },
    getDoctorName (id) {
      let arr = this.$store.getters.adminUserArr.adminUserArr
      let name = ''
      arr.map(item => {
        if (id == item.id) {
          name = item.name
        }
      })
      return name
    },

    getTimes (time) {
      return parseTime(time, '{h}:{i}')
    },

    GetAnticoagulantById: function (val) {
      let anticoagulan_name = ''
      let anticoagulant = this.anticoagulantsConfit

      for (let keys in anticoagulant) {
        if (anticoagulant[keys].id == val) {
          anticoagulan_name = anticoagulant[keys].name
        }
      }

      return anticoagulan_name
    }
  },
  components: {
    CheckBoxSubMenu
  }
}
</script>

<style style="stylesheet/scss" lang="scss" scoped>
.DialogContent {
  .content {
    .cell {
      float: left;
      width: 4.8rem;
      margin: 0.35rem 0 0 0.5rem !important;
      label {
        display: block;
        height: 0.55rem;
        line-height: 0.55rem;
        color: $pgh-color;
        font-size: 0.45rem;
        margin-bottom: 0.2rem;
      }
      select {
        width: 100%;
        padding: 0.2rem 0;
        border: 1px $border-color solid;
        border-radius: 2px;
        padding-left: 5px;
      }

      .inputBox {
        border: 1px $border-color solid;
        border-radius: 2px;
        padding: 0.18rem 0;
        padding-left: 5px;
        width: 100%;
        @media only screen and (max-width: 415px) {
          padding: 12px 0;
        }
        @media only screen and (min-width: 415px) and (max-width: 767px) {
          padding: 9.4px 0;
        }
        @media only screen and (min-width: 768px) {
          height: 60px;
          line-height: 60px;
          font-size: 0.45rem;
        }
      }
      .typeButton {
        height: 38px;
        line-height: 38px;
        font-size: 0.42rem;
        padding: 0 !important;
        @media only screen and (min-width: 415px) and (max-width: 767px) {
          font-size: 0.4rem;
        }
        @media only screen and (min-width: 768px) {
          height: 60px;
          line-height: 60px;
          font-size: 0.45rem;
          padding: 0 !important;
        }
      }
      .input_focus {
        margin-bottom: 2rem;
      }
      .textarea {
        width: 100%;
        height: 1.22rem;
        border: 1px $border-color solid;
        border-radius: 2px;
        padding-left: 5px;
      }
    }
    .width {
      width: 95%;
      @include box-sizing;
      label {
        display: inline-block;
      }
      button {
        background: $main-color;
        color: #fff;
        border-radius: 6px;
        width: 3.1rem;
        height: 0.9rem;
        line-height: 0.9rem;
        text-align: center;
        margin: 0 0 0.9rem 0;
      }
    }
    .center {
      text-align: center;
    }
  }
  .newMonitTable {
    width: 1670px;
  }
}

.row-class-active > td {
  background: #badcff !important;
}
.doctor {
  font-size: 0.45rem;
}
</style>
<style lang="scss">
.el-table td {
  padding: 0;
}
.el-table th {
  padding: 6px 0;
}
</style>
