<template>
  <el-container>
    <el-header height="35px">
      <el-button type="primary" icon="el-icon-check" :disabled="submitDisabled" @click="submitPatientInfo"> 提交 </el-button>
      <el-button v-if="greatestRole < 3 || greatestRole === 8" type="primary" icon="el-icon-document-delete" @click="revoke">撤销 </el-button>
      <el-dropdown style="margin-left: 10px" trigger="click" @command="beforeReadCard">
        <el-button type="primary">读卡<i class="el-icon-arrow-down el-icon--right"></i> </el-button>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item icon="el-icon-bank-card" command="sicard">社保卡</el-dropdown-item>
            <el-dropdown-item icon="el-icon-s-grid" command="qrcode">二维码</el-dropdown-item>
            <el-dropdown-item icon="el-icon-user" command="idcard">身份证</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
      &nbsp;
      <el-button type="success" icon="el-icon-bottom" @click="beforeCancelRegister">取消入院登记</el-button>
      <el-button type="success" icon="el-icon-s-claim" @click="xiangMuLuRuRouter">项目录入</el-button>
      <el-button type="danger" icon="el-icon-warning" @click="yiZhuTuiFeiClick" v-if="greatestRole < 8">医嘱退费</el-button>
    </el-header>
    <el-main>
      <div>
        <el-tag type="info">病人基本信息（*病人基本信息可以修改提交医保部门审核*）</el-tag>
        <div style="height: 4px"></div>
        <el-row>
          <el-col :span="2" style="text-align: right">住院号：</el-col>
          <el-col :span="4"><el-input v-model="patient.inpatientNo"></el-input></el-col>
          <el-col :span="2" style="text-align: right">住院次数：</el-col>
          <el-col :span="4"><el-input v-model="patient.admissTimes"></el-input></el-col>
          <el-col :span="2" style="text-align: right">身份证号：</el-col>
          <el-col :span="4"><el-input v-model="patient.socialNo"></el-input></el-col>
          <el-col :span="2" style="text-align: right">出生日期：</el-col>
          <el-col :span="4"><el-input v-model="patient.birthDate"></el-input></el-col>
        </el-row>
        <el-row>
          <el-col :span="2" style="text-align: right">姓名：</el-col>
          <el-col :span="4"><el-input v-model="patient.name"></el-input></el-col>
          <el-col :span="2" style="text-align: right">性别：</el-col>
          <el-col :span="4">
            <el-select v-model="patient.sex" placeholder="请选择">
              <el-option v-for="item in sexes" :key="item.code" :label="item.name" :value="item.code"> </el-option>
            </el-select>
          </el-col>
          <el-col :span="2" style="text-align: right">联系电话：</el-col>
          <el-col :span="4"><el-input v-model="patient.homeTel"></el-input></el-col>
          <el-col :span="2" style="text-align: right">入院日期：</el-col>
          <el-col :span="4"><el-input v-model="patient.admissDate" disabled></el-input></el-col>
        </el-row>
        <el-row>
          <el-col :span="2" style="text-align: right">管床医生：</el-col>
          <el-col :span="4">
            <el-autocomplete v-model="patient.referPhysicianName" :fetch-suggestions="searchPhysician" placeholder="请输入内容" clearable @select="handleSelectPhysician">
              <template #default="{ item }">
                <span style="color: #8492a6; font-size: 12px">{{ item.code }}</span>
                <el-divider direction="vertical"></el-divider>
                <span>{{ item.name }}</span>
              </template>
            </el-autocomplete>
          </el-col>
          <el-col :span="2" style="text-align: right">病区：</el-col>
          <el-col :span="4"><el-input v-model="patient.admissWardName" disabled></el-input></el-col>
          <el-col :span="2" style="text-align: right">入院医生：</el-col>
          <el-col :span="4"><el-input v-model="patient.admissPhysicianName" disabled></el-input></el-col>
          <el-col :span="2" style="text-align: right">入院诊断：</el-col>
          <el-col :span="4"><el-input v-model="patient.admissDiagStr" disabled></el-input></el-col>
        </el-row>
        <el-row>
          <el-col :span="2" style="text-align: right">小科室：</el-col>
          <el-col :span="4"><el-input v-model="patient.smallDeptName" disabled></el-input></el-col>
          <el-col :span="2" style="text-align: right">登记日期：</el-col>
          <el-col :span="4">
            <el-date-picker v-model="patient.ybRegisterDate" type="datetime" placeholder="选择日期时间" @change="formatYbRegisterDate"></el-date-picker>
          </el-col>
          <el-col :span="2" style="text-align: right">参保地区：</el-col>
          <el-col :span="4">
            <el-select v-model="patient.admdvs" placeholder="请选择" filterable>
              <el-option v-for="item in admdvs" :key="item.code" :label="item.name" :value="item.code">
                <span style="color: #8492a6; font-size: 12px">{{ item.code }}</span>
                <el-divider direction="vertical"></el-divider>
                <span>{{ item.name }}</span>
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="2" style="text-align: right">医疗类别：</el-col>
          <el-col :span="4">
            <el-select v-model="patient.medType" placeholder="请选择" @change="handleSelectMedType">
              <el-option v-for="item in medTypes" :key="item.code" :label="item.name" :value="item.code" :disabled="item.disabled">
                <span style="color: #8492a6; font-size: 12px">{{ item.code }}</span>
                <el-divider direction="vertical"></el-divider>
                <span>{{ item.name }}</span>
              </el-option>
            </el-select>
          </el-col>
        </el-row>
      </div>
      <div style="height: 16px"></div>
      <div class="his-info">
        <div>
          <el-tag type="info"> 医保入院诊断（*自费患者无需填写*） </el-tag>
          <el-button type="primary" icon="el-icon-plus" circle @click="openDiagDialog" title="添加入院诊断"></el-button>
          <el-button type="success" icon="el-icon-check" circle :disabled="zyInYbDiags.length === 0" @click="saveYbDiags" title="保存入院诊断"></el-button>
        </div>
        <div>
          <div style="height: 8px"></div>
          <el-table :data="zyInYbDiags" height="160" stripe>
            <el-table-column prop="diagNo" label="诊断序号"></el-table-column>
            <el-table-column prop="property" label="诊断属性"></el-table-column>
            <el-table-column prop="icdCode" label="诊断编码"></el-table-column>
            <el-table-column prop="icdText" label="诊断名称"></el-table-column>
            <el-table-column label="诊断类别">
              <template #default="scope">
                {{ getDiagTypeName(scope.row.diagType) }}
              </template>
            </el-table-column>
            <el-table-column prop="opDate" label="诊断时间"></el-table-column>
            <el-table-column label="操作">
              <template #default="scope">
                <el-button type="danger" icon="el-icon-delete" circle @click="deleteYbDiag(scope.$index)"></el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div style="height: 16px"></div>
      <div>
        <div>
          <el-row :gutter="5">
            <el-col :span="10">
              <el-tag type="info">科室备注信息：</el-tag>
              <el-input type="textarea" rows="3" placeholder="请输入内容" v-model="patient.remark"> </el-input>
            </el-col>
            <el-col :span="10">
              <el-tag type="info">医保审核信息：</el-tag>
              <el-input type="textarea" rows="3" v-model="patient.ybRemark"> </el-input>
            </el-col>
          </el-row>
        </div>
        <div style="margin-top: 8px; padding: 8px 20px">
          录入人：
          <el-input v-model="patient.inputName" readonly style="width: 120px"> </el-input>
          &nbsp;&nbsp; 录入时间：
          <el-input v-model="patient.inputDate" readonly style="width: 160px"> </el-input>
          &nbsp;&nbsp; 审核人：
          <el-input readonly v-model="patient.passName" style="width: 120px"></el-input>
          &nbsp;&nbsp; 审核时间：
          <el-input readonly v-model="patient.passDate" style="width: 160px"></el-input>
        </div>
        <el-dialog title="医保入院诊断" v-model="showSearchDiag" width="360px" :close-on-click-modal="false">
          <div style="margin-top: 8px">
            诊断名称：
            <el-autocomplete
              v-model="diagItem.icdText"
              :fetch-suggestions="searchDiag"
              placeholder="请输入内容"
              clearable
              @select="handleSelectDiag"
              style="width: 220px"
              :disabled="!patient.inpatientNo"
            >
              <template #default="{ item }">
                <div style="height: 40px">
                  <div style="height: 16px; margin-top: 4px; font-size: 12px; color: #8492a6">
                    {{ item.code }}
                  </div>
                  <div style="height: 16px">{{ item.name }}</div>
                </div>
              </template>
            </el-autocomplete>
          </div>
          <div style="margin-top: 8px">
            诊断编码：
            <el-input v-model="diagItem.icdCode" disabled style="width: 220px"></el-input>
          </div>
          <div style="margin-top: 8px">
            诊断类别：
            <el-select v-model="diagItem.diagType" style="width: 220px">
              <el-option v-for="item in diagTypes" :key="item.code" :value="item.code" :label="item.name"></el-option>
            </el-select>
          </div>
          <div style="margin-top: 8px; width: 100%; text-align: right; padding: 8px 20px 8px 0">
            <el-button type="primary" icon="el-icon-check" @click="pushSiZyInDiag">确定</el-button>
          </div>
        </el-dialog>
      </div>
    </el-main>
    <el-dialog v-model="openXmlr" title="项目录入" :fullscreen="true" @close="closeXiangMuLuRuDialog">
      <Xmlr :init="initProp" @closeXmlr="openXmlr = false" />
    </el-dialog>
    <el-dialog v-model="openYiZhuTuiFei" title="医嘱退费" :fullscreen="true">
      <YiZhuTuiFei :initYiZhu="initYiZhu" @closeYiZhuTuiFei="openYiZhuTuiFei = false" />
    </el-dialog>
    <el-dialog v-model="showSearchSpecialDiag" title="医保入院诊断录入" width="80%" :close-on-click-modal="false">
      <div v-if="patient.medType === '2102'" style="margin-top: -30px; margin-bottom: 12px">
        <el-radio-group v-model="singleDiseaseType" @change="singleDiseaseTypeChanged">
          <el-radio label="2102">职工单病种</el-radio>
          <el-radio label="2102-residents">居民单病种</el-radio>
        </el-radio-group>
      </div>
      <el-row :gutter="5">
        <el-col :span="18">
          <el-tag>可选诊断</el-tag>&nbsp;&nbsp;
          <el-input placeholder="请输入诊断名称" v-model="specialDiagName" style="width: 260px" clearable></el-input>
          <span v-if="patient.medType === '52'">
            <el-select v-model="patient.matnType" placeholder="请选择生育类别" style="width: 120px">
              <el-option v-for="item in matnTypes" :value="item.code" :label="item.name" :key="item.code"></el-option>
            </el-select>
            &nbsp;&nbsp; 是否晚育：
            <el-radio-group v-model="patient.latechbFlag">
              <el-radio label="0">否</el-radio>
              <el-radio label="1">是</el-radio>
            </el-radio-group>
            &nbsp;&nbsp; 是否早产：
            <el-radio-group v-model="patient.pretFlag">
              <el-radio label="0">否</el-radio>
              <el-radio label="1">是</el-radio>
            </el-radio-group>
          </span>
          <el-table :data="cptSpecialDiags.slice((currentPage - 1) * 10, currentPage * 10)" stripe highlight-current-row height="400">
            <el-table-column prop="oldCode" label="老系统编码"></el-table-column>
            <el-table-column prop="oldName" label="老系统名称"></el-table-column>
            <el-table-column prop="newCode" label="新系统编码"></el-table-column>
            <el-table-column prop="newName" label="新系统名称"></el-table-column>
            <el-table-column prop="limitWay" label="限额方式"></el-table-column>
            <el-table-column prop="limitAmountCalculateWay" label="限额额度计算方式"></el-table-column>
            <el-table-column prop="limitAmount" label="疾病限额"></el-table-column>
            <el-table-column prop="reimbursementRate" label="报销比例"></el-table-column>
            <el-table-column>
              <template #default="scope">
                <el-button type="primary" @click="addSpecialDiag(scope.row)">{{ addDiagButtonText }}</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            page-size="10"
            layout="total, prev, pager, next, jumper"
            :total="cptSpecialDiags.length"
            style="margin-top: 5px"
          ></el-pagination>
        </el-col>
        <el-col :span="6">
          <el-tag>已选诊断</el-tag>&nbsp;&nbsp;
          <el-button type="success" icon="el-icon-check" :disabled="zyInYbDiags.length === 0" @click="saveYbDiags">保存入院诊断</el-button>
          <el-table stripe :data="zyInYbDiags" height="400">
            <el-table-column prop="icdCode" label="诊断编码"></el-table-column>
            <el-table-column prop="icdText" label="诊断名称"></el-table-column>
            <el-table-column>
              <template #default="scope">
                <el-button type="danger" icon="el-icon-delete" @click="deleteYbDiag(scope.$index)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
    </el-dialog>
  </el-container>
</template>

<script>
import { computed, onActivated, onDeactivated, onMounted, ref, watchEffect } from 'vue'
import { getCancelRegisterRequests, submitCancelRegisterRequest, revokeYbsf, submitSiPatientInfo, getZyInYbDiags, saveZyInYbDiags } from '@/api/yibao/patient'
import { searchData, getAllSpecialDiags } from '@/api/yibao/dictionary'
import store from '@/store'
import { cptSex } from '@/utils/computed'
import { sexes, admdvs } from '@/data/index'
import { nullPatient } from '@/utils/validate'
import { ElMessage, ElMessageBox } from 'element-plus'
import { revokeAdmission } from '@/api/medical-insurance/si-inpatient'
import { prepareReadCard } from '@/utils/readcard'
import { formatDatetime, getDatetime } from '@/utils/date'
import { getGreatestRole } from '@/utils/permission'
import { clone } from '@/utils/clone'
import { cancelInjuryRegister } from '@/api/medical-insurance/si-injury'
import { getDiagTypes, getMedTypesByFlag, getMatnTypes } from '@/api/medical-insurance/si-dict'
import { baseinfo } from '@/data/inpatient'
import Xmlr from '@/components/inpatient/XiangMuLuRu.vue'
import YiZhuTuiFei from '@/components/inpatient/YiZhuTuiFei.vue'
export default {
  components: {
    Xmlr,
    YiZhuTuiFei,
  },
  setup() {
    const greatestRole = getGreatestRole()
    const patient = computed(() => {
      return baseinfo()
    })
    const fetchZyYbDiags = () => {
      if (nullPatient()) return
      getZyInYbDiags(patient.value.inpatientNo, patient.value.admissTimes).then((res) => {
        zyInYbDiags.value = res
      })
    }

    const actived = ref(false)

    onActivated(() => {
      actived.value = true
    })

    onDeactivated(() => {
      actived.value = false
    })

    watchEffect(() => {
      if (actived.value) {
        if (patient.value.inpatientNo) {
          fetchZyYbDiags()
        }
      }
    })

    const submitDisabled = computed(() => {
      return patient.value.statusFlag === '1' || patient.value.statusFlag === '2'
    })

    const medTypes = ref([])
    const diagItem = ref({})
    const showSearchDiag = ref(false)
    const showSearchSpecialDiag = ref(false)
    const insuinfo = ref([])
    const showInsuinfo = ref(false)
    const zyInYbDiags = ref([])
    const diagTypes = ref([])
    const singleDiseaseType = ref('2102')
    const addDiagButtonText = computed(() => {
      return zyInYbDiags.value.length === 0 ? '添加为主诊断' : '添加为副诊断'
    })
    const specialDiags = ref([])
    const specialDiagName = ref('')
    const cptSpecialDiags = computed(() => {
      return specialDiags.value.filter((item) => {
        return (item.oldName + '' + item.newName).indexOf(specialDiagName.value) !== -1
      })
    })
    const matnTypes = ref([])

    const singleDiseaseTypeChanged = (val) => {
      zyInYbDiags.value = []
      diagItem.value = {}
      getAllSpecialDiags(val).then((res) => {
        specialDiags.value = res
      })
    }

    const openDiagDialog = () => {
      if (nullPatient()) {
        return
      }
      if (!patient.value.medType) {
        ElMessage({
          message: '请先选择医疗类别！',
          type: 'warning',
          duration: 2500,
          showClose: true,
        })
        return
      }
      diagItem.value.icdCode = null
      diagItem.value.icdText = null
      if (patient.value.medType === '52' || patient.value.medType === '2102') {
        if (patient.value.medType === '52') {
          getMatnTypes().then((res) => {
            matnTypes.value = res
          })
        }
        getAllSpecialDiags(patient.value.medType).then((res) => {
          specialDiags.value = res
          showSearchSpecialDiag.value = true
        })
      } else {
        showSearchDiag.value = true
      }
    }

    const pushSiZyInDiag = () => {
      if (!diagItem.value.icdCode) {
        ElMessage({
          message: '请选择具体诊断！',
          type: 'warning',
          duration: 2000,
          showClose: true,
        })
        return
      }
      if (!diagItem.value.diagType) {
        ElMessage({
          message: '请选择诊断类别！',
          type: 'warning',
          duration: 2000,
          showClose: true,
        })
        return
      }
      diagItem.value.property = zyInYbDiags.value.length === 0 ? '主要诊断' : '次要诊断'
      diagItem.value.diagNo = zyInYbDiags.value.length + 1
      diagItem.value.opDate = getDatetime()
      zyInYbDiags.value.push(clone(diagItem.value))
      showSearchDiag.value = false
    }

    const addSpecialDiag = (row) => {
      for (let i = 0; i < zyInYbDiags.value.length; i++) {
        if (zyInYbDiags.value[i].id === row.id) {
          ElMessage({
            message: '请勿添加重复诊断！',
            type: 'warning',
            duration: 2000,
            showClose: true,
          })
          return
        }
      }
      diagItem.value.id = row.id
      diagItem.value.diagType = '1'
      diagItem.value.icdCode = row.newCode ? row.newCode : row.oldCode
      diagItem.value.icdText = row.newName ? row.newName : row.oldName
      diagItem.value.property = zyInYbDiags.value.length === 0 ? '主要诊断' : '次要诊断'
      diagItem.value.diagNo = zyInYbDiags.value.length + 1
      diagItem.value.opDate = getDatetime()
      zyInYbDiags.value.push(clone(diagItem.value))
    }

    const getDiagTypeName = (val) => {
      for (let i = 0; i < diagTypes.value.length; i++) {
        if (diagTypes.value[i].code === val) {
          return diagTypes.value[i].name
        }
      }
    }

    const deleteYbDiag = (index) => {
      zyInYbDiags.value.splice(index, 1)
      for (let i = 0; i < zyInYbDiags.value.length; i++) {
        const element = zyInYbDiags.value[i]
        element.diagNo = i + 1
        if (i === 0) {
          element.property = '主要诊断'
        }
      }
    }

    const saveYbDiags = () => {
      if (patient.value.medType === '52' && !patient.value.matnType) {
        ElMessage({
          message: '请选择生育类别！',
          type: 'warning',
          duration: 2500,
          showClose: true,
        })
        return
      }
      const param = {
        inpatientNo: patient.value.inpatientNo,
        admissTimes: patient.value.admissTimes,
        diags: zyInYbDiags.value,
      }
      saveZyInYbDiags(param).then(() => {
        ElMessage({
          message: '医保入院诊断保存成功。',
          type: 'success',
          duration: 2500,
          showClose: true,
        })
        showSearchSpecialDiag.value = false
      })
    }

    const handleSelectMedType = (val) => {
      store.commit('ptnt/setInjuryMode', val === '42')
    }

    const submitPatientInfo = () => {
      if (nullPatient()) return
      let message = null
      if (!patient.value.remark) {
        message = '请输入科室备注信息！'
      } else if (zyInYbDiags.value.length === 0) {
        message = '医保入院诊断不能为空！'
      } else if (!patient.value.medType) {
        message = '请选择医疗类别！'
      } else if (!patient.value.admdvs) {
        message = '请选择患者参保地区！'
      }
      if (message) {
        ElMessage({
          message: message,
          type: 'error',
          duration: 2500,
          showClose: true,
        })
      } else {
        ElMessageBox.confirm('确定提交？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          submitSiPatientInfo({ patient: patient.value, diags: zyInYbDiags.value }).then(() => {
            ElMessage({
              message: '提交患者基本成功。',
              type: 'success',
              duration: 2500,
              showClose: true,
            })
            const overview = clone(store.state.ptnt.overview)
            patient.value.statusFlag = overview.status = '1'
          })
        })
      }
    }

    const searchMethod = computed(() => {
      return store.state.ptnt.searchMethod
    })

    const searchPhysician = (queryString, cb) => {
      if (queryString && queryString.length > 1) {
        const param = {
          method: searchMethod.value,
          content: queryString,
          target: 'physician',
          medType: patient.value.medType,
        }
        searchData(param).then((res) => {
          cb(res)
        })
      }
    }
    const handleSelectPhysician = (item) => {
      patient.value.referPhysician = item.code
      patient.value.referPhysicianName = item.name
    }

    const injuryMode = computed(() => {
      return store.state.ptnt.injuryMode
    })
    const searchDiag = (queryString, cb) => {
      if (queryString && queryString.length > 1) {
        const param = {
          method: searchMethod.value,
          content: queryString,
          target: injuryMode.value ? 'injurydiag' : 'diag',
          medType: patient.value.medType,
        }
        searchData(param).then((res) => {
          cb(res)
        })
      }
    }
    const handleSelectDiag = (item) => {
      diagItem.value.icdCode = item.code
      diagItem.value.icdText = item.name
    }

    const revoke = () => {
      if (nullPatient()) return
      ElMessageBox.confirm('是否撤销此患者的医保身份审核？(请勿对已成功进行医保入院登记的患者作此操作！)', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          revokeYbsf(patient.value.inpatientNo, patient.value.admissTimes).then(() => {
            ElMessage({
              message: '撤销成功。',
              type: 'success',
              duration: 2500,
              showClose: true,
            })
            const overview = store.state.ptnt.overview
            patient.value.statusFlag = overview.status = ''
          })
        })
        .catch(() => {})
    }

    const beforeReadCard = (val) => {
      if (nullPatient()) return
      prepareReadCard(val, patient.value.inpatientNo, '01103')
    }

    const formatYbRegisterDate = () => {
      patient.value.ybRegisterDate = formatDatetime(patient.value.ybRegisterDate)
    }

    const beforeCancelRegister = () => {
      if (nullPatient()) return
      getCancelRegisterRequests(patient.value.inpatientNo, patient.value.admissTimes, 1).then((res) => {
        if (res.length > 0) {
          const req = res[res.length - 1]
          if (req.statusFlag === 2) {
            // 审核通过
            if (injuryMode.value) {
              cancelInjuryRegister(patient.value).then(() => {
                ElMessageBox.alert('取消入院登记成功。', '提示', {
                  type: 'success',
                })
              })
            } else {
              revokeAdmission(patient.value).then(() => {
                ElMessageBox.alert('取消入院登记成功。', '提示', {
                  type: 'success',
                })
              })
            }
          } else if (req.statusFlag === 1) {
            ElMessage({
              message: '医保科尚未处理您的请求，请耐心等待医保科审核结果。',
              type: 'warning',
              duration: 2500,
              showClose: true,
            })
          } else {
            ElMessageBox.confirm(req.ybRemark, '审核不通过，请重新提交请求。', {
              type: 'error',
              confirmButtonText: '确定',
              cancelButtonText: '取消',
            })
              .then(() => inputBox())
              .catch(() => {})
          }
        } else {
          inputBox()
        }
      })
    }
    const inputBox = () => {
      ElMessageBox.prompt('请输入取消医保登记理由，以提交医保科审核。', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      })
        .then(({ value }) => {
          const indata = {
            inpatientNo: patient.value.inpatientNo,
            admissTimes: patient.value.admissTimes,
            name: patient.value.name,
            sex: patient.value.sex,
            remark: value,
            inputName: store.state.user.info.name,
            requestType: 1,
          }
          submitCancelRegisterRequest(indata).then(() => {
            ElMessage({
              message: '提交成功。',
              type: 'success',
              duration: 2500,
              showClose: true,
            })
          })
        })
        .catch(() => {})
    }

    // 项目录入
    const openXmlr = ref(false)
    const initProp = ref(0)
    const xiangMuLuRuRouter = () => {
      initProp.value += 1
      openXmlr.value = true
    }
    const closeXiangMuLuRuDialog = () => {
      openXmlr.value = false
    }

    // 医嘱退费
    const initYiZhu = ref(0)
    const openYiZhuTuiFei = ref(false)
    const yiZhuTuiFeiClick = () => {
      if (nullPatient()) return
      initYiZhu.value += 1
      openYiZhuTuiFei.value = true
    }

    const currentPage = ref(1)
    const handleCurrentChange = (val) => {
      currentPage.value = val
    }

    onMounted(() => {
      getMedTypesByFlag('hospitalization').then((res) => {
        medTypes.value = res
      })
      getDiagTypes().then((res) => {
        diagTypes.value = res
      })
    })

    return {
      greatestRole,
      patient,
      submitDisabled,
      sexes,
      admdvs,
      medTypes,
      diagTypes,
      insuinfo,
      showInsuinfo,
      zyInYbDiags,
      showSearchDiag,
      showSearchSpecialDiag,
      diagItem,
      cptSex,
      openXmlr,
      initProp,
      openDiagDialog,
      fetchZyYbDiags,
      deleteYbDiag,
      saveYbDiags,
      pushSiZyInDiag,
      searchPhysician,
      handleSelectPhysician,
      searchDiag,
      getDiagTypeName,
      handleSelectDiag,
      submitPatientInfo,
      revoke,
      beforeReadCard,
      beforeCancelRegister,
      formatYbRegisterDate,
      xiangMuLuRuRouter,
      closeXiangMuLuRuDialog,
      yiZhuTuiFeiClick,
      openYiZhuTuiFei,
      initYiZhu,
      specialDiags,
      singleDiseaseType,
      singleDiseaseTypeChanged,
      addDiagButtonText,
      addSpecialDiag,
      specialDiagName,
      cptSpecialDiags,
      matnTypes,
      currentPage,
      handleCurrentChange,
      handleSelectMedType,
    }
  },
}
</script>

<style>
.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
.el-collapse-item__content {
  padding-bottom: 0;
}
.el-collapse-item__header {
  height: 30px;
  line-height: 30px;
}
.el-collapse-item__header,
.el-collapse-item__wrap {
  background-color: inherit;
}
.el-autocomplete-suggestion li {
  line-height: normal !important;
}
</style>
