<template>
  <a-modal
    v-model:visible="patientVisible"
    fullscreen
    :title="modalTitle"
    title-align="start"
    :footer="false"
    @cancel="handleClose"
  >
    <div class="titlebox">
      <div class="bar"></div>
      <div class="name">基本信息</div>
    </div>
    <a-form
      :model="data"
      :disabled="modalSatus == 'detail'"
      ref="modalFormRef"
      :auto-label-width="true"
    >
      <a-row :gutter="24" style="margin-top: 35px">
        <a-col :span="12">
          <a-form-item field="avatar" label="真实姓名：">
            <span
              >{{ data.name }}（{{ data.sex == 1 ? '男，' : '女，'
              }}{{ data.age }}岁）</span
            >
          </a-form-item>
        </a-col>
        <!-- <a-col :span="12"  >
      <a-form-item field="mobile" label="手机号码：">
         <span>{{data.mobile}}</span>
      </a-form-item>
    </a-col> -->
      </a-row>
      <a-row :gutter="24">
        <a-col :span="12" v-if="data.disease_class_name">
          <a-form-item field="avatar" label="所患疾病：">
            <span>{{ data.disease_class_name }}</span>
          </a-form-item>
        </a-col>
        <a-col :span="12" v-if="data.diagnosis_date"> 
          <a-form-item field="mobile" label="确诊日期：" >
            <span v-if="parseTime(data.diagnosis_date)">{{parseTime(data.diagnosis_date,'{y}-{m}-{d}') }}</span>
            <span v-else>-</span>
          </a-form-item>
        </a-col>
      </a-row>
      <a-row :gutter="24">
        <a-col :span="12" v-if="data.disease_desc">
          <a-form-item field="mobile" label="病情主诉：" >
            <span>{{ data.disease_desc }}</span>
          </a-form-item>
        </a-col>
      </a-row>
      <a-divider />
      <div class="titlebox">
        <div class="bar"></div>
        <div class="name">其他信息</div>
      </div>
      <a-col style="margin-top: 35px;">
        <div class="box" v-if="otherList.length>0">
            <div class="row" v-for="(item,index) in otherList" :key="item.type">
          <div class="num">{{index+1}}、</div>
          <div class="qabox" v-if="item.infoType==1">
            <div class="qa">
              {{item.name}}
              <text class="answer" v-if="item.status==1">是</text><text class="answer" v-else>否</text>
            </div>
            <div class="radiotip" v-if="(item.status==1 && item.desc)">
              <text>{{item.nameTip}}</text>
              {{item.desc}}
            </div>
          </div>
          <div class="qabox" v-else-if="item.infoType==2">
            <div class="qa">
              {{item.name}}
              <text class="answer" v-if="item.status==1">从不</text>
              <text class="answer" v-else-if="item.status==2">偶尔</text>
              <text class="answer" v-else-if="item.status==3">经常 </text>
              <text class="answer" v-else-if="item.status==4">每天</text>
              <text class="answer" v-else>
               <text v-if="item.type=='smoke'">已戒烟</text>
               <text v-else>已戒酒</text>
              </text>
            </div>
          </div>
          <div class="qabox" v-else-if="item.infoType==3">
            <div class="qa">
              {{item.name}}
              <text class="answer" v-if="item.status==1">从不</text>
              <text class="answer" v-else-if="item.status==2">偶尔</text>
              <text class="answer" v-else-if="item.status==3">经常 </text>
              <text class="answer" v-else-if="item.status==4">每天</text> 
            </div>
            <div class="radiotip"  v-if="(item.status && item.status!=1)">
              <text>{{item.nameTip}}</text>
              {{item.desc}}
            </div>
          </div>
          <div class="qabox" v-else-if="item.infoType==4">
            <div class="qa">
              {{item.name}}
              <text class="answer" >{{item.desc}}</text>
            </div>
          </div>
        </div>
        </div>
        <div v-else>暂无数据！</div>
      </a-col>
    </a-form>
  </a-modal>
</template>
<script setup>
import {
  reactive,
  ref,
  getCurrentInstance,
  watch,
  toRefs,

} from 'vue';
import { parseTime } from '@/utils/parseTime';
const otherList=ref([]);
const props = defineProps({
  // 是否显示
  patientVisible: {
    type: Boolean,
    default: false,
  },
  modalTitle:{
    type: String,
    default:'就诊人详情'
  },
  data: {
    type: Object,
  },
});
const emits = defineEmits(['patientVisibleChange']);
const { patientVisible, data,modalTitle } = toRefs(props);
const modalSatus = ref('detail');
const loading = ref(false);

watch(
  () => props.patientVisible,
  (value) => {
    if (value) {
      patientVisible.value = value;
    }
  }
);
watch(()=>props.data,(data)=>{
    let filter1=[];
    let filter2=[];
    let arr=[
       {
       type:"taboo",
       name:'是否服用过您想购买的药品且无相关禁忌：',
       nameTip:'',
       status:data.is_taboo,
       desc:"",
       infoType:1
     },
     {
      type:"allergy_history",
      name:'是否有过敏史：',
      nameTip:'过敏史：',
      infoType:1,
      status:data.is_allergy_history,
      desc:data.allergy_history
    },
    {
      type:"family_history",
      name:'是否有家族史：',
      nameTip:'家族史：',
      infoType:1,
      status:data.is_family_history,
      desc:data.family_history
    },
    {
      infoType:1,
      type:"pregnant",
      name:'是否处于备孕、妊娠、哺乳期：',
      nameTip:'',
      status:data.is_pregnant,
      desc:data.pregnant
    },
    {  infoType:1,
      type:"operation",
      name:'是否做过手术：',
      nameTip:'手术史',
      status:data.is_operation,
      desc:data.operation
    },
    {
      infoType:2,
      type:"drink_wine",
      name:'是否有饮酒史：',
      nameTip:'',
      status:data.drink_wine_status,
      desc:''
    },
    {
      infoType:2,
      type:"smoke",
      name:'是否有吸烟史：',
      nameTip:'',
      status:data.smoke_status,
      desc:''
    },
    {
      infoType:3,
      type:"chemical",
      name:'是否有接触过化学物：',
      nameTip:'接触过的化学物：',
      status:data.chemical_compound_status,
      desc:data.chemical_compound_describe
    },
    {
      infoType:4,
      type:'hospital',
      name:'确诊医院：',
      status:'',
      nameTip:'',
      desc:data.diagnosis_hospital
    },
    {
      type:"takeMedince",
      name:'是否服药：',
      nameTip:'正在服药：',
      status:data.is_take_medicine,
      desc:data.drugs_name,
      infoType:1
    }
    ]
     if(data.sex==1){
        filter1=arr.filter((item)=>{
            return  item.type!="pregnant"
        });
     }else{
        filter1=arr;
     }
     if(!data.diagnosis_hospital){
        filter2=filter1.filter((item)=>{
            return  item.type!="hospital"
        });
     }else{
        filter2=filter1
     }
     let newarr=filter2.filter((item)=>{
       return  item.status!=null 
     });
     console.log(newarr)
     otherList.value=newarr;
},{immediate:true,deep:true})
// Akiraka 20230210 关闭弹窗
const handleClose = () => {
  emits('patientVisibleChange', (patientVisible.value = false));
  // Akiraka 20230210 关闭弹窗
  patientVisible.value = false;
  //otherList.value=[];
};
</script>
<style scoped>
.row{
  display: flex;
  line-height: 32px;
}
</style>