<template>
  <div class="popup-content">
    <h2 class="title">
      <span class="line"></span>
      <p>{{ title }}</p>
      <span class="line"></span>
    </h2>
    <div class="content">
      <div class="cell">
        <label>透前称重(kg)</label>
        <input
          type="text"
          class="inputBox"
          v-model="beforeFrom.weight_before"
        />
      </div>
      <div class="cell">
        <label>附加物重(kg)</label>
        <input
          type="text"
          class="inputBox"
          v-model="beforeFrom.additional_weight"
        />
      </div>
      <div class="cell">
        <label>体温(℃)</label>
        <input type="text" class="inputBox" v-model="beforeFrom.temperature" />
      </div>
      <div class="cell">
        <label>收缩压(mmHg)</label>
        <input
          type="text"
          class="inputBox"
          v-model="beforeFrom.systolic_blood_pressure"
        />
      </div>
      <div class="cell">
        <label>舒张压(mmHg)</label>
        <input
          type="text"
          class="inputBox"
          v-model="beforeFrom.diastolic_blood_pressure"
        />
      </div>
      <div class="cell">
        <label>心率(次/分)</label>
        <input
          type="text"
          class="inputBox"
          v-model="beforeFrom.pulse_frequency"
        />
      </div>

      <div class="cell">
        <label>前次透析后</label>
        <el-select
          v-model="beforeFrom.last_post_dialysis_more"
          multiple
          collapse-tags
          placeholder="请选择"
        >
          <el-option
            v-for="item in qctxList"
            :key="item.id"
            :label="item.name"
            :value="item.name"
          >
          </el-option>
        </el-select>
      </div>
      <div class="cell">
        <label>透析期间</label>
        <el-select
          v-model="beforeFrom.dialysis_interphase_more"
          multiple
          collapse-tags
          placeholder="请选择"
        >
          <el-option
            v-for="item in txqjList"
            :key="item.id"
            :label="item.name"
            :value="item.name"
          >
          </el-option>
        </el-select>
      </div>
      <div class="cell">
        <label>透析前症状</label>
        <el-select
          v-model="beforeFrom.symptom_before_dialysis_more"
          multiple
          collapse-tags
          placeholder="请选择"
        >
          <el-option
            v-for="item in txqjList"
            :key="item.id"
            :label="item.name"
            :value="item.name"
          >
          </el-option>
        </el-select>
      </div>

      <!-- <div class="cell">
              <label>血管通路</label>
              <el-select
                v-model="beforeFrom.symptom_before_dialysis"
                multiple
                collapse-tags
                placeholder="请选择">
                <el-option
                  v-for="item in txqjList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.name">
                </el-option>
              </el-select>
            </div> -->
      <div class="cell">
        <label>导管</label>
        <el-select
          v-model="beforeFrom.catheter_more"
          multiple
          collapse-tags
          placeholder="请选择"
        >
          <el-option
            v-for="item in dgList"
            :key="item.id"
            :label="item.name"
            :value="item.name"
          >
          </el-option>
        </el-select>
      </div>
      <div class="cell">
        <label>合并症</label>
        <el-select
          v-model="beforeFrom.complication_more"
          multiple
          collapse-tags
          placeholder="请选择"
        >
          <el-option
            v-for="item in hbzList"
            :key="item.id"
            :label="item.name"
            :value="item.name"
          >
          </el-option>
        </el-select>
      </div>

      <div class="cell width">
        <label>备注</label>
        <textarea type="text" class="textarea" v-model="beforeFrom.remark">
        </textarea>
      </div>
      <div class="cell width">
        <label>处方医生：</label>
        <span>{{ doctor }}</span>
      </div>
      <div class="cell width center">
        <button @click="submitBefore">提交</button>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";

import { EditAssessmentBeforeDislysis } from "@/api/patient";
export default {
  name: "PreDialysis",
  data() {
    return {
      title: "透前评估 ",
      doctor: "",
      tqtz: "5",
      fjwz: "5",
      tw: "5",
      ssy: "5",
      szy: "5",
      xl: "5",
      qctxList: [],
      txqjList: [],
      dgList: [],
      hbzList: [],
      bz: "5",
      beforeFrom: {
        id: 0,
        user_org_id: "",
        patient_id: "",
        assessment_date: "",
        dialysis_order_id: "",
        temperature: "",
        pulse_frequency: "",
        breathing_rate: "",
        systolic_blood_pressure: "",
        diastolic_blood_pressure: "",
        blood_pressure_type: "",
        dry_weight: "",
        weight_after_last_transparency: "",
        weighing_way: "",
        weighing_before: "",
        additional_weight: "",
        weight_before: "",
        weight_gain: "",
        preloaded_dewatering: "",
        ultrafiltration_amount: "",
        dialysis_interphase: "",
        dialysis_interphase_more: [],
        last_post_dialysis: "",
        last_post_dialysis_more: "",
        symptom_before_dialysis: "",
        symptom_before_dialysis_more: "",
        internal_fistula: "",
        catheter: "",
        catheter_more: "",
        complication: "",
        complication_more: "",
        evaluator: "",
        creater: "",
        remark: "",
        status: "",
        created_time: "",
        updated_time: "",
        modifier: ""
      },
      patient: {
        id: 0
      },
      record_date: ""
    };
  },
  props: {
    patient_prop: {
      type: Object
    },
    predialysis: {
      type: Object
    }
  },
  created() {
    this.patient = this.patient_prop;

    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();
    }
    this.record_date =
      y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);

    this.qctxList = this.$store.getters.last_dialysis_after;
    this.txqjList = this.$store.getters.dialysis_before;
    this.dgList = this.$store.getters.catheter;
    this.hbzList = this.$store.getters.complication;
    if (this.predialysis) {
      this.beforeFrom = this.predialysis;

      // this.beforeFrom.dialysis_interphase_more = this.predialysis.dialysis_interphase.split(',');
      // this.beforeFrom.last_post_dialysis_more = this.predialysis.last_post_dialysis.split(',');
      // this.beforeFrom.symptom_before_dialysis_more = this.predialysis.symptom_before_dialysis.split(',');
      // this.beforeFrom.catheter_more = this.predialysis.catheter.split(',');
      // this.beforeFrom.complication_more = this.predialysis.complication.split(',');
    }

    this.doctor = this.$store.getters.user.user.user_name;
  },
  methods: {
    initPredialysisEvaluation(patient, evaluation, doctor, datetime) {
      //上层传值
      this.patient = patient;
      this.beforeFrom = evaluation;
      this.doctor = doctor;
      this.record_date = datetime;
    },

    submitBefore() {
      this.beforeFrom.complication = this.beforeFrom.complication_more.join(
        ","
      );
      this.beforeFrom.catheter = this.beforeFrom.catheter_more.join(",");
      this.beforeFrom.symptom_before_dialysis = this.beforeFrom.symptom_before_dialysis_more.join(
        ","
      );
      this.beforeFrom.dialysis_interphase = this.beforeFrom.dialysis_interphase_more.join(
        ","
      );
      this.beforeFrom.last_post_dialysis = this.beforeFrom.last_post_dialysis_more.join(
        ","
      );
      EditAssessmentBeforeDislysis(
        this.patient.id,
        this.record_date,
        this.beforeFrom
      ).then(response => {
        if (response.data.state == 0) {
          Toast(response.data.msg);
          return false;
        } else {
          Toast("提交完成");
          this.$emit("evaluation", response.data.data.evaluation);
        }
      });
    }
  }
};
</script>

<style style="stylesheet/scss" lang="scss" scoped></style>
