<template>
  <!--  -->
  <el-dialog :title="title" v-model="openDiagnosisInformation" :width="`${style.watch}`">
    <el-form ref="patientDiagnosisRef" :model="form" :rules="rules" label-width="100px">
      <!-- 病人信息1 -->
      <el-row v-if="controlData[0].display" :gutter="20">
        <!-- 病人信息 -->
        <el-col v-if="controlData[0].data[0].display" :span="controlData[0].data[0].span">
          <!-- 患者信息 -->
          <el-col v-if="controlData[0].data[0].colList[0].display" :span="24">
            <!-- 1 学号  诊断类型 -->
            <el-row v-if="controlData[0].data[0].colList[0].rowList[0].display">
              <!-- 1 学号 col -->
              <el-col v-if="controlData[0].data[0].colList[0].rowList[0].colList[0].display" :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[0].colList[0].data[0]
                      .display
                  " label="学号/工号" prop="studentId">
                  <el-input :disabled="
                      controlData[0].data[0].colList[0].rowList[0].colList[0].data[0]
                        .prohibit
                    " v-model="form.studentId" placeholder="请输入学号/工号" @change="selectPatient()" />
                </el-form-item>
              </el-col>
              <!-- 1 诊断类型 col -->
              <el-col v-if="controlData[0].data[0].colList[0].rowList[0].colList[1].display" :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[0].colList[1].data[0]
                      .display
                  " label="诊断类型" prop="diagnosisType">
                  <el-select v-model="form.diagnosisType" placeholder="请选择诊断类型类型" :disabled="
                      controlData[0].data[0].colList[0].rowList[0].colList[1].data[0]
                        .prohibit
                    ">
                    <el-option v-for="dict in healthcare_os_diagnosis_type" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 2 姓名 就诊人类型 -->
            <el-row v-if="controlData[0].data[0].colList[0].rowList[1].display">
              <!-- 2 姓名 col -->
              <el-col v-if="controlData[0].data[0].colList[0].rowList[1].colList[0].display" :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[1].colList[0].data[0]
                      .display
                  " label="姓名" prop="name">
                  <el-input :disabled="
                      controlData[0].data[0].colList[0].rowList[1].colList[0].data[0]
                        .prohibit
                    " v-model="form.name" placeholder="请输入姓名" clearable />
                </el-form-item>
              </el-col>
              <!-- 2 就诊人类型 col -->
              <el-col v-if="controlData[0].data[0].colList[0].rowList[1].colList[1].display" :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[1].colList[1].data[0]
                      .display
                  " label="就诊人类型" prop="patientType">
                  <el-select :disabled="
                      controlData[0].data[0].colList[0].rowList[1].colList[1].data[0]
                        .prohibit
                    " v-model="form.patientType" placeholder="请选择就诊人类型">
                    <el-option v-for="dict in healthcare_os_patient_type" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 3 性别 年龄  -->
            <el-row v-if="controlData[0].data[0].colList[0].rowList[2].display">
              <!-- 3 性别 col  -->
              <el-col v-if="controlData[0].data[0].colList[0].rowList[2].colList[0].display" :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[2].colList[0].data[0]
                      .display
                  " label="性别" prop="gender">
                  <el-select :disabled="
                      controlData[0].data[0].colList[0].rowList[2].colList[0].data[0]
                        .prohibit
                    " v-model="form.gender" placeholder="请输入性别" clearable>
                    <el-option v-for="dict in sys_user_sex" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <!-- 3 年龄 col  -->
              <el-col v-if="controlData[0].data[0].colList[0].rowList[2].colList[1].display" :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[2].colList[1].data[0]
                      .display
                  " label="年龄" prop="age">
                  <el-input :disabled="
                      controlData[0].data[0].colList[0].rowList[2].colList[1].data[0]
                        .prohibit
                    " v-model="form.age" clearable placeholder="请输入年龄" />
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 4 专业 班级 -->
            <el-row v-if="
                controlData[0].data[0].colList[0].rowList[3].display ||
                form.patientType === 0
              ">
              <!-- 4 专业 col -->
              <el-col v-if="controlData[0].data[0].colList[0].rowList[3].colList[0].display" :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[3].colList[0].data[0]
                      .display
                  " label="专业" prop="major">
                  <el-input :disabled="
                      controlData[0].data[0].colList[0].rowList[3].colList[0].data[0]
                        .prohibit
                    " v-model="form.major" clearable placeholder="请输入专业" />
                </el-form-item>
              </el-col>
              <!-- 4 班级 col  -->
              <el-col v-if="controlData[0].data[0].colList[0].rowList[3].colList[1].display" :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[3].colList[1].data[0]
                      .display
                  " label="班级" prop="classInfo">
                  <el-input :disabled="
                      controlData[0].data[0].colList[0].rowList[3].colList[1].data[0]
                        .prohibit
                    " v-model="form.classInfo" clearable placeholder="请输入班级" />
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 5 电话  辅导员 部门 -->
            <el-row v-if="controlData[0].data[0].colList[0].rowList[4].display">
              <!--  5 电话 -->
              <el-col v-if="controlData[0].data[0].colList[0].rowList[4].colList[0].display" :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[4].colList[0].data[0]
                      .display
                  " label="电话" prop="phone">
                  <el-input :disabled="
                      controlData[0].data[0].colList[0].rowList[4].colList[0].data[0]
                        .prohibit
                    " v-model="form.phone" clearable placeholder="请输入电话" />
                </el-form-item>
              </el-col>
              <!-- 5   辅导员 -->
              <el-col v-if="
                  controlData[0].data[0].colList[0].rowList[4].colList[1].display ||
                  form.patientType === 0
                " :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[4].colList[1].data[0]
                      .display
                  " label="辅导员" prop="counselor">
                  <el-input v-model="form.counselor" clearable placeholder="请输入辅导员" :disabled="
                      controlData[0].data[0].colList[0].rowList[4].colList[1].data[0]
                        .prohibit
                    " />
                </el-form-item>
              </el-col>
              <!-- 5 部门 -->
              <el-col v-if="
                  controlData[0].data[0].colList[0].rowList[4].colList[2].display ||
                  form.patientType === 1 ||
                  form.patientType === 2
                " :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[4].colList[2].data[0]
                      .display
                  " label="部门" prop="counselor">
                  <el-input v-model="form.counselor" clearable placeholder="请输入部门" :disabled="
                      controlData[0].data[0].colList[0].rowList[4].colList[2].data[0]
                        .display
                    " />
                </el-form-item>
              </el-col>
            </el-row>
            <!--  6 是否医保  报销比率 -->
            <el-row v-if="controlData[0].data[0].colList[0].rowList[5].display">
              <!-- 6 是否医保 -->
              <el-col v-if="controlData[0].data[0].colList[0].rowList[5].colList[0].display" :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[5].colList[0].data[0]
                      .display
                  " label="是否医保" prop="isInsured">
                  <el-select :disabled="
                      controlData[0].data[0].colList[0].rowList[5].colList[0].data[0]
                        .prohibit
                    " v-model="form.isInsured" placeholder="是否医保" clearable>
                    <el-option v-for="dict in healthcare_os_insured" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <!-- 6  报销比率 -->
              <el-col v-if="controlData[0].data[0].colList[0].rowList[5].colList[1].display" :span="12">
                <el-form-item v-if="
                    controlData[0].data[0].colList[0].rowList[5].colList[1].data[0]
                      .display && form.isInsured == 0
                  " label="报销比率" prop="value">
                  <el-input :disabled="
                      controlData[0].data[0].colList[0].rowList[5].colList[1].data[0]
                        .prohibit
                    " @input="calculationWholeTotal()" v-model="form.value" clearable placeholder="请输入报销比率" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <!-- 主诉 -->
          <el-col v-if="controlData[0].data[0].colList[1].display" :span="24">
            <el-row v-if="controlData[0].data[0].colList[1].rowList[0].display">
              <el-col v-if="controlData[0].data[0].colList[1].rowList[0].colList[0].display">
                <el-form-item v-if="
                    controlData[0].data[0].colList[1].rowList[0].colList[0].data[0]
                      .display
                  " label="主诉" prop="chiefComplaint">
                  <el-input :disabled="
                      controlData[0].data[0].colList[1].rowList[0].colList[0].data[0]
                        .prohibit
                    " v-model="form.chiefComplaint" type="textarea" placeholder="请输入内容" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <!-- 现病史 -->
          <el-col v-if="controlData[0].data[0].colList[2].display" :span="24">
            <el-row v-if="controlData[0].data[0].colList[2].rowList[0].display">
              <el-col v-if="controlData[0].data[0].colList[2].rowList[0].colList[0].display">
                <el-form-item v-if="
                    controlData[0].data[0].colList[2].rowList[0].colList[0].data[0]
                      .display
                  " label="现病史" prop="presentIllness">
                  <el-input :disabled="
                      controlData[0].data[0].colList[2].rowList[0].colList[0].data[0]
                        .prohibit
                    " v-model="form.presentIllness" type="textarea" placeholder="请输入内容" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <!-- 既往史 -->
          <el-col v-if="controlData[0].data[0].colList[3].display" :span="24">
            <el-row v-if="controlData[0].data[0].colList[3].rowList[0].display">
              <el-col v-if="controlData[0].data[0].colList[3].rowList[0].colList[0].display">
                <el-form-item v-if="
                    controlData[0].data[0].colList[3].rowList[0].colList[0].data[0]
                      .display
                  " label="既往史" prop="pastHistory">
                  <el-input :disabled="
                      controlData[0].data[0].colList[3].rowList[0].colList[0].data[0]
                        .prohibit
                    " v-model="form.pastHistory" type="textarea" placeholder="请输入内容" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <!-- 诊断 -->
          <el-col v-if="controlData[0].data[0].colList[4].display" :span="24">
            <el-row v-if="controlData[0].data[0].colList[4].rowList[0].display">
              <el-col v-if="controlData[0].data[0].colList[4].rowList[0].colList[0].display">
                <el-form-item v-if="
                    controlData[0].data[0].colList[4].rowList[0].colList[0].data[0]
                      .display
                  " label="临床诊断" prop="diagnosis">
                  <el-input :disabled="
                      controlData[0].data[0].colList[4].rowList[0].colList[0].data[0]
                        .prohibit
                    " v-model="form.diagnosis" type="textarea" placeholder="请输入内容" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
          <!-- 医嘱事项 -->
          <el-col v-if="controlData[0].data[0].colList[5].display" :span="24">
            <el-row v-if="controlData[0].data[0].colList[5].rowList[0].display">
              <el-col v-if="controlData[0].data[0].colList[5].rowList[0].colList[0].display">
                <el-form-item v-if="
                    controlData[0].data[0].colList[5].rowList[0].colList[0].data[0]
                      .display
                  " label="医嘱事项" prop="medicalAdvice">
                  <el-input :disabled="
                      controlData[0].data[0].colList[5].rowList[0].colList[0].data[0]
                        .prohibit
                    " v-model="form.medicalAdvice" type="textarea" placeholder="请输入内容" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
        </el-col>
        <!-- 病人病历 -->
        <el-col v-if="controlData[0].data[1].display" :span="12"> </el-col>
      </el-row>
      <!-- 提示 处方详情 -->
      <el-row v-if="controlData[1].display">
        <el-divider content-position="center"> 处方详情</el-divider>
      </el-row>
      <!-- 新增处方 -->
      <el-row v-if="controlData[2].display" class="prescriptionAdd">
        <el-col :span="20">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="addPrescriptionButton()" v-hasPermi="['electronicPrescribing:prescription:add']">新增处方</el-button>
        </el-col>
      </el-row>
      <!-- 处方 -->
      <el-row v-if="controlData[3].display" v-for="(index, item) in form.prescriptionDetailsList" :key="item">
        <PrescriptionList
          :controlButton="controlButtonPrescriptionList"
          :controlData="controlDataPrescriptionList"
          v-model:prescriptionData="form.prescriptionDetailsList[item]"
          :isInsured="form.isInsured"
          :reimbursementRate="form.value"
        />
      </el-row>
      <!-- 汇总展示 -->
      <el-row>
        <el-col :span="24">
          <div style="text-align: right; margin-top: 20px; color: red">
            <span>
              应收金额：{{ form.isInsured === 0 ? patientPay : ceilPrice(totalPriceSum) }} 元
            </span>
            <span style="margin-left: 16px; color: #666">
              处方总金额：{{ ceilPrice(totalPriceSum) }} 元
            </span>
            <span v-if="form.isInsured === 0" style="margin-left: 16px; color: #333">
              预计报销：{{ Number(currentReimbursement).toFixed(2) }} 元
            </span>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button v-if="false" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="closeDialog()">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup name="DiagnosisInformation">
//
const { proxy } = getCurrentInstance()

// 价格向上取整到小数点后两位（进一法）
// 先缩放到整数避免浮点精度问题
function ceilPrice(value) {
  const num = Number(value)
  if (isNaN(num)) return '0.00'
  const scaled = Math.round(num * 10000)
  const cents = Math.ceil(scaled / 100)
  return (cents / 100).toFixed(2)
}

// 患者类型
const { healthcare_os_patient_type } = proxy.useDict('healthcare_os_patient_type')
// os_patient_type
const { healthcare_os_diagnosis_type } = proxy.useDict('healthcare_os_diagnosis_type')
// 医药包装单位
const { healthcare_packaging_unit } = proxy.useDict('healthcare_packaging_unit')
//
const { sys_user_sex } = proxy.useDict('sys_user_sex')
//
const { healthcare_dose_unit } = proxy.useDict('healthcare_dose_unit')
// healthcare_os_insured  是否 医保
const { healthcare_os_insured } = proxy.useDict('healthcare_os_insured')
// healthcare_os_diagnosis_status    诊断状态
const { healthcare_os_diagnosis_status } = proxy.useDict('healthcare_os_diagnosis_status')

// 系统 的 是否
const { sys_yes_no } = proxy.useDict('sys_yes_no')

// 打开 弹框
const openDiagnosisInformation = ref(false)
//
const form = ref({})

//
const checkId = ref(0)

const totalPriceSum = ref(0) //所有药品总价和
const currentReimbursement = ref(0)
const patientPay = ref(0)

//
const props = defineProps({
  // 标题
  title: {
    type: String,
    default: '诊断信息'
  },
  // 显示
  open: {
    type: Boolean
  },
  // 控制 弹框 宽
  style: {
    type: Object,
    default: () => ({
      watch: '50%'
    })
  },
  // 控制 框架 数据 的 信息
  controlData: {
    type: Array,
    default: () => [
      {
        id: 0,
        name: 'el-row',
        description: '病人信息1',
        display: true,
        // 控制 内置 的 col
        data: [
          {
            id: 0,
            name: 'el-col',
            description: '病人信息',
            display: true,
            span: 0,
            colList: [
              {
                id: 0,
                name: 'el-col',
                description: '患者信息',
                display: true,
                rowList: [
                  {
                    id: 0,
                    name: 'el-row',
                    description: '1 学号 诊断类型 ',
                    display: true,
                    colList: [
                      {
                        id: 0,
                        name: 'el-col',
                        description: '1 学号 col ',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: 'el-form-input > el-input',
                            description: '学号/工号',
                            display: true,
                            prohibit: false
                          }
                        ]
                      },
                      {
                        id: 1,
                        name: 'el-col',
                        description: '1 诊断类型 col',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '诊断类型',
                            display: true,
                            prohibit: false
                          }
                        ]
                      }
                    ]
                  },
                  {
                    id: 1,
                    name: 'el-row',
                    description: '2 姓名 就诊人类型 ',
                    display: true,
                    colList: [
                      {
                        id: 0,
                        name: 'el-col',
                        description: '2 姓名 col ',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: 'el-form-input > el-input',
                            description: '姓名',
                            display: true,
                            prohibit: false
                          }
                        ]
                      },
                      {
                        id: 1,
                        name: 'el-col',
                        description: '2 就诊人类型 col',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '就诊人类型',
                            display: true,
                            prohibit: false
                          }
                        ]
                      }
                    ]
                  },
                  {
                    id: 2,
                    name: 'el-row',
                    description: '3 性别 年龄 ',
                    display: true,
                    colList: [
                      {
                        id: 0,
                        name: 'el-col',
                        description: '3 性别 col ',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: 'el-form-input > el-input',
                            description: '性别',
                            display: true,
                            prohibit: false
                          }
                        ]
                      },
                      {
                        id: 1,
                        name: 'el-col',
                        description: '3 年龄 col',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '年龄',
                            display: true,
                            prohibit: false
                          }
                        ]
                      }
                    ]
                  },
                  {
                    id: 3,
                    name: 'el-row',
                    description: '4 专业 班级 ',
                    display: true,
                    colList: [
                      {
                        id: 0,
                        name: 'el-col',
                        description: '4 专业 col ',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: 'el-form-input > el-input',
                            description: '专业',
                            display: true,
                            prohibit: false
                          }
                        ]
                      },
                      {
                        id: 1,
                        name: 'el-col',
                        description: '4 班级 col',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '班级',
                            display: true,
                            prohibit: false
                          }
                        ]
                      }
                    ]
                  },
                  {
                    id: 4,
                    name: 'el-row',
                    description: '5 电话  辅导员 部门 ',
                    display: true,
                    colList: [
                      {
                        id: 0,
                        name: 'el-col',
                        description: '5 电话 col ',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: 'el-form-input > el-input',
                            description: '电话',
                            display: true,
                            prohibit: false
                          }
                        ]
                      },
                      {
                        id: 1,
                        name: 'el-col',
                        description: '5 辅导员 col',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '辅导员',
                            display: true,
                            prohibit: false
                          }
                        ]
                      },
                      {
                        id: 2,
                        name: 'el-col',
                        description: '5 部门 col',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '部门',
                            display: true,
                            prohibit: false
                          }
                        ]
                      }
                    ]
                  },
                  {
                    id: 5,
                    name: 'el-row',
                    description: '6 是否医保  报销比率 ',
                    display: true,
                    colList: [
                      {
                        id: 0,
                        name: 'el-col',
                        description: '6 是否医保 col ',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: 'el-form-input > el-input',
                            description: '是否医保',
                            display: true,
                            prohibit: false
                          }
                        ]
                      },
                      {
                        id: 1,
                        name: 'el-col',
                        description: '6 报销比率 col',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '报销比率',
                            display: true,
                            prohibit: false
                          }
                        ]
                      }
                    ]
                  }
                ]
              },
              {
                id: 1,
                name: 'el-col',
                description: '主诉',
                display: true,
                rowList: [
                  {
                    id: 0,
                    name: 'el-row',
                    description: 'el-col',
                    display: true,
                    colList: [
                      {
                        id: 0,
                        name: '主诉',
                        description: '',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '主诉',
                            display: true,
                            prohibit: false
                          }
                        ]
                      }
                    ]
                  }
                ]
              },
              {
                id: 2,
                name: 'el-col',
                description: '现病史',
                display: true,
                rowList: [
                  {
                    id: 0,
                    name: 'el-row',
                    description: 'el-col',
                    display: true,
                    colList: [
                      {
                        id: 0,
                        name: '现病史',
                        description: '',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '现病史',
                            display: true,
                            prohibit: false
                          }
                        ]
                      }
                    ]
                  }
                ]
              },
              {
                id: 3,
                name: 'el-col',
                description: '既往史',
                display: true,
                rowList: [
                  {
                    id: 0,
                    name: 'el-row',
                    description: 'el-col',
                    display: true,
                    colList: [
                      {
                        id: 0,
                        name: '既往史',
                        description: '',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '既往史',
                            display: true,
                            prohibit: false
                          }
                        ]
                      }
                    ]
                  }
                ]
              },
              {
                id: 4,
                name: 'el-col',
                description: '临床诊断',
                display: true,
                rowList: [
                  {
                    id: 0,
                    name: 'el-row',
                    description: 'el-col',
                    display: true,
                    colList: [
                      {
                        id: 0,
                        name: '临床诊断',
                        description: '',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '临床诊断',
                            display: true,
                            prohibit: false
                          }
                        ]
                      }
                    ]
                  }
                ]
              },
              {
                id: 5,
                name: 'el-col',
                description: '医嘱事项',
                display: true,
                rowList: [
                  {
                    id: 0,
                    name: 'el-row',
                    description: 'el-col',
                    display: true,
                    colList: [
                      {
                        id: 0,
                        name: '医嘱事项',
                        description: '',
                        display: true,
                        data: [
                          {
                            id: 0,
                            name: '医嘱事项',
                            display: true,
                            prohibit: false
                          }
                        ]
                      }
                    ]
                  }
                ]
              }
            ]
          },
          {
            id: 1,
            name: 'el-col',
            description: '病人病历',
            display: true,
            span: 0,
            rowList: []
          }
        ]
      },
      {
        id: 1,
        name: '',
        description: '提示 处方详情',
        display: true
      },
      {
        id: 2,
        name: '',
        description: '新增处方',
        display: true
      },
      {
        id: 3,
        name: '',
        description: '处方',
        display: true
      }
    ]
  }
})

//  子组件 处方列表 使用
import PrescriptionList from '@/components/Healthcare/OutpatientService/PrescriptionList/index.vue'
import prescriptionListUse from '@/components/Healthcare/OutpatientService/PrescriptionList/use.ts'

let { controlButtonPrescriptionList, controlDataPrescriptionList, modifyWholeCheckProp, modifyWholeProhibit, modifyWholeButtonDisplay } = prescriptionListUse()

// controlDataPrescriptionList.value[8].display = false;
controlDataPrescriptionList.value[11].display = false
// controlDataPrescriptionList.value[10].check[0].isCheck = false;
// controlDataPrescriptionList.value[1].pattern[0].isUse = false;
// controlDataPrescriptionList.value[1].pattern[2].isUse = true;
modifyWholeCheckProp(controlDataPrescriptionList.value, 'drugUseList')

// console.log('修改 数据', controlDataPrescriptionList.value)
modifyWholeProhibit(controlDataPrescriptionList.value, true)
modifyWholeButtonDisplay(controlButtonPrescriptionList.value, false)
// console.log('修改 数据', controlButtonPrescriptionList.value)

import { getPatientDiagnosis } from '@/api/healthcare/outpatientService/patientDiagnosis'

// 监听
watch(
  () => checkId.value,
  (newValue, oldValue) => {
    // console.log('获取id：2', newValue)
    //
    getPatientDiagnosis(newValue).then(response => {
      form.value = response.data
      // title.value = '患者诊断信息'
      // console.log('获取数据111111111111：', form.value)
      // 更新总价和
      totalPriceSum.value = ceilPrice(form.value.prescriptionDetailsList
        .reduce((sum, prescription) => {
          return sum + prescription.reduce((innerSum, drug) => innerSum + parseFloat(drug.totalPrice || 0), 0)
        }, 0))
      const insured = form.value?.isInsured
      const sumNum = Number(totalPriceSum.value || 0)
      if (insured === 0) {
        const rate = Number(form.value?.value || 0) / 100
        const r = isNaN(rate) ? 0 : rate
        // 先计算个人应付（向上取整）
        const pay = ceilPrice(sumNum * (1 - r))
        patientPay.value = pay
        // 预计报销 = 总价 - 个人应付
        currentReimbursement.value = (sumNum - Number(pay)).toFixed(2)
      } else {
        currentReimbursement.value = '0.00'
        patientPay.value = ceilPrice(sumNum)
      }
    })
  }
)

// 方法 控制 弹框 的 显示
const openDialog = id => {
  console.log('获取id：', id)

  checkId.value = id
  openDiagnosisInformation.value = true
}

// 方法 控制 弹框 的 隐藏
const closeDialog = () => {
  openDiagnosisInformation.value = false
}

// 可以 给 queryRef 组件 暴露 方法   父组件 可以 调用 子组件 的 方法
defineExpose({
  openDialog,
  closeDialog
})
</script>

<style scoped>
.prescriptionAdd {
  margin-bottom: 20px;
}
.prescription {
  margin-bottom: 20px;
}
/* .el-input {
  width: 100%;
} */
</style>
