<template>
    <div class="accepts">
        <div>
            <div class="warnTxt" v-if="showTxt != ''">
                {{ showTxt }}
            </div>
            <van-collapse v-model="activeNames" accordion>
                <van-collapse-item v-if="isShow('入室方式')" title="入室方式" name="1">
                  <template slot="title">
                  <div><span v-if="isShow_title('入室方式')" class="warn_tip">*</span>入室方式</div>
                  </template>
                    <template #value>
                        <div>{{GetWay(receiveTreatmentAsses.way)}}</div>
                    </template>
                    <van-radio-group v-model="receiveTreatmentAsses.way">
                        <van-radio :name="item.id" v-for='(item,index) in way_arr' :key="index">{{ item.name }}</van-radio>
                    </van-radio-group>
                </van-collapse-item>
                <van-collapse-item v-if="isShow('病人意识')" title="病人意识" name="2">
                  <template slot="title">
                  <div><span v-if="isShow_title('病人意识')" class="warn_tip">*</span>病人意识</div>
                  </template>
                    <template #value>
                        <div>{{GetConsciousness(receiveTreatmentAsses.consciousness)}}</div>
                    </template>
                    <van-radio-group v-model="receiveTreatmentAsses.consciousness">
                        <van-radio :name="item.id" v-for='(item,index) in consciousness_arr' :key="index">{{ item.name }}</van-radio>
                    </van-radio-group>
                </van-collapse-item>
                <van-collapse-item v-if="isShow('病人食欲')" title="病人食欲" name="3">
                  <template slot="title">
                  <div><span v-if="isShow_title('病人食欲')" class="warn_tip">*</span>病人食欲</div>
                  </template>
                    <template #value>
                        <div>{{GetAppetite(receiveTreatmentAsses.appetite)}}</div>
                    </template>
                    <van-radio-group v-model="receiveTreatmentAsses.appetite">
                        <van-radio :name="item.id" v-for='(item,index) in appetite_arr' :key="index">{{ item.name }}</van-radio>
                    </van-radio-group>
                </van-collapse-item>
                <van-collapse-item v-if="isShow('病人情况')" title="病人情况" name="4">
                  <template slot="title">
                  <div><span v-if="isShow_title('病人情况')" class="warn_tip">*</span>病人情况</div>
                  </template>
                    <template #value>
                        <div>{{GetCondition(receiveTreatmentAsses.condition)}}</div>
                    </template>
                    <van-radio-group v-model="receiveTreatmentAsses.condition" @change="changeRadio">
                       <van-radio :name="2">门诊</van-radio>
                        <van-radio :name="1">住院</van-radio>
                        <van-radio :name="3">手术期</van-radio>
                        <van-radio :name="4">急诊</van-radio>
                    </van-radio-group>
                </van-collapse-item>
                <van-field v-model="receiveTreatmentAsses.admission_number"
                 v-if="receiveTreatmentAsses.condition == 1"
                  :required="isShow_title('住院号')"
                   label="住院号" input-align="right"/>
                <van-field v-model="receiveTreatmentAsses.his_department" v-if="receiveTreatmentAsses.condition == 1" :required="isShow_title('住院科室')" label="住院科室" input-align="right"/>
                <van-field v-model="receiveTreatmentAsses.his_bed" v-if="receiveTreatmentAsses.condition == 1" :required="isShow_title('住院床位')" label="住院床位" input-align="right"/>
                <van-field v-model="receiveTreatmentAsses.diacrisis" v-if="isShow('诊断') && receiveTreatmentAsses.condition == 1" :required="isShow_title('诊断') && receiveTreatmentAsses.condition == 1" label="诊断" input-align="right"/>
                <van-collapse-item v-if="isShow('体位')" title="体位" name="5">
                  <template slot="title">
                  <div><span v-if="isShow_title('体位')" class="warn_tip">*</span>体位</div>
                  </template>
                    <template #value>
                        <div>{{GetPosture(receiveTreatmentAsses.posture)}}</div>
                    </template>
                    <van-radio-group v-model="receiveTreatmentAsses.posture">
                        <van-radio :name="item.id" v-for='(item,index) in posture_arr' :key="index">{{ item.name }}</van-radio>
                    </van-radio-group>
                </van-collapse-item>
                <van-collapse-item v-if="isShow('病情')" title="病情" name="6">
                  <template slot="title">
                  <div><span v-if="isShow_title('病情')" class="warn_tip">*</span>病情</div>
                  </template>
                    <template #value>
                        <div>{{GetSickCondition(receiveTreatmentAsses.sick_condition)}}</div>
                    </template>
                    <van-radio-group v-model="receiveTreatmentAsses.sick_condition">
                        <van-radio :name="item.id" v-for='(item,index) in sick_condition_arr' :key="index">{{ item.name }}</van-radio>
                    </van-radio-group>
                </van-collapse-item>
                <van-field v-model="receiveTreatmentAsses.sick_condition_other" v-if="isShow('其他病情')" :required="isShow_title('其他病情')" label="其他病情" input-align="right"/><!--isShow_title('其他病情')-->
                <van-field v-model="receiveTreatmentAsses.score" v-if="isShow('跌倒风险评估评分')" :required="isShow_title('跌倒风险评估评分')" label="跌倒风险评估评分" input-align="right"/>
                <van-collapse-item v-if="isShow('风险程度')" title="风险程度" name="7">
                  <template slot="title">
                  <div><span v-if="isShow_title('风险程度')" class="warn_tip">*</span>风险程度</div>
                  </template>
                    <template #value>
                        <div>{{GetDangerLevel(receiveTreatmentAsses.danger_level)}}</div>
                    </template>
                    <van-radio-group v-model="receiveTreatmentAsses.danger_level">
                        <van-radio :name="1">无</van-radio>
                        <van-radio :name="2">低风险</van-radio>
                        <van-radio :name="3">中度风险</van-radio>
                        <van-radio :name="4">高风险</van-radio>
                    </van-radio-group>
                </van-collapse-item>
                <van-collapse-item v-if="isShow('跌倒风险预防措施')" title="跌倒风险预防措施" name="8">
                  <template slot="title">
                  <div><span v-if="isShow_title('跌倒风险预防措施')" class="warn_tip">*</span>跌倒风险预防措施</div>
                  </template>
                    <template #value>
                        <div>{{GetPrecaution(precautionTwo)}}</div>
                    </template>
                    <van-checkbox-group v-model="precautionTwo">
                        <van-checkbox :name="item.id" v-for='(item,index) in precaution_arr' :key="index">{{ item.name }}</van-checkbox>
                    </van-checkbox-group>
                </van-collapse-item>
                <van-field v-model="receiveTreatmentAsses.precaution_other" v-if="isShow('其他跌倒风险预防措施')" :required="isShow_title('其他跌倒风险预防措施')" label="其他跌倒风险预防措施" input-align="right"/>
                <van-collapse-item v-if="isShow('摄入量')" title="摄入量" name="9">
                  <template slot="title">
                  <div><span v-if="isShow_title('摄入量')" class="warn_tip">*</span>摄入量</div>
                  </template>
                    <template #value>
                        <div>{{GetIntake(receiveTreatmentAsses.intake)}}</div>
                    </template>
                    <van-radio-group v-model="receiveTreatmentAsses.intake">
                        <van-radio :name="item.id" v-for='(item,index) in intake_arr' :key="index">{{ item.name }}</van-radio>
                    </van-radio-group>
                </van-collapse-item>
                <van-collapse-item v-if="isShow('营养状况')" title="营养状况" name="10">
                  <template slot="title">
                  <div><span v-if="isShow_title('营养状况')" class="warn_tip">*</span>营养状况</div>
                  </template>
                    <template #value>
                        <div>{{GetNutrition(receiveTreatmentAsses.nutrition)}}</div>
                    </template>
                    <van-radio-group v-model="receiveTreatmentAsses.nutrition">
                        <van-radio :name="item.id" v-for='(item,index) in nutrition_arr' :key="index">{{ item.name }}</van-radio>
                    </van-radio-group>
                </van-collapse-item>
                <van-collapse-item v-if="isShow('心理评估')" title="心理评估" name="11">
                  <template slot="title">
                  <div><span v-if="isShow_title('心理评估')" class="warn_tip">*</span>心理评估</div>
                  </template>
                    <template #value>
                        <div>{{GetPsychologicalAssessment(receiveTreatmentAsses.psychological_assessment)}}</div>
                    </template>
                    <van-radio-group v-model="receiveTreatmentAsses.psychological_assessment">
                        <van-radio :name="1">正常</van-radio>
                        <van-radio :name="2">异常</van-radio>
                    </van-radio-group>
                </van-collapse-item>
                <van-collapse-item v-if="isShow('是否跌倒')" title="是否跌倒" name="12">
                  <template slot="title">
                    <div><span v-if="isShow_title('是否跌倒')" class="warn_tip">*</span>是否跌倒</div>
                    </template>
                      <template #value>
                          <div>{{GetPsyTumble(receiveTreatmentAsses.tumble)}}</div>
                      </template>
                      <van-radio-group v-model="receiveTreatmentAsses.tumble">
                          <van-radio :name="1">是</van-radio>
                          <van-radio :name="2">否</van-radio>
                      </van-radio-group>
                </van-collapse-item>
                <van-field v-model="receiveTreatmentAsses.psychological_assessment_other" v-if="isShow('心理评估异常情况') && receiveTreatmentAsses.psychological_assessment == 2" :required="isShow_title('心理评估异常情况')&& receiveTreatmentAsses.psychological_assessment == 2" label="心理评估异常情况" input-align="right"/>
                <van-field v-model="receiveTreatmentAsses.psychological_other" v-if="isShow('其他心理评估')" :required="isShow_title('其他心理评估')" label="其他心理评估" input-align="right"/>
            </van-collapse>
        </div>
        <div class="preserveBox">
            <div @click="commitInfo" v-if="hasPermission && isCommit">保存</div>
            <div v-else class="disabled">保存</div>
        </div>

      <van-popup
        v-model="infor_visibility"
        class="advicePopup"
        get-container="#today_panel"
      >
        <infor-sub-menu
        :visibility="infor_visibility"
        v-on:menu-cancle-three="menuCancleFour"
        v-on:menu-comfirm-three="menuComfirmFour"
        >
      </infor-sub-menu>
      </van-popup>
    </div>
</template>

<script>
import { commitAcceptsAssessment, getLastAccepts,saveMobileInformation,getLastAcceptRecords } from '@/api/dialysis'
import InforSubMenu from "../dialog/subMenu/InforSubMenu.vue"
import { Toast } from 'vant'
import { Dialog } from "vant";
import { getDataConfig } from '@/utils/data'
import request from '@/utils/request'
import { data } from 'jquery';
export default {
  props: {
    accepts: {
      type: Object
    },
    patient_prop: {
      type: Object
    }
  },
  data () {
    return {
      showTxt: '',
      hasPermission: true,
      activeNames: '',
      way_arr: [],
      consciousness_arr: [],
      appetite_arr: [],
      posture_arr: [],
      sick_condition_arr: [],
      precaution_arr: [],
      intake_arr: [],
      nutrition_arr: [],
      receiveTreatmentAsses: {
        way: '1',
        consciousness: '1',
        appetite: '1',
        condition: '1',
        posture: '1',
        sick_condition: '1',
        sick_condition_other: '',
        score: '',
        danger_level: '',//1
        precaution_other: '',
        intake: '1',
        nutrition: '1',

        tumble: '',
        psychological_assessment: '1',
        psychological_assessment_other: '',
        psychological_other: '',

        precaution: '',
        admission_number: '',
        diacrisis: '',
        his_department: '',
        his_bed: ''
      },
      patient: {
        id: 0
      },
      precautionTwo: [],
      changeReceiveTreatmentAsses: 0,
      isCommit: true,
      infor_visibility:false,
    }
  },
 components: {
    InforSubMenu
  },
  computed: {
    newReceiveTreatmentAsses () {
      return JSON.parse(JSON.stringify(this.receiveTreatmentAsses))
    }
  },
  created () {
    this.getPermission()
    this.way_arr = getDataConfig('hemodialysis', 'way')
    this.consciousness_arr = getDataConfig('hemodialysis', 'consciousness')
    this.appetite_arr = getDataConfig('hemodialysis', 'appetite')
    this.posture_arr = getDataConfig('hemodialysis', 'posture')
    this.sick_condition_arr = getDataConfig('hemodialysis', 'sick_condition')
    this.precaution_arr = getDataConfig('hemodialysis', 'precaution')
    console.log("hhahhah",this.precaution_arr)
    this.intake_arr = getDataConfig('hemodialysis', 'intake')
    this.nutrition_arr = getDataConfig('hemodialysis', 'nutrition')
    this.situation_arr = [
      {id: 1, name: '住院'},
      {id: 2, name: '门诊'},
      {id: 3, name: '手术期'},
      {id: 4, name: '急诊'}
    ]
    this.danger_level_arr = [
      {id: 1, name: '无'},
      {id: 2, name: '低风险'},
      {id: 3, name: '中度风险'},
      {id: 4, name: '高风险'}
    ]

    var arr = []

    if (this.accepts.precaution) {
      var precaution = this.accepts.precaution.split(',')
      console.log("加钱玄机搜啊",precaution)
      for (let i = 0; i < precaution.length; i++) {
        for (let j = 0; j < this.precaution_arr.length; j++) {
          if (parseInt(precaution[i]) == this.precaution_arr[j].id) {
            arr.push(this.precaution_arr[j].id)
          }
        }
      }
      this.precautionTwo = arr
    }

    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 {
             console.log("z中国hhhhhhhhhhhhhhhhh",this.accepts)
            for (const key in response.data.data.receiveTreatmentAsses) {
              this.accepts[key] = response.data.data.receiveTreatmentAsses[key]
              this.accepts['id'] = 0
              this.accepts['creater'] = 0
              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
              this.receiveTreatmentAsses.score = this.accepts.score
              this.receiveTreatmentAsses.sick_condition_other = this.accepts.sick_condition_other
              this.receiveTreatmentAsses.psychological_other = this.accepts.psychological_other

              this.receiveTreatmentAsses.precaution = this.accepts.precaution
              this.receiveTreatmentAsses.precaution_other = this.accepts.precaution_other
              this.receiveTreatmentAsses.admission_number = this.accepts.admission_number
              this.receiveTreatmentAsses.his_department = this.accepts.his_department
              this.receiveTreatmentAsses.his_bed = this.accepts.his_bed
              this.receiveTreatmentAsses.diacrisis = this.accepts.diacrisis
              this.receiveTreatmentAsses.tumble = this.accepts.tumble + ''
              this.receiveTreatmentAsses.his_department = this.accepts.his_department
              this.receiveTreatmentAsses.his_bed = this.accepts.his_bed

              if(this.$store.getters.user.template_info.org_id == 10293){
                this.receiveTreatmentAsses.way =1
                this.receiveTreatmentAsses.consciousness =2
                this.receiveTreatmentAsses.appetite =2
                this.receiveTreatmentAsses.posture= 1
                this.receiveTreatmentAsses.danger_level=2
                this.receiveTreatmentAsses.precaution = 3

                var arr = [3,4]
                this.precautionTwo.push(...arr)

                this.receiveTreatmentAsses.precaution = this.precautionTwo



              }
            }
          }
        })
        .catch(error => {
          Toast.fail('请求失败')
        })
    } 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 == '' &&
            this.accepts.sick_condition_other == '' &&
            this.accepts.psychological_other == '' &&
            this.accepts.precaution == 0 &&
            this.accepts.precaution_other == '' &&
            this.accepts.score == '' &&
            this.accepts.admission_number == ''
      ) {
        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.accepts['id'] = 0
              this.accepts['creater'] = 0

              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 + ''
              this.receiveTreatmentAsses.score = this.accepts.score
              this.receiveTreatmentAsses.sick_condition_other = this.accepts.sick_condition_other

              this.receiveTreatmentAsses.precaution = this.accepts.precaution
              this.receiveTreatmentAsses.precaution_other = this.accepts.precaution_other
              this.receiveTreatmentAsses.psychological_other = this.accepts.psychological_other
              this.receiveTreatmentAsses.admission_number = this.accepts.admission_number
              this.receiveTreatmentAsses.diacrisis = this.accepts.diacrisis
              this.receiveTreatmentAsses.tumble = this.accepts.tumble + ''
              this.receiveTreatmentAsses.his_department = this.accepts.his_department
              this.receiveTreatmentAsses.his_bed = this.accepts.his_bed
            }
          }
        })
      } 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 + ''
        this.receiveTreatmentAsses.score = this.accepts.score
        this.receiveTreatmentAsses.sick_condition_other = this.accepts.sick_condition_other

        this.receiveTreatmentAsses.precaution = this.accepts.precaution
        this.receiveTreatmentAsses.precaution_other = this.accepts.precaution_other
        this.receiveTreatmentAsses.psychological_other = this.accepts.psychological_other
        this.receiveTreatmentAsses.admission_number = this.accepts.admission_number
        this.receiveTreatmentAsses.diacrisis = this.accepts.diacrisis
        this.receiveTreatmentAsses.tumble = this.accepts.tumble + ''
        this.receiveTreatmentAsses.his_department = this.accepts.his_department
        this.receiveTreatmentAsses.his_bed = this.accepts.his_bed
      }
    }
    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_title (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&&
            filedList[i].is_write == 1
        ) {
          return true
        }
      }

      return false
    },
    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
    },
    getArrEqual(arr1, arr2) {
      let newArr = [];
      for (let i = 0; i < arr2.length; i++) {
        for (let j = 0; j < arr1.length; j++) {
            if (arr1[j].module == 2&&arr1[j].is_show == 1&&arr1[j].filed_name === arr2[i][0]&&arr1[j].is_write == 1 ) {
              newArr.push(arr1[j]);
            }

        }
      }
      return newArr;
    },

    open_tips(info) {
      for (let i = 0; i < info.length; i++) {
        if (info[i].is_write == 1) {
          Toast.fail(`${info[i].filed_name_cn}为必填字段，不能为空`)
        }
      }
      return
    },
    isWrite(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_write == 1 &&
          filedList[i].is_show == 1
        ) {
          return true;
        }
      }
      return false;
    },

    commitInfo: function () {
      if (
        this.isWrite("病人情况") == true &&
        this.receiveTreatmentAsses.condition == "0"
      ) {
        Toast.fail(`病人情况为必填字段，不能为空`)
      }
      else
      if (this.isCommit == true) {
        // this.isCommit = false
        var arr = []
        for (let i = 0; i < this.precaution_arr.length; i++) {
          for (let j = 0; j < this.precautionTwo.length; j++) {
            if (this.precaution_arr[i].id == this.precautionTwo[j]) {
              arr.push(this.precaution_arr[i].id)
            }
          }
        }
        var obj = arr.join(',')
        this.receiveTreatmentAsses.precaution = obj
        let mode = 1
        let ParamsQuery = this.receiveTreatmentAsses
        let newParams = ParamsQuery;
        // 必填弹窗开始

          if(newParams.condition !='1'){
            delete newParams.his_bed
            delete newParams.his_department
            delete newParams.admission_number
            delete newParams.diacrisis
          }

          if(newParams.psychological_assessment != 2){
            delete newParams.psychological_assessment_other
          }

          let result = [];
          let filedList = this.$store.getters.user.fileds;
          let new_arr = Object.entries(newParams);
          new_arr.forEach((el) => {
            if (el[1] === "" || el[1] === 0 ) {
              // result.push(el);
              result.unshift(el)
            }else if(el[1] =='0' && el[1].length <= 0){
              result.unshift(el)
            }else if(el[0] == 'danger_level' && el[1] == '0'){
              result.unshift(el)
            }else if(el[0] == 'psychological_assessment' && el[1] == '0'){
              result.unshift(el)
            }else if(el[0] == 'tumble' && el[1] == '0'){
              result.unshift(el)
            }
          });
          let warnarr = [];
          warnarr = this.getArrEqual(filedList, result);
           if (warnarr.length > 0) {
            this.open_tips(warnarr);
            // 必填弹窗结束
          }else{
            Toast.loading({ forbidClick: true, duration: 0 })
            ParamsQuery['patient'] = this.$route.query.patient_id
            ParamsQuery['record_date'] = this.record_date
            if (this.accepts.id > 0) {
          mode = 2
          if (this.accepts.creater != this.$store.getters.user.admin.id) {
            mode = 3
          }
        }
        ParamsQuery['mode'] = mode
        if (ParamsQuery.condition == 2 || ParamsQuery.condition == 3 || ParamsQuery.condition == 4) {
          ParamsQuery.admission_number = ''
        }

        commitAcceptsAssessment(ParamsQuery).then(response => {
            if (response.data.state == 0) {
              Toast.fail(response.data.msg)
              if(response.data.code == 600000008){
                this.infor_visibility = true
              }
              this.isCommit = true
              return false
            } else {
              Toast.success('提交成功')
              for (const key in response.data.data.receiveTreatmentAsses) {
                this.accepts[key] = response.data.data.receiveTreatmentAsses[key]
              }
            }
            this.changeReceiveTreatmentAsses = 0
            this.isCommit = true
          })
          .catch(error => {
            this.changeReceiveTreatmentAsses = 0
            Toast.fail('请求失败')
            this.isCommit = true
          })
          }
      }
    },
    GetWay (val) {
      let str = ''
      for (let i = 0; i < this.way_arr.length; i++) {
        if (this.way_arr[i].id == val) {
          str = this.way_arr[i].name
        }
      }
      return str
    },
    GetConsciousness (val) {
      let str = ''
      for (let i = 0; i < this.consciousness_arr.length; i++) {
        if (this.consciousness_arr[i].id == val) {
          str = this.consciousness_arr[i].name
        }
      }
      return str
    },
    GetAppetite (val) {
      let str = ''
      for (let i = 0; i < this.appetite_arr.length; i++) {
        if (this.appetite_arr[i].id == val) {
          str = this.appetite_arr[i].name
        }
      }
      return str
    },
    GetCondition (val) {
      let str = ''
      let arr = [
        {id: 1, name: '住院'},
        {id: 2, name: '门诊'},
        {id: 3, name: '手术期'},
        {id: 4, name: '急诊'}
      ]
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].id == val) {
          str = arr[i].name
        }
      }
      return str
    },
    GetPosture (val) {
      let str = ''
      for (let i = 0; i < this.posture_arr.length; i++) {
        if (this.posture_arr[i].id == val) {
          str = this.posture_arr[i].name
        }
      }
      return str
    },
    GetSickCondition (val) {
      let str = ''
      for (let i = 0; i < this.sick_condition_arr.length; i++) {
        if (this.sick_condition_arr[i].id == val) {
          str = this.sick_condition_arr[i].name
        }
      }
      return str
    },
    GetDangerLevel (val) {
      let str = ''
      let arr = [
        {id: 1, name: '无'},
        {id: 2, name: '低风险'},
        {id: 3, name: '中度风险'},
        {id: 4, name: '高风险'}
      ]
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].id == val) {
          str = arr[i].name
        }
      }
      return str
    },
    GetPrecaution (val) {
      let str = ''
      for (let i = 0; i < this.precaution_arr.length; i++) {
        if (val.indexOf(this.precaution_arr[i].id) > -1) {
          str += this.precaution_arr[i].name + ','
        }
      }
      return str.substr(0, str.length - 1)
    },
    GetIntake (val) {
      let str = ''
      for (let i = 0; i < this.intake_arr.length; i++) {
        if (this.intake_arr[i].id == val) {
          str = this.intake_arr[i].name
        }
      }
      return str
    },
    GetNutrition (val) {
      let str = ''
      for (let i = 0; i < this.nutrition_arr.length; i++) {
        if (this.nutrition_arr[i].id == val) {
          str = this.nutrition_arr[i].name
        }
      }
      return str
    },
    GetPsychologicalAssessment (val) {
      let str = ''
      let arr = [
        {id: 1, name: '正常'},
        {id: 2, name: '异常'}
      ]
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].id == val) {
          str = arr[i].name
        }
      }
      return str
    },
    GetPsyTumble (val) {
      let str = ''
      let arr = [
        {id: 1, name: '是'},
        {id: 2, name: '否'}
      ]
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].id == val) {
          str = arr[i].name
        }
      }
      return str
    },
    getPermission () {
      request
        .get('/m/api/permission/get', {
          params: {
            create_url: '/m/api/dialysis/acceptsAssessment?mode=1',
            modify_url: '/m/api/dialysis/acceptsAssessment?mode=2',
            modify_other_url: '/m/api/dialysis/acceptsAssessment?mode=3',
            module: 2
          }
        })
        .then(res => {

          if (res.data.state == 0) {
            this.hasPermission = false
          } else if (res.data.state == 1) {
            if (this.accepts.id != '' && this.accepts.creater != 0) {
              // 有数据
              if (this.accepts.creater == this.$store.getters.user.admin.id) {
                // 创建人是自己
                if (res.data.data.is_has_modify == false) {
                  this.hasPermission = false
                  this.showTxt = '你没有修改接诊评估权限'
                }
              } else {
                // 创建人不是自己
                if (res.data.data.is_has_modify_other == false) {
                  this.hasPermission = false
                  this.showTxt = '你没有修改他人接诊评估权限'
                }
              }
            } else if (this.accepts.id == '' || this.accepts.creater == 0) {
              if (res.data.data.is_has_create == false) {
                this.hasPermission = false
                this.showTxt = '你没有新增接诊评估权限'
              }
            }
          }
        })
    },
    isObjectValueEqual (a, b) {
      // 取对象a和b的属性名
      var aProps = Object.getOwnPropertyNames(a)
      var bProps = Object.getOwnPropertyNames(b)
      // 判断属性名的length是否一致
      if (aProps.length != bProps.length) {
        return false
      }
      // 循环取出属性名，再判断属性值是否一致
      for (var i = 0; i < aProps.length; i++) {
        var propName = aProps[i]
        if (a[propName] != b[propName]) {
          return false
        }
      }
      return true
    },
    menuComfirmFour:function(start_time,remark){
       var params = {
         patient_id:this.$route.query.patient_id,
         record_date:this.$route.query.date,
         start_time:start_time,
         module:2,
         remark:remark,
       }

      saveMobileInformation(params).then(response=>{
        if(response.data.state == 1){
           this.infor_visibility = false
           Toast.success('申请成功')
        }
      })
    },
    menuCancleFour:function(){
     this.infor_visibility = false

    },
    changeRadio(val){
      console.log("hahdfh hadfh a",val)
      if(val == 1){
        var params = {
         patient_id:this.$route.query.patient_id
       }
        getLastAcceptRecords(params).then(response=>{
           if(response.data.state == 1){
             var records =  response.data.data.recrods
             console.log("recors",records)
             if(records!=null){
              this.receiveTreatmentAsses.admission_number = records.admission_number
              this.receiveTreatmentAsses.his_department = records.his_department
              this.receiveTreatmentAsses.his_bed =records.his_bed
             }

           }
        })
      }else{
        this.receiveTreatmentAsses.admission_number=""
      }

    }
  },
  watch: {
    newReceiveTreatmentAsses: {
      handler (newVal, oldVal) {
        if (!this.isObjectValueEqual(newVal, oldVal)) {
          this.changeReceiveTreatmentAsses++
        }
      },
      deep: true
    }
  }
}
</script>

<style lang="scss" scoped>
.accepts{
    display: flex;
    flex-direction: column;
    height: 100%;
    >:first-child{
        flex: 1;
        overflow-y: auto;
    }
}
.van-radio-group{
    display: flex;
    flex-wrap: wrap;
    .van-radio{
        width: 50%;
        margin-bottom: .625rem;
    }
}
.van-checkbox-group{
    display: flex;
    flex-wrap: wrap;
    .van-checkbox{
        width: 50%;
        margin-bottom: .625rem;
    }
}
.preserveBox{
    height: 3.125rem;
    display: flex;
    justify-content: space-between;
    padding: 0 1rem;
    align-items: center;
    font-size: 1rem;

    >:first-child{
        text-align: center;
        height: 2.5rem;
        width: 100%;
        line-height: 2.5rem;
        background: #409eff;
        color:#fff;
        border-radius: 4px;
    }
}

.warnTxt {
  font-size: 1rem;
  height: 1.875rem;
  line-height: 1.875rem;
  text-align: center;
  background: #faa331;
  color: #fff;
}
.disabled{
  background: #D8D8D8 !important;
}
.warn_tip{
  color: red;
}
</style>
<style lang="scss">
.accepts{
    .van-field__label{
        width: 8.75rem;
    }
}

</style>
