<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 style="width:100%;background: #fff;">
         <div class="yzNav" style="width:80%">
                <span @click="openForm()">新增监测</span>
                <span @click="openEidtForm()">修改监测</span>
                <span @click="deleteForm()">删除监测</span>
            </div>
          </div>
        <div class="DialogContent choose" id="dialogTop">
           <div style="width:100%;overflow:hildden;">
            <table  class="table" style="">
            <tr @click="selectRow(-1, null)">
                <th  v-if="isShow('监测时间')"  width="124px">时间</th>
                <th  v-if="isShow('血压')" width="72px">血压(mmHg)</th>
                <th  v-if="isShow('心率')" width="80px">心率(次/分)</th>
                <th  v-if="isShow('呼吸')" width="110px">呼吸(次/分)</th>
                <th  v-if="isShow('血流量')" width="92px">血流量(ml/min)</th>
                <th width="76px">静脉压/动脉压(mmHg)</th>
                <th  v-if="isShow('跨膜压')" width="76px">跨膜压(mmHg)</th>
                <th  v-if="isShow('超滤量')" width="76px">超滤量(L)</th>
                <th  v-if="isShow('钠浓度')" width="92px">钠浓度(mmol/L)</th>
                <th  v-if="isShow('透析液温度')" width="82px">透析液温度(℃)</th>
                <th  v-if="isShow('置换率')" width="92px">置换率(L/h)</th>
                <th  v-if="isShow('置换量')" width="50px">置换量(L)</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.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('病情变化')">{{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">
            <div class="cell"  v-if="isShow('监测时间')">
              <label>监测时间</label>
              <input type="text" class="inputBox" @click="chooseTime()" :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">
            </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">
            </div>
            <div class="cell"  v-if="isShow('心率')">
              <label>心率(次/分)</label>
              <input type="number" @focus="inputFocus" onclick="this.select();" class="inputBox" v-model="form.pulse_frequency">
            </div>
            <div class="cell"  v-if="isShow('呼吸频率')">
              <label>呼吸频率(次/分)</label>
              <input type="number" @focus="inputFocus" onclick="this.select();" class="inputBox" v-model="form.breathing_rated">
            </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">
            </div>
            <div class="cell"  >
              <label>静脉压(mmHg)</label>
              <input type="number" @focus="inputFocus" onclick="this.select();" class="inputBox" v-model="form.venous_pressure">
            </div>
            <div class="cell"  v-if="isShow('跨膜压')">
              <label>跨膜压(mmHg)</label>
              <input type="number" @focus="inputFocus" onclick="this.select();" class="inputBox" v-model="form.transmembrane_pressure">
            </div>
            <div class="cell"  v-if="isShow('超滤量')">
              <label>超滤量(L)</label>
              <input type="number" @focus="inputFocus" onclick="this.select();" class="inputBox" v-model="form.ultrafiltration_volume">
            </div>
            <div class="cell"  v-if="isShow('超滤率')">
              <label>超滤率(ml/h)</label>
              <input type="number" @focus="inputFocus" onclick="this.select();" class="inputBox" v-model="form.ultrafiltration_rate">
            </div>
            <div class="cell"  >
              <label>动脉压(mmHg)</label>
              <input type="number" @focus="inputFocus" onclick="this.select();" class="inputBox" v-model="form.arterial_pressure">
            </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">
            </div>
            <div class="cell"  v-if="isShow('透析液温度')">
              <label>透析液温度(℃)</label>
              <input type="number" @focus="inputFocus" onclick="this.select();" class="inputBox" v-model="form.dialysate_temperature">
            </div>
            <div class="cell"  v-if="isShow('置换率')">
              <label>置换率(L/h)</label>
              <input type="number" @focus="inputFocus" onclick="this.select();" class="inputBox" v-model="form.replacement_rate">
            </div>
            <div class="cell"  v-if="isShow('置换量')">
              <label>置换量(L)</label>
              <input type="number" @focus="inputFocus" onclick="this.select();" class="inputBox" v-model="form.displacement_quantity">
            </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('病情变化')" >
              <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>{{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,
  editMonitorRecord,
  deleteMonitorRecord,
  GetMonitor
} from "@/api/dialysis";
import { parseTime } from "@/utils";
import { Toast } from "vant";
import CheckBoxSubMenu from "./subMenu/checkBoxSubMenu";
import { getDataConfig } from "@/utils/data";
import { Dialog } from "vant";

export default {
  name: "MonitDialog",

  props: {
    monitor_records: {
      type: Array
    },
    patient: {
      type: Object
    },
    order: {
      type: Object
    },
    last_monitor_record: {
      type: Object
    }
  },
  data() {
    return {
      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",

      visibility: false,
      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: "", // 静脉压
        arterial_pressure: "", // 动脉压
        transmembrane_pressure: "", // 跨膜压
        ultrafiltration_rate: "", // 超滤率
        ultrafiltration_volume: "", // 超滤量
        sodium_concentration: "", // 钠浓度
        dialysate_temperature: "", // 透析液温度
        replacement_rate: "", // 置换率
        displacement_quantity: "", // 置换量
        ktv: "", // KT/V(在线)
        symptom: "", // 症状
        dispose: "", // 处理
        result: "", // 结果
        monitoring_nurse: this.$store.getters.user.user.id // 监测人
      },
      doctor: this.$store.getters.user.user.user_name
    };
  },
  created() {
    var date = this.$route.query && this.$route.query.date;
    // date *= 1000;
    // var newDate = new Date(date);
    // var cDate = new Date();

    // var y = newDate.getFullYear();
    // var m = newDate.getMonth() + 1;
    // var d = newDate.getDate();
    // if (isNaN(y) || isNaN(m) || isNaN(d)) {
    //   // newDate = new Date();
    //   y = cDate.getFullYear();
    //   m = cDate.getMonth() + 1;
    //   d = cDate.getDate();
    // }

    // var h = cDate.getHours();
    // var mi = cDate.getMinutes();

    // var pickertime = (h < 10 ? "0" + h : h) + ":" + (mi < 10 ? "0" + mi : mi);
    // var monitor_date_str =
    //   y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
    // this.form.monitor_date = Math.round(
    //   new Date(monitor_date_str + " 00:00:00").getTime() / 1000
    // );
    // this.form.monitor_date = parseInt((new Date(date.getFullYear, date.getMonth, date.getDate, 0, 0, 0, 0)).getTime()) //parseTime(date, "{y}-{m}-{d}") + " 00:00:00"
    this.form.monitor_date = date;

    this.form.operate_time = this.pickertime.getTime();
  },
  methods: {
    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
    },
    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;
          }

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

          if(monitor.transmembrane_pressure == 0){
            this.form.transmembrane_pressure = ""
          }else {
            this.form.transmembrane_pressure = monitor.transmembrane_pressure;
          }

          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.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;
          }

          this.form.ktv = monitor.ktv;
          this.form.symptom = monitor.symptom;
          this.form.dispose = monitor.dispose;
          this.form.result = monitor.result;
          this.form.operate_time = new Date(
            monitor.operate_time * 1000
          ).getTime();
          this.form.id = -1;
        }
      });
    },
    selectRow(index, row) {
      this.currentIndex = index;
      this.currentRow = row;
    },

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

      // if (input.setSelectionRange) {
      //   setTimeout(function () {
      //     input.setSelectionRange(0, input.value.length);
      //   }, 0);
      // } else if (input.createTextRange) {
      //     var rng = input.createTextRange();
      //     rng.move('character', input.value.length);
      //     rng.select();
      // }
    },
    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) {
      if (records == null) {
        records = [];
      }
      this.tableDate.splice(0, this.tableDate.length);
      this.tableDate.push(...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
          };
          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();
      // var timeMap = time.split(":");
      // this.form.monitor_time = time;
      // this.monitor_time_str =
      //   parseTime(this.form.monitor_date, "{y}-{m}-{d}") +
      //   " " +
      //   this.form.monitor_time;

      // this.monitor_time_str = this.handleTime(time);
      // this.form.monitor_time =  parseTime(time, "{h}:{i}")
      // this.form.monitor_date = Math.round(new Date(parseTime(time, "{y}-{m}-{d}") + " 00:00:00").getTime()/1000);
    },
    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);


      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;
      }

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

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

      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.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.ktv == 0){
        this.form.ktv = ""
      }else {
        this.form.ktv = this.currentRow.ktv;
      }

      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.monitor_time_str =
      //   parseTime(this.form.monitor_date, "{y}-{m}-{d}") +
      //   " " +
      //   this.form.monitor_time;
    },
    openForm() {
      this.formTitle = "新增监测";
      this.formPanel = true;
      this.listPanel = false;
      // if(this.monitor_time_str == "") {

      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();
      if (isNaN(y) || isNaN(m) || isNaN(d)) {
        newDate = new Date();
        y = newDate.getFullYear();
        m = newDate.getMonth() + 1;
        d = newDate.getDate();
      }
      var record_date =
        y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);

      this.form.monitor_date = Math.round(
        new Date(record_date + " 00:00:00").getTime() / 1000
      );
      var nowTime = new Date();
      // this.form.monitor_time = parseTime(nowTime, "{h}:{i}");
      // this.monitor_time_str = this.handleTime(nowTime);
      // this.monitor_time_str = record_date + " " + this.form.monitor_time;

      // this.getLastRecord()

      this.form.operate_time = Date.parse(new Date());
      this.form.pulse_frequency = ""; //this.last_monitor_record.pulse_frequency;
      this.form.breathing_rated = ""; //this.last_monitor_record.breathing_rate;
      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 =""; //this.last_monitor_record.blood_flow_volume;
      this.form.venous_pressure = "";//this.last_monitor_record.venous_pressure;
      this.form.arterial_pressure = ""; //this.last_monitor_record.arterial_pressure;
      this.form.transmembrane_pressure =""; // this.last_monitor_record.transmembrane_pressure;
      this.form.ultrafiltration_rate = "";// this.last_monitor_record.ultrafiltration_rate;
      this.form.ultrafiltration_volume ="";// this.last_monitor_record.ultrafiltration_volume;
      this.form.sodium_concentration = "";//this.last_monitor_record.sodium_concentration;
      this.form.dialysate_temperature = ""; //this.last_monitor_record.dialysate_temperature;
      this.form.replacement_rate = ""; // this.last_monitor_record.replacement_rate;
      this.form.displacement_quantity =""; // this.last_monitor_record.displacement_quantity;
      this.form.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.id = -1;
      console.log(this.form);
      // }
    },
    submitEditAction: function() {
      this.loading = true
      Toast.loading({ forbidClick: true, duration: 0 });
      var params = {};
      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.arterial_pressure = this.form.arterial_pressure;
      params.transmembrane_pressure = this.form.transmembrane_pressure;
      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.replacement_rate = this.form.replacement_rate;
      params.displacement_quantity = this.form.displacement_quantity;
      params.ktv = this.form.ktv;
      params.symptom = this.form.symptom;
      params.dispose = this.form.dispose;
      params.result = this.form.result;
      params.monitoring_nurse = this.form.monitoring_nurse;
      params.id = this.form.id;
      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);

          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.replacement_rate = "";
          this.form.displacement_quantity = "";
          this.form.ktv = "";
          this.form.symptom = "";
          this.form.dispose = "";
          this.form.result = "";
          this.form.id = -1;

          Toast.success("修改成功");
          this.formPanel = false;
          this.listPanel = true;
        } else {
          this.loading = false
          Toast.fail(resp.msg);
        }
      });
    },
    submitAction: function() {
      this.loading = true
      Toast.loading({ forbidClick: true, duration: 0 });
      var params = {};
      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.arterial_pressure = this.form.arterial_pressure;
      params.transmembrane_pressure = this.form.transmembrane_pressure;
      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.replacement_rate = this.form.replacement_rate;
      params.displacement_quantity = this.form.displacement_quantity;
      params.ktv = this.form.ktv;
      params.symptom = this.form.symptom;
      params.dispose = this.form.dispose;
      params.result = this.form.result;
      params.monitoring_nurse = this.form.monitoring_nurse;
      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.monitor_records.unshift(monitor)

            // this.monitor_records= this.quickSort(this.monitor_records,"operate_time",false)

            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.replacement_rate = "";
            this.form.displacement_quantity = "";
            this.form.ktv = "";
            this.form.symptom = "";
            this.form.dispose = "";
            this.form.result = "";

            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;
      }
    },
    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;
      }
    },
    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)
      );
    }
  },
  components: {
    CheckBoxSubMenu
  }
};
</script>

<style style="stylesheet/scss" lang="scss"  scoped>
.DialogContent {
  .content {
    .cell {
      float: left;
      width: 4.93rem;
      margin: 0.35rem 0 0 0.5rem !important;
      label {
        display: block;
        height: 0.55rem;
        line-height: 0.55rem;
        color: $pgh-color;
      }
      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%;
      }
      .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;
    }
  }
}

.row-class-active > td {
  background: #badcff !important;
}
</style>

