<template>
  <el-container>
    <el-dialog v-model="huanZheXinXiDialog" fullscreen>
      <el-descriptions title="基本信息" border style="width: 100%" :column="4">
        <template #extra>
          <el-button type="info" @click="shenHeClick">审核信息</el-button>
          <el-button type="primary" size="small" @click="shuJuDuiBi">数据对比</el-button>
          <el-button type="success" size="small" @click="baoCunXiuGai">保存修改</el-button>
          <bei-zhu :data="baoCunXiuGaiData" ref="beiZhuRef" @baoCunHouGuanBi="baoCunHouGuanBi"></bei-zhu>
        </template>
        <el-descriptions-item label="姓名">
          {{ setlinfo.name }}
          <el-button @click="feiYongDrawer">{{ setlinfo.outDeptName }}</el-button>
          <ke-shi-fei-yong ref="keShiFeiYongRef"></ke-shi-fei-yong>
        </el-descriptions-item>
        <el-descriptions-item label="住院号">
          {{ setlinfo.inpatientNo }}
        </el-descriptions-item>
        <el-descriptions-item label="医保身份">
          {{ setlinfo.responceTypeName }}
        </el-descriptions-item>
        <el-descriptions-item label="性别">
          {{ cptSex(setlinfo.sex) }}
        </el-descriptions-item>
        <el-descriptions-item label="住院次数">
          {{ setlinfo.admissTimes }}
        </el-descriptions-item>
        <el-descriptions-item label="总费用">
          {{ setlinfo.medfeeSumamt }}
        </el-descriptions-item>
        <el-descriptions-item label="诊断编码">
          {{ setlinfo.disDiag }}
        </el-descriptions-item>
        <el-descriptions-item label="治疗方式">
          <el-select v-model="setlinfo.operation" filterable style="width: 220px;"
          >
            <el-option v-for="item in operations" :key="item.code" :value="item.code" :label="item.name">
              <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-descriptions-item>
        <el-descriptions-item label="住院天数">
          {{ setlinfo.actIptDays }}
        </el-descriptions-item>
        <el-descriptions-item label="报销金额">
          {{ setlinfo.fundPaySumamt }}
        </el-descriptions-item>
        <el-descriptions-item label="诊断名称">
          {{ setlinfo.disDiagComment }}
        </el-descriptions-item>
        <el-descriptions-item label="申报类型">
          <el-select v-model="setlinfo.decType" filterable style="width: 150px;"
          >
            <el-option v-for="item in decTypes" :key="item.code" :value="item.code" :label="item.name"
                       :disabled="item.dis">
              <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-descriptions-item>
        <el-descriptions-item label="审核" v-if="shenHeQuanXian()">
          <el-button type="success" :disabled="keFeiShenHe" @click="shenHeTongGuoClick">审核通过</el-button>
          <el-button type="success" :disabled="keFeiShenHe" @click="shenHeTongGuoShangChuanClick">审核通过并上传</el-button>
          <el-button type="danger" :disabled="keFeiShenHe" @click="shenHeBoHuiClick">审核驳回</el-button>
        </el-descriptions-item>
      </el-descriptions>
      <el-tag size="small">住院诊断信息</el-tag>
      <el-button type="success" icon="el-icon-circle-plus" @click="addZhenDuanClick">新增诊断</el-button>
      入院病情： 1.有，2.临床未确定，3.情况不明，4.无
      <el-table :data="diseinfo" :height="store.state.app.windowSize.h / 2.5" stripe highlight-current-row>
        <el-table-column label="诊断代码" prop="disDiag">
          <template #default="scope">
            <el-button type="text" @click="xiuGaiZhenDuanClick(scope.$index,scope.row)">{{
                scope.row.disDiag
              }}
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="诊断名称" prop="disDiagComment"></el-table-column>
        <el-table-column label="入院病情" prop="admissCond" width="90">
        </el-table-column>
        <el-table-column label="诊断类别" prop="siDiagTypeName">
          <template #default="scope">
            {{ getsiDiagTypeName(scope.row.siDiagType) }}
          </template>
        </el-table-column>
        <el-table-column label="诊断排序" prop="disDiagNo">
          <template #default="scope">
            {{ scope.row.disDiagNo }}
            &nbsp;&nbsp;&nbsp;
            <el-button type="primary" v-if="scope.row.disDiagNo !== 1"
                       @click="sheZhiZhuZhenDuan(scope.$index,scope.row.disDiagNo)">
              设为主诊断
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="删除">
          <template #default="scope">
            <el-popconfirm
                confirm-button-text="确认"
                cancel-button-text="取消"
                icon="el-icon-info"
                iconColor="#F56C6C"
                title="是否删除该诊断"
                @confirm="delZhenDuan(scope.$index,scope.row.disDiagNo)"
            >
              <template #reference>
                <el-button size="mini" type="danger" icon="el-icon-delete">删除</el-button>
              </template>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <el-tag size="small">手术操作信息</el-tag>
      <el-button type="success" icon="el-icon-circle-plus" @click="tianJiaXiuGaiShouShu(-1)">新增手术</el-button>
      <el-table :data="oprninfo" :height="store.state.app.windowSize.h / 2.5" stripe highlight-current-row>
        <el-table-column label="手术及操作名称" prop="ssmc">
          <template #default="scope">
            <el-button type="text" @click="tianJiaXiuGaiShouShu(scope.$index)">{{ scope.row.ssmc }}</el-button>
          </template>
        </el-table-column>
        <el-table-column label="手术及操作日期" prop="ssrq"></el-table-column>
        <el-table-column label="手术级别" prop="ssjb"></el-table-column>
        <el-table-column label="手术及操作编码	" prop="ssbm"></el-table-column>
        <el-table-column label="手术及操作医师">
          <el-table-column label="术者" prop="ssysName"></el-table-column>
          <el-table-column label="I助" prop="sszsName1"></el-table-column>
          <el-table-column label="II助" prop="sszsName2"></el-table-column>
        </el-table-column>
        <el-table-column label="切口愈合等级" prop="qkjb">
          <template #default="scope">
            {{ qieKouName(scope.row.qkjb, scope.row.yhqk) }}
          </template>
        </el-table-column>
        <el-table-column label="麻醉方式" prop="mzff">
          <template #default="scope">
            {{ maZuiName(scope.row.mzff) }}
          </template>
        </el-table-column>
        <el-table-column label="麻醉医师" prop="mzysName"></el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-popconfirm
                confirm-button-text="确认"
                cancel-button-text="取消"
                icon="el-icon-info"
                iconColor="#F56C6C"
                title="是否删除该手术"
                @confirm="delShouShu(scope.$index)"
            >
              <template #reference>
                <el-button size="mini" type="danger" icon="el-icon-delete">删除</el-button>
              </template>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog v-model="zhenDuanDialog" width="60%">
      <el-select v-model="zhenDuanQuery.method" filterable style="width: 100px;"
      >
        <el-option v-for="item in methods" :key="item.code" :value="item.code" :label="item.name">
          <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-input v-model="zhenDuanQuery.content" style="width: 120px" @keyup.enter="zhenDuanChaXunClick"
                clearable></el-input>
      <el-button type="primary" icon="el-icon-search" @click="zhenDuanChaXunClick">查询</el-button>
      诊断类别：
      <el-select v-model="lingShiZhenDuan.siDiagType"
                 style="width: 120px;"
      >
        <el-option v-for="item in siDiagTypes" :key="item.code" :value="item.code" :label="item.name">
          <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-select v-model="lingShiZhenDuan.admissCond"
                 style="width: 60px;"
      >
        <el-option v-for="item in admissCondData" :key="item.code" :value="item.code" :label="item.name">
          <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-table :data="queryZhenDuanData" height="450px"
                stripe highlight-current-row>
        <el-table-column label="编码" prop="code"></el-table-column>
        <el-table-column label="名称" prop="name"></el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-popconfirm
                v-if="addZhenDuanFlag"
                confirm-button-text="确认"
                cancel-button-text="取消"
                icon="el-icon-info"
                iconColor="#67C23A"
                title="是否添加该诊断"
                @confirm="addZhenDuan(scope.row)"
            >
              <template #reference>
                <el-button size="mini" type="success" icon="el-icon-circle-plus">新增</el-button>
              </template>
            </el-popconfirm>
            <el-popconfirm
                v-else
                confirm-button-text="确认"
                cancel-button-text="取消"
                icon="el-icon-info"
                iconColor="#E6A23C"
                title="是否修改为该诊断"
                @confirm="xuanZheZhenDuan(scope.row)"
            >
              <template #reference>
                <el-button size="mini" type="warning" icon="el-icon-edit">修改</el-button>
              </template>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>
      <br>
      <el-button @click="pageZhenDuanChaXun(zhenDuanQuery.page -= 1)" :disabled="zhenDuanQuery.page === 1">上一页
      </el-button>
      <el-button @click="pageZhenDuanChaXun(zhenDuanQuery.page += 1)">下一页</el-button>
    </el-dialog>
    <!--    这里都是手术的了  -->
    <el-dialog v-model="shouShuDialog" title="修改或添加手术">
      <el-form :model="formShouShu" label-width="100px" ref="formShouShuRef" size="mini" :rules="shouShuRules">
        <el-form-item prop="ssmc" label="手术名称">
          <el-input v-model="formShouShu.ssmc" @click="queryShouShu('手术编码')"></el-input>
        </el-form-item>
        <el-form-item prop="ssrq" label="手术日期">
          <el-date-picker type="datetime" v-model="formShouShu.ssrq"></el-date-picker>
        </el-form-item>
        <el-form-item prop="ssjb" label="手术级别">
          <el-select v-model="formShouShu.ssjb">
            <el-option :value="1" :key="1" :label="1"></el-option>
            <el-option :value="2" :key="2" :label="2"></el-option>
            <el-option :value="3" :key="3" :label="3"></el-option>
            <el-option :value="4" :key="4" :label="4"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="ssbm" label="手术编码">
          <el-input v-model="formShouShu.ssbm" disabled></el-input>
        </el-form-item>
        <el-form-item prop="ssysName" label="术者">
          <el-input v-model="formShouShu.ssysName" @click="queryShouShu('术者')"></el-input>
        </el-form-item>
        <el-form-item prop="sszsName1" label="I助">
          <el-input v-model="formShouShu.sszsName1" @click="queryShouShu('I助')"></el-input>
        </el-form-item>
        <el-form-item prop="sszsName2" label="II助">
          <el-input v-model="formShouShu.sszsName2" @click="queryShouShu('II助')"></el-input>
        </el-form-item>
        <el-form-item prop="qkName" label="切口愈合等级">
          <el-select v-model="formShouShu.qkName" @change="formQieKou">
            <el-option v-for="item in qks" :key="item.code" :value="item.code" :label="item.name">
              <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-form-item>
        <el-form-item prop="mzff" label="麻醉方式">
          <el-select v-model="formShouShu.mzff">
            <el-option v-for="item in maZuiFangShis" :key="item.code" :value="item.code" :label="item.name">
              <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-form-item>
        <el-form-item prop="mzys" label="麻醉医生">
          <el-input v-model="formShouShu.mzysName" @click="queryShouShu('麻醉医生')"></el-input>
        </el-form-item>
      </el-form>
      <el-button @click="shouShuBaoCunClick">保存</el-button>
    </el-dialog>
    <el-dialog v-model="queryShouShuDialog" :title="queryShouShuCodeName">
      {{ queryShouShuCodeName }} ：
      <el-input v-model="queryShouShuCodeData.code" style="width: 120px;" @keyup.enter="queryShouShuClick"></el-input>
      <el-button type="primary" @click="queryShouShuClick">查询</el-button>
      <el-table :data="shouShuData">
        <el-table-column label="编码" prop="code"></el-table-column>
        <el-table-column label="名称" prop="name"></el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button @click="xuanZheShouShu(scope.row)">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          layout="total,  prev, pager, next"
          :total="queryShouShuCodeData.total"
          @current-change="shouShuCurrentPage"
      >
      </el-pagination>
    </el-dialog>
    <shu-ju-dui-bi ref="shuJuDuiBiDialogRef"
                   :oldYbZyDisDiag="props.data.ybZyDisDiag"
                   :newYbZyDisDiag="props.data.newYbZyDisDiag"
                   :oldBat="props.data.batjBa4"
                   :new-bat="props.data.newBatjBa4"></shu-ju-dui-bi>
    <shen-he-xin-xi :data="props.data.shenHeXinXi" ref="shenHeRef"></shen-he-xin-xi>
  </el-container>
</template>

<script>
import {watch, ref, unref} from "vue";
import store from '@/store'
import {cptSex} from "../../utils/computed";
import {searchYbDiag} from "../../api/yibao/dictionary";
import {operations, decTypes} from '../../data'
import {clone} from "../../utils/clone";
import {ElMessage, ElMessageBox} from "element-plus";
import {getRenYuan} from "../../api/public-api";
import {setlModifyReq, setlUploadAudit, shouShuBianMa, upldSetlList} from "../../api/medical-insurance/si-setl-upload";
import {formatDatetime} from "../../utils/date";
import {listIsBlank, listNotBlank, stringIsBlank} from "../../utils/blank-utils";
import ShuJuDuiBi from "./ShuJuDuiBi.vue"
import {getsiDiagTypeName, maZuiFangShis, maZuiName, qieKouName, qks, shenHeQuanXian} from "./jieSuanDanXiuGai";
import ShenHeXinXi from "./ShenHeXinXi.vue";
import KeShiFeiYong from "./KeShiFeiYong.vue";
import BeiZhu from "./BeiZhu.vue";

export default {
  name: "JieSuanDanXiangQing",
  components: {BeiZhu, KeShiFeiYong, ShenHeXinXi, ShuJuDuiBi},
  props: {
    data: {}
  },
  setup(props, ctx) {
    // 基本信息
    const setlinfo = ref({})
    // 住院诊断信息
    const diseinfo = ref([])
    // 手术操作信息
    const oprninfo = ref([])
    const huanZheXinXiDialog = ref(false)

    const code = store.state.user.info.code
    const name = store.state.user.info.name

    const openDialog = (val) => {
      huanZheXinXiDialog.value = val
    }
    /*以下全部都是诊断*/
    const zhenDuanQuery = ref({
      method: 'alpha',
      target: 'diag',
      // 内容
      content: '',
      medType: '',
      // 当前页
      page: 1
    })
    const lingShiZhenDuan = ref({
      disDiag: '',
      disDiagComment: '',
      admissCond: '',
      siDiagType: ''
    })

    const zhenDuanDialog = ref(false)
    const addZhenDuanFlag = ref(false)
    let zhenDuanIndex = 0
    const xiuGaiZhenDuanClick = (index, val) => {
      lingShiZhenDuan.value = val
      addZhenDuanFlag.value = false
      zhenDuanDialog.value = true
      zhenDuanIndex = index
    }
    const queryZhenDuanData = ref([])
    const xuanZheZhenDuan = (val) => {
      if (zhenDuanTianJiaTiaoJian()) return
      diseinfo.value[zhenDuanIndex].disDiag = val.code
      diseinfo.value[zhenDuanIndex].disDiagComment = val.name
      setTimeout(() => {
        ElMessage({
          message: "修改成功",
          type: "success",
          showClose: true,
        })
        zhenDuanDialog.value = false
      }, 100)
    }
    const zhenDuanChaXunClick = () => {
      zhenDuanQuery.value.page = 1
      searchYbDiag(zhenDuanQuery.value).then((res) => {
        queryZhenDuanData.value = res
      })
    }
    const pageZhenDuanChaXun = (val) => {
      searchYbDiag(zhenDuanQuery.value).then((res) => {
        queryZhenDuanData.value = res
      })
    }

    const sheZhiZhuZhenDuan = (index, val) => {
      let data = []
      for (let item of diseinfo.value) {
        if (val !== item.disDiagNo) {
          data.push(item)
        }
      }
      data.unshift(diseinfo.value[index])
      for (let i = 0; i < data.length; i++) {
        data[i].disDiagNo = i + 1
      }
      diseinfo.value = data
    }

    const addZhenDuanClick = () => {
      lingShiZhenDuan.value = {
        disDiag: '',
        disDiagComment: '',
        admissCond: '',
        siDiagType: ''
      }
      queryZhenDuanData.value = []
      addZhenDuanFlag.value = true
      zhenDuanDialog.value = true
    }
    const addZhenDuan = (val) => {
      if (zhenDuanTianJiaTiaoJian()) return
      lingShiZhenDuan.value.disDiag = val.code
      lingShiZhenDuan.value.disDiagComment = val.name
      lingShiZhenDuan.value.disDiagNo = diseinfo.value.length + 1
      lingShiZhenDuan.value.newData = true
      diseinfo.value.push(lingShiZhenDuan.value)
      zhenDuanDialog.value = false
    }
    const delZhenDuan = (index, val) => {
      diseinfo.value.splice(index, 1)
      for (let i = 0; i < diseinfo.value.length; i++) {
        diseinfo.value[i].disDiagNo = i + 1
      }
    }

    function zhenDuanTianJiaTiaoJian() {
      if (stringIsBlank(lingShiZhenDuan.value.siDiagType)) {
        ElMessage.error("请先选择诊断类别")
        return true
      }
      if (stringIsBlank(lingShiZhenDuan.value.disDiagStatus)
          || lingShiZhenDuan.value.disDiagStatus === '0') {
        ElMessage.error("请先选择出院病情")
        return true
      }
      return false
    }

    /*诊断结束*/

    /*一下都是手术的*/
    const shouShuDialog = ref(false)
    const formShouShu = ref({
      ssmc: '',
      ssrq: '',
      ssjb: '',
      ssbm: '',
      ssys: '',
      ssysName: '',
      sszs1: '',
      sszsName1: '',
      sszs2: '',
      sszsName2: '',
      qkjb: '',
      yhqk: '',
      qkName: '',
      mzff: '',
      mzys: '',
      mzysName: '',
    })
    const formShouShuRef = ref(null)
    const formShouShuCz = ref({})
    formShouShuCz.value = clone(formShouShu.value)
    // 限制
    const shouShuRules = ref({
      ssmc: [{required: true, message: '该项不能为空', trigger: 'blur'}],
      ssrq: [{required: true, message: '该项不能为空', trigger: 'blur'}],
      ssjb: [{required: true, message: '该项不能为空', trigger: 'blur'}],
      ssbm: [{required: true, message: '该项不能为空', trigger: 'blur'}],
      ssysName: [{required: true, message: '该项不能为空', trigger: 'blur'}],
      sszsName1: [{required: true, message: '该项不能为空', trigger: 'blur'}],
      qkName: [{required: true, message: '该项不能为空', trigger: 'blur'}],
      mzff: [{required: true, message: '该项不能为空', trigger: 'blur'}],
      mzys: [{required: true, message: '该项不能为空', trigger: 'blur'}],
    })

    const oprninfoIndex = ref(-1)
    const tianJiaXiuGaiShouShu = (index) => {
      if (index !== -1) {
        formShouShu.value = clone(oprninfo.value[index])
      } else {
        formShouShu.value = clone(formShouShuCz.value)
      }
      oprninfoIndex.value = index
      shouShuDialog.value = true
    }

    const queryShouShuCodeData = ref({
      code: '',
      page: 1,
      total: 0
    })
    const queryShouShuCodeName = ref("手术编码")
    const queryShouShuDialog = ref(false)
    const shouShuData = ref([])
    const queryShouShu = (val) => {
      queryShouShuCodeName.value = val
      queryShouShuDialog.value = true
      queryShouShuCodeData.value.code = ''
      shouShuData.value = []
    }
    const queryShouShuClick = () => {
      if (queryShouShuCodeName.value.length < 1) {
        return
      }
      switch (queryShouShuCodeName.value) {
        case '手术编码':
          shouShuBianMa(queryShouShuCodeData.value.code, 1).then((res) => {
            shouShuData.value = res.records
            queryShouShuCodeData.value.total = res.total
          })
          return
        default:
          getRenYuan(queryShouShuCodeData.value.code).then((res) => {
            shouShuData.value = res
            queryShouShuCodeData.value.total = 0
          })
          return;
      }
    }

    const shouShuCurrentPage = (val) => {
      queryShouShuCodeData.value.page = val
      shouShuBianMa(queryShouShuCodeData.value.code, queryShouShuCodeData.value.page).then((res) => {
        shouShuData.value = res.records
        queryShouShuCodeData.value.total = res.total
      })
    }

    const xuanZheShouShu = (val) => {
      switch (queryShouShuCodeName.value) {
        case '手术编码':
          formShouShu.value.ssbm = val.code
          formShouShu.value.ssmc = val.name
          break;
        case '术者':
          formShouShu.value.ssys = val.code
          formShouShu.value.ssysName = val.name
          break;
        case 'I助':
          formShouShu.value.sszs1 = val.code
          formShouShu.value.sszsName1 = val.name
          break;
        case 'II助':
          formShouShu.value.sszs2 = val.code
          formShouShu.value.sszsName2 = val.name
          break;
        case '麻醉医生':
          formShouShu.value.mzys = val.code
          formShouShu.value.mzysName = val.name
          break;
      }
      setTimeout(() => {
        queryShouShuDialog.value = false
      }, 400)
    }

    const formQieKou = (val) => {
      formShouShu.value.qkjb = val.split('/')[0]
      formShouShu.value.yhqk = val.split('/')[1]
    }

    const shouShuBaoCunClick = async () => {
      let form = unref(formShouShuRef)
      if (!form) return
      try {
        await form.validate()
        formShouShu.value.ssrq = formatDatetime(formShouShu.value.ssrq)
        if (oprninfoIndex.value !== -1) {
          oprninfo.value[oprninfoIndex.value] = clone(formShouShu.value)
          console.log(oprninfo.value[oprninfoIndex.value])
        } else {
          formShouShu.value.newData = true
          oprninfo.value.push(clone(formShouShu.value))
        }
        shouShuDialog.value = false
      } catch (e) {
      }
    }

    const delShouShu = (index) => {
      oprninfo.value.splice(index, 1)
      ElMessage.success("删除成功。")
    }

    const baoCunXiuGaiData = ref({})
    const beiZhuRef = ref(null)
    const baoCunHouGuanBi = () => {
      huanZheXinXiDialog.value = false
      ctx.emit('shua-xin')
    }
    const baoCunXiuGai = () => {
      if ((setlinfo.value.operation === '1' || setlinfo.value.operation === '2' || setlinfo.value.operation === '3')) {
        if (listIsBlank(oprninfo.value)) {
          return ElMessage.error("选择治疗类型为手术的，至少要有一个手术。")
        }
      } else if (oprninfo.value.length > 5) {
        return ElMessage.error("手术不能超过五个。")
      }
      if (stringIsBlank(setlinfo.value.decType)) {
        return ElMessage.error("请填写申报类型。")
      }
      if (listIsBlank(diseinfo.value)) {
        return ElMessage.error("诊断不能为空切不能大于27个。")
      } else if (diseinfo.value.length > 27) {
        return ElMessage.error("诊断超过27个。")
      }
      let data = setlinfo.value
      data['opIdCode'] = code
      data['opIdName'] = name
      data.batjBa4 = oprninfo.value
      data.ybZyDisDiag = diseinfo.value
      baoCunXiuGaiData.value = data
      beiZhuRef.value.beiZhuDialog = true
    }

    /*手术结束*/

    /* 审核信息 */
    const shenHeRef = ref(null)
    const keFeiShenHe = ref(false)
    watch(() => props.data.shenHeXinXi,
        () => {
          if (stringIsBlank(props.data.shenHeXinXi.id)
              && props.data.shenHeXinXi.auditFlag !== 0) {
            keFeiShenHe.value = true
          } else {
            keFeiShenHe.value = false
          }
        })

    const shenHeClick = () => {
      if (stringIsBlank(props.data.shenHeXinXi.id)) {
        return ElMessage.error("您还没有进行申请。")
      }
      shenHeRef.value.shenHeDialogOpen(true)
    }

    const shenHeTongGuoClick = () => {
      ElMessageBox.confirm('是否通过该审核', '提示', {
        type: "warning"
      }).then(() => {
        const data = {
          id: props.data.shenHeXinXi.id,
          auditFlag: 1,
          auditRemark: "审核通过 ❥(^_-)",
          auditStaff: code,
          auditName: name,
        }
        console.log(data)
        setlUploadAudit(data
        ).then((res) => {
          guanBi()
        }).catch((e) => {
        })
      })
    }

    const shenHeTongGuoShangChuanClick = () => {
      ElMessageBox.confirm('是否通过该审核并上传', '提示', {
        type: "warning"
      }).then(() => {
        const data = {
          id: props.data.shenHeXinXi.id,
          auditFlag: 1,
          auditRemark: "审核通过 ❥(^_-)",
          auditStaff: code,
          auditName: name,
        }
        console.log(data)
        setlUploadAudit(data
        ).then((res) => {
          let data = []
          data.push(props.data.upload)
          upldSetlList(data).then((res) => {
            guanBi()
          })
        }).catch((e) => {
        })
      })
    }

    const shenHeBoHuiClick = () => {
      ElMessageBox.prompt('请填写申请备注', '提示', {
        type: "warning",
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /\S/,
        inputErrorMessage: '审核备注不能为空且不得超过 100 字 (∩•̀ω•́)⊃-*⋆',
      }).then(({value}) => {
        if (value.length > 100) {
          return ElMessage.error("驳回原因超过 100 字。")
        }
        const data = {
          id: props.data.shenHeXinXi.id,
          auditFlag: 2,
          auditRemark: value,
          auditStaff: code,
          auditName: name,
        }
        setlUploadAudit(data
        ).then((res) => {
          guanBi()
        })

      }).catch((e) => {
      })
    }

    function guanBi() {
      huanZheXinXiDialog.value = false
      ctx.emit('shua-xin')
    }

    /* 审核信息结束 */

    /* 数据对比 */
    const shuJuDuiBiDialogRef = ref(null)
    const shuJuDuiBi = () => {
      if (stringIsBlank(props.data.shenHeXinXi.id)) {
        return ElMessage.error("您还没有进行申请。")
      }
      shuJuDuiBiDialogRef.value.isOpenDialog(true)
    }
    /* 数据对比结束 */


    /* 获取患者各个科室的费用 */
    const keShiFeiYongRef = ref(null)
    const feiYongDrawer = () => {
      keShiFeiYongRef.value.getFeiYongClick(setlinfo.value.inpatientNo, setlinfo.value.admissTimes)
    }
    /* 获取患者各个科室的费用结束 */

    const init = () => {
      setlinfo.value = clone(props.data)
      console.log(setlinfo.value)
      // 如果新的没有就用老的
      if (listNotBlank(props.data.newYbZyDisDiag)) {
        diseinfo.value = clone(props.data.newYbZyDisDiag)
      } else {
        diseinfo.value = clone(props.data.ybZyDisDiag)
      }
      if (listNotBlank(props.data.newBatjBa4)) {
        oprninfo.value = clone(props.data.newBatjBa4)
      } else {
        oprninfo.value = clone(props.data.batjBa4)
      }
      zhenDuanQuery.value.medType = props.data.medType
    }
    watch(() => props.data,
        () => {
          init()
        })

    return {
      props,
      setlinfo,
      diseinfo,
      oprninfo,
      huanZheXinXiDialog,
      openDialog,
      sheZhiZhuZhenDuan,
      store,
      cptSex,
      xiuGaiZhenDuanClick,
      zhenDuanDialog,
      methods: [
        {code: 'alpha', name: '拼音'},
        {code: 'code', name: '编码'},
        {code: 'name', name: '名称'},
      ],
      admissCondData: [
        {code: 1, name: '有'},
        {code: 2, name: '临床未确定'},
        {code: 3, name: '情况不明'},
        {code: 4, name: '无'},
      ],
      siDiagTypes: [
        {code: '1', name: '西医主要诊断'},
        {code: '2', name: '西医其他诊断'},
        {code: '3', name: '中医主要诊断'},
        {code: '4', name: '中医其他诊断'}
      ],
      zhenDuanQuery,
      queryZhenDuanData,
      zhenDuanChaXunClick,
      xuanZheZhenDuan,
      operations,
      decTypes,
      addZhenDuanClick,
      addZhenDuanFlag,
      addZhenDuan,
      lingShiZhenDuan,
      getsiDiagTypeName,
      delZhenDuan,
      shouShuDialog,
      pageZhenDuanChaXun,
      maZuiFangShis,
      formShouShu,
      maZuiName,
      qks,
      qieKouName,
      queryShouShuDialog,
      queryShouShu,
      queryShouShuCodeData,
      queryShouShuCodeName,
      shouShuData,
      queryShouShuClick,
      shouShuCurrentPage,
      xuanZheShouShu,
      formQieKou,
      shouShuBaoCunClick,
      tianJiaXiuGaiShouShu,
      shouShuRules,
      formShouShuRef,
      delShouShu,
      baoCunXiuGai,
      shuJuDuiBi,
      shuJuDuiBiDialogRef,
      shenHeClick,
      shenHeRef,
      shenHeBoHuiClick,
      shenHeTongGuoClick,
      shenHeTongGuoShangChuanClick,
      keFeiShenHe,
      shenHeQuanXian,
      feiYongDrawer,
      keShiFeiYongRef,
      baoCunXiuGaiData,
      beiZhuRef,
      baoCunHouGuanBi,
    }
  }
}


</script>

<style>

</style>
