<template>
  <div>
    <div class="Dialog">
      <div class="DialogTit">
        <span class="iconfont" @click="close()">&#xe6e9;</span>
        <h1 class="name">接诊评估</h1>
        <span class="success" @click="commitInfo">完成</span>
      </div>
      <div class="DialogContent choose">
        <el-form :model="receiveTreatmentAsses" label-width="90px">
          <el-form-item label="入室方式: " v-if="isShow('入室方式')">
            <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>
            <!--</el-radio-group>-->
          </el-form-item>
          <el-form-item label="病人意识: " v-if="isShow('病人意识')">

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

          </el-form-item>
          <el-form-item label="病人食欲: " v-if="isShow('病人食欲')">
            <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>
          </el-form-item>
          <el-form-item label="病人情况: " v-if="isShow('病人情况')">
            <el-radio v-model="receiveTreatmentAsses.condition" label="1">住院</el-radio>
            <el-radio v-model="receiveTreatmentAsses.condition" label="2">门诊</el-radio>
            <el-radio v-model="receiveTreatmentAsses.condition" label="3">手术期</el-radio>
          </el-form-item>
          <el-form-item label="体位: " v-if="isShow('体位')">
            <el-radio v-model="receiveTreatmentAsses.posture" label="1">自动体位</el-radio>
            <el-radio v-model="receiveTreatmentAsses.posture" label="2">平卧位</el-radio>
            <el-radio v-model="receiveTreatmentAsses.posture" label="3">半卧位</el-radio>
            <el-radio v-model="receiveTreatmentAsses.posture" label="4">端坐位</el-radio>
            <el-radio v-model="receiveTreatmentAsses.posture" label="5">躁动不安</el-radio>
          </el-form-item>
          <el-form-item label="病情: "  v-if="isShow('病情')">
            <el-radio v-model="receiveTreatmentAsses.sick_condition" label="1">一般</el-radio>
            <el-radio v-model="receiveTreatmentAsses.sick_condition" label="2">严重</el-radio>
            <el-radio v-model="receiveTreatmentAsses.sick_condition" label="3">危</el-radio>
          </el-form-item>

          <el-form-item label="风险程度: " v-if="isShow('风险程度')">
            <el-radio v-model="receiveTreatmentAsses.danger_level" label="1">无</el-radio>
            <el-radio v-model="receiveTreatmentAsses.danger_level" label="2">低风险</el-radio>
            <el-radio v-model="receiveTreatmentAsses.danger_level" label="3">中度风险</el-radio>
            <el-radio v-model="receiveTreatmentAsses.danger_level" label="4">高风险</el-radio>

          </el-form-item>
          <el-form-item label="摄入量: "  v-if="isShow('摄入量')">
            <el-radio v-model="receiveTreatmentAsses.intake" label="1">正常</el-radio>
            <el-radio v-model="receiveTreatmentAsses.intake" label="2">减少</el-radio>
          </el-form-item>
          <el-form-item label="营养状况: "  v-if="isShow('营养状况')">
            <el-radio v-model="receiveTreatmentAsses.nutrition" label="1">正常</el-radio>
            <el-radio v-model="receiveTreatmentAsses.nutrition" label="2">营养不良</el-radio>
          </el-form-item>
          <el-form-item label="心理评估: "  v-if="isShow('心理评估')">
            <el-radio v-model="receiveTreatmentAsses.psychological_assessment" label="1">正常</el-radio>
            <el-radio v-model="receiveTreatmentAsses.psychological_assessment" label="2">异常</el-radio>
          </el-form-item>
          <el-form-item label-width="100dp" label="心理评估异常情况 : "
                        v-if="isShow('心理评估异常情况')&&receiveTreatmentAsses.psychological_assessment == 2">
            <el-input v-model="receiveTreatmentAsses.psychological_assessment_other"></el-input>
          </el-form-item>
        </el-form>
        <!-- <div class="button">
          <button @click="commitInfo" class="submitButton">提交</button>
      </div> -->
      </div>
      <!-- <div class="footer">
          处方医生：刘小军 医生
      </div> -->
    </div>
  </div>
</template>

<script>
  import {commitAcceptsAssessment, getLastAccepts} from '@/api/dialysis'
  import {Toast} from 'vant'

  export default {
    name: 'AcceptsDialog',
    data () {
      return {
        receiveTreatmentAsses: {
          way: '1',
          consciousness: '1',
          appetite: '1',
          condition: '1',
          posture: '1',
          sick_condition: '1',
          danger_level: '1',
          intake: '1',
          nutrition: '1',
          psychological_assessment: '1',
          psychological_assessment_other: '',
        },
        patient: {
          id: 0
        },
        record_date: ''
      }
    },
    props: {
      accepts: {
        type: Object
      },
      patient_prop: {
        type: Object
      }
    },
    created () {
      if (this.accepts == null || this.accepts.id == '') {
        let ParamsQuery = {}
        ParamsQuery['patient'] = this.$route.query.patient_id
        getLastAccepts(ParamsQuery).then(response => {
          if (response.data.state == 0) {
            return false
          } else {
            for (const key in response.data.data.receiveTreatmentAsses) {
              this.accepts[key] = response.data.data.receiveTreatmentAsses[key]
              this.receiveTreatmentAsses.way = this.accepts.way + ''
              this.receiveTreatmentAsses.consciousness =
                this.accepts.consciousness + ''
              this.receiveTreatmentAsses.appetite = this.accepts.appetite + ''
              this.receiveTreatmentAsses.condition = this.accepts.condition + ''
              this.receiveTreatmentAsses.posture = this.accepts.posture + ''
              this.receiveTreatmentAsses.sick_condition = this.accepts.sick_condition + ''
              this.receiveTreatmentAsses.danger_level = this.accepts.danger_level + ''
              this.receiveTreatmentAsses.intake = this.accepts.intake + ''
              this.receiveTreatmentAsses.nutrition = this.accepts.nutrition + ''
              this.receiveTreatmentAsses.psychological_assessment = this.accepts.psychological_assessment + ''
              this.receiveTreatmentAsses.psychological_assessment_other = this.accepts.psychological_assessment_other

            }
          }
        })
      } else {
        if (
          this.accepts.way == 0 &&
          this.accepts.consciousness == 0 &&
          this.accepts.appetite == 0 &&
          this.accepts.condition == 0 &&
          this.accepts.posture == 0 &&
          this.accepts.sick_condition == 0 &&
          this.accepts.danger_level == 0 &&
          this.accepts.intake == 0 &&
          this.accepts.nutrition == 0 &&
          this.accepts.psychological_assessment == 0 &&
          this.accepts.psychological_assessment_other == ''
        ) {
          let ParamsQuery = {}
          ParamsQuery['patient'] = this.$route.query.patient_id
          getLastAccepts(ParamsQuery).then(response => {
            if (response.data.state == 0) {
              return false
            } else {
              for (const key in response.data.data.receiveTreatmentAsses) {
                this.accepts[key] = response.data.data.receiveTreatmentAsses[key]
                this.receiveTreatmentAsses.way = this.accepts.way + ''
                this.receiveTreatmentAsses.consciousness =
                  this.accepts.consciousness + ''
                this.receiveTreatmentAsses.appetite = this.accepts.appetite + ''
                this.receiveTreatmentAsses.condition =
                  this.accepts.condition + ''
                this.receiveTreatmentAsses.posture = this.accepts.posture + ''
                this.receiveTreatmentAsses.sick_condition = this.accepts.sick_condition + ''
                this.receiveTreatmentAsses.danger_level = this.accepts.danger_level + ''
                this.receiveTreatmentAsses.intake = this.accepts.intake + ''
                this.receiveTreatmentAsses.nutrition = this.accepts.nutrition + ''
                this.receiveTreatmentAsses.psychological_assessment = this.accepts.psychological_assessment + ''
                this.receiveTreatmentAsses.psychological_assessment_other = this.accepts.psychological_assessment_other + ''

              }
            }
          })
        } 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 + ''
          this.receiveTreatmentAsses.posture = this.accepts.posture + ''
          this.receiveTreatmentAsses.sick_condition = this.accepts.sick_condition + ''
          this.receiveTreatmentAsses.danger_level = this.accepts.danger_level + ''
          this.receiveTreatmentAsses.intake = this.accepts.intake + ''
          this.receiveTreatmentAsses.nutrition = this.accepts.nutrition + ''
          this.receiveTreatmentAsses.psychological_assessment = this.accepts.psychological_assessment + ''
          this.receiveTreatmentAsses.psychological_assessment_other = this.accepts.psychological_assessment_other + ''


        }
      }

      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: {
      isShow(name){
        var filedList = this.$store.getters.user.fileds
        for (let i = 0; i < filedList.length; i++){
          if(filedList[i].module == 2 && filedList[i].filed_name_cn == name&&filedList[i].is_show == 1){
            return true
          }
        }
        return false
      },
      commitInfo: function () {
        Toast.loading({forbidClick: true, duration: 0})
        let ParamsQuery = this.receiveTreatmentAsses
        // ParamsQuery["patient"] =  this.patient.id
        ParamsQuery['patient'] = this.$route.query.patient_id
        ParamsQuery['record_date'] = this.record_date

        commitAcceptsAssessment(ParamsQuery).then(response => {
          if (response.data.state == 0) {
            Toast.fail(response.data.msg)
            return false
          } else {
            Toast.success('提交成功')
            for (const key in response.data.data.receiveTreatmentAsses) {
              this.accepts[key] = response.data.data.receiveTreatmentAsses[key]
            }
            this.finish()
          }
        })
      },
      finish: function () {
        this.$emit('finish')
      },
      close: function () {
        this.$emit('close')
      }
    }
  }
</script>

<style style="stylesheet/scss" lang="scss" scoped>
  .choose {
  .el-form-item {
  margin-bottom: 0;
  border-bottom: 1px #e5e5e5 solid;
  padding: 0.15rem 0.36rem;
  .el-radio {
  font-size: 18px;
  }

  }
  .button {
  text-align: center;
  margin-top: 1rem;
  .submitButton {
  width: 3rem;
  height: 0.8rem;
  line-height: 0.8rem;
  background: $main-color;
  color: #fff;
  font-size: 0.3rem;
  text-align: center;
  border-radius: 6px;
  }
  }
  }
</style>

