<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 inline">
        <label>入室方式 : </label>
        <div class="check">
          <el-radio v-model="receiveTreatmentAsses.way" label="1">步行</el-radio>
          <el-radio v-model="receiveTreatmentAsses.way" label="2">扶行</el-radio>
          <el-radio v-model="receiveTreatmentAsses.way" label="3">轮椅</el-radio>
          <el-radio v-model="receiveTreatmentAsses.way" label="4">平车</el-radio>
        </div>
      </div>

      <div class="cell inline">
        <label>病人意识 : </label>
        <div class="check">

          <el-radio v-model="receiveTreatmentAsses.consciousness" label="1">清醒</el-radio>
          <el-radio v-model="receiveTreatmentAsses.consciousness" label="2">嗜睡</el-radio>
          <el-radio v-model="receiveTreatmentAsses.consciousness" label="3">昏迷</el-radio>

        </div>
      </div>
      <div class="cell inline">
        <label>病人食欲 : </label>
        <div class="check">
          <van-radio-group>
            <el-radio v-model="receiveTreatmentAsses.appetite" label="1">正常</el-radio>
            <el-radio v-model="receiveTreatmentAsses.appetite" label="2">减退</el-radio>
            <el-radio v-model="receiveTreatmentAsses.appetite" label="3">恶心</el-radio>
            <el-radio v-model="receiveTreatmentAsses.appetite" label="4">呕吐</el-radio>
            <el-radio v-model="receiveTreatmentAsses.appetite" label="5">腹泻</el-radio>
          </van-radio-group>
        </div>
      </div>
      <div class="cell inline">
        <label>病人情况 : </label>
        <div class="check">
          <van-radio-group>
            <el-radio v-model="receiveTreatmentAsses.condition" label="1">住院</el-radio>
            <el-radio v-model="receiveTreatmentAsses.condition" label="2">手术期</el-radio>
          </van-radio-group>
        </div>
      </div>
      <div class="cell width center">
        <button @click="commitInfo">提交</button>
      </div>
    </div>
  </div>
</template>


<script>
import { commitAcceptsAssessment } from "@/api/dialysis";

import { Toast } from "vant";

export default {
  name: "AcceptsAssessment",
  props: {
    accepts: {
      type: Object
    },
    patient_prop: {
      type: Object
    }
  },

  data() {
    return {
      id: 0,
      receiveTreatmentAsses: {
        way: "1",
        consciousness: "1",
        appetite: "1",
        condition: "1"
      },
      patient: {
        id: 0
      },
      doctor: "",
      title: "接诊评估",
      record_date:""
    };
  },
  created() {
    if (this.accepts == null) {
      this.receiveTreatmentAsses.way = "1";
      this.receiveTreatmentAsses.consciousness = "1";
      this.receiveTreatmentAsses.appetite = "1";
      this.receiveTreatmentAsses.condition = "1";
      this.patient.id = 0;

    } else {
      this.receiveTreatmentAsses.way = this.accepts.way + ""
      this.receiveTreatmentAsses.consciousness = this.accepts.consciousness + ""
      this.receiveTreatmentAsses.appetite = this.accepts.appetite + ""
      this.receiveTreatmentAsses.condition = this.accepts.condition + ""
    }

    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.patient.id = this.patient_prop.id;
  },
  methods: {
    commitInfo: function() {
      let ParamsQuery = this.receiveTreatmentAsses;
      ParamsQuery["patient"] =  this.patient.id
      ParamsQuery["record_date"] = this.record_date;
      // console.log(ParamsQuery)
      // return
      commitAcceptsAssessment(ParamsQuery).then(response => {
        if (response.data.state == 0) {
          Toast.fail(response.data.msg);
          return false;
        } else {
          Toast.success("提交成功");
          // this.$emit(
          //   "receiveTreatmentAsses",
          //   response.data.data.receiveTreatmentAsses
          // );
          console.log(response.data.data.receiveTreatmentAsses)
          for (const key in response.data.data.receiveTreatmentAsses) {
            // if (key == "id") {
            //   continue
            // }
            this.accepts[key] = response.data.data.receiveTreatmentAsses[key]
          }
          // this.accepts["id"] = response.data.data.receiveTreatmentAsses["id"]
        }
      });
    }
  }
};
</script>

<style style="stylesheet/scss" lang="scss" scoped>
.content {
  .cell {
    label {
      display: inline-block;
      margin: 0 0.2rem 0 0;
      float: left;
    }
    span {
      margin: 0.07rem 0 0 0;
      display: inline-block;
    }
    select {
      width: 3.2rem;
    }
    .textarea {
      height: 2.16rem;
    }
  }
  .inline {
    display: inline-block;
    width: 96% !important;
  }
}
</style>
