<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="性别">
          {{ cptSex(setlinfo.sex) }}
        </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="住院次数">
          {{ 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="keFouShenHe" @click="shenHeTongGuoClick">审核通过</el-button>
          <el-button type="success" :disabled="keFouShenHe" @click="shenHeTongGuoShangChuanClick">审核通过并上传</el-button>
          <el-button type="danger" :disabled="keFouShenHe" @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
                id="sortable-diseinfo" row-key="id">
        <el-table-column width="50">
          <template #default>
            <el-button class="shangxiatuodong"><i class="iconfont icon-shangxiatuodong"></i></el-button>
          </template>
        </el-table-column>
        <el-table-column label="诊断代码" prop="disDiag"></el-table-column>
        <el-table-column label="诊断名称" prop="disDiagComment"></el-table-column>
        <el-table-column label="入院病情" prop="admissCond" width="90">
          <template #default="scope">
            {{ getAdmissCond(scope.row.admissCond) }}
          </template>
        </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-button type="warning" @click="xiuGaiZhenDuanClick(scope.$index,scope.row)" icon="el-icon-edit">修改
            </el-button>
            <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 row-key="id" id="sortable-oprninfo">
        <el-table-column width="50">
          <template #default>
            <el-button class="shangxiatuodong"><i class="iconfont icon-shangxiatuodong"></i></el-button>
          </template>
        </el-table-column>
        <el-table-column label="手术及操作名称" prop="ssmc"></el-table-column>
        <el-table-column label="序号" prop="ssxh" width="50"></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="操作" width="210">
          <template #default="scope">
            <el-button type="warning" @click="tianJiaXiuGaiShouShu(scope.$index)" icon="el-icon-edit">修改</el-button>
            <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="addShouShuClick">保存</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 {setlUploadAudit, shouShuBianMa, upldSetlList} from "../../api/medical-insurance/si-setl-upload";
import {formatDatetime} from "../../utils/date";
import {listIsBlank, stringIsBlank, stringNotBlank} from "../../utils/blank-utils";
import ShuJuDuiBi from "./ShuJuDuiBi.vue"
import {
  getAdmissCond,
  getsiDiagTypeName,
  maZuiFangShis,
  maZuiName,
  qieKouName,
  qks,
  shenHeQuanXian
} from "./jieSuanDanXiuGai";
import ShenHeXinXi from "./ShenHeXinXi.vue";
import KeShiFeiYong from "./KeShiFeiYong.vue";
import BeiZhu from "./BeiZhu.vue";
import Sortable from "sortablejs";

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: 'name',
      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) => {
      queryZhenDuanData.value = []
      zhenDuanQuery.value.content = val.disDiagComment
      lingShiZhenDuan.value = val
      addZhenDuanFlag.value = false
      zhenDuanDialog.value = true
      zhenDuanIndex = index
      diseinfo.value.forEach((item, index) => {
        item.disDiagNo = index + 1
      })
    }
    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: '',
        id: null,
      }
      queryZhenDuanData.value = []
      addZhenDuanFlag.value = true
      zhenDuanDialog.value = true
    }
    const addZhenDuan = (val) => {
      if (zhenDuanTianJiaTiaoJian()) return
      lingShiZhenDuan.value.disDiag = val.code
      lingShiZhenDuan.value.id = diseinfo.value.length + 1
      lingShiZhenDuan.value.disDiagComment = val.name
      lingShiZhenDuan.value.disDiagNo = diseinfo.value.length + 1
      lingShiZhenDuan.value.newData = true
      diseinfo.value.push(lingShiZhenDuan.value)
      zhenDuanDialog.value = false
      setTimeout(() => {
        sortableDiseinfo()
      }, 100)
    }
    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.admissCond)) {
        ElMessage.error("请先选择入院院病情")
        return true
      }
      return false
    }

    /*诊断结束*/

    /*一下都是手术的*/
    const shouShuDialog = ref(false)
    const formShouShu = ref({
      id: 0,
      ssxh: 0,
      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'}],
      qkName: [{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 addShouShuClick = 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)
        } else {
          // 只有在新增的 时候才需要 加长度
          formShouShu.value.id = oprninfo.value.length + 1
          formShouShu.value.ssxh = oprninfo.value.length + 1
          formShouShu.value.newData = true
          oprninfo.value.push(clone(formShouShu.value))
        }
        shouShuDialog.value = false
        setTimeout(() => {
          sortableOprninfo()
        }, 100)
      } catch (e) {
      }
    }

    const delShouShu = (index) => {
      oprninfo.value.splice(index, 1)
      oprninfo.value.forEach((item, index) => {
        item.ssxh = 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 > 7) {
        return ElMessage.error("手术不能超过7个。")
      }
      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 keFouShenHe = ref(false)
    watch(() => props.data.shenHeXinXi,
        () => {
          keFouShenHe.value = !(stringNotBlank(props.data.shenHeXinXi.id)
              && props.data.shenHeXinXi.auditFlag === 0);
        })

    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,
        }
        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,
        }
        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)
      // 如果新的没有就用老的
      if (stringNotBlank(props.data.shenHeXinXi.id)) {
        diseinfo.value = clone(props.data.newYbZyDisDiag)
        oprninfo.value = clone(props.data.newBatjBa4)
        if (stringNotBlank(props.data.shenHeXinXi.reqRemark)
            && props.data.shenHeXinXi.auditFlag === 0) {
          setTimeout(() => {
            ElMessageBox.alert(props.data.shenHeXinXi.reqRemark, '申请备注', {
              type: 'warning'
            })
          }, 1000)
        }

        //初始化拖拽表格
      } else {
        diseinfo.value = clone(props.data.ybZyDisDiag)
        oprninfo.value = clone(props.data.batjBa4)
      }
      if (diseinfo.value.length > 0) {
        setTimeout(() => {
          sortableDiseinfo()
        }, 100)
      }
      if (oprninfo.value.length > 0) {
        setTimeout(() => {
          sortableOprninfo()
        }, 100)
      }
      zhenDuanQuery.value.medType = props.data.medType
    }

    /**
     * 诊断的拖拽
     */
    function sortableDiseinfo() {
      const el = document.querySelector("#sortable-diseinfo tbody");
      //设置拖拽的参数
      const ops = {
        animation: 200, //动画时长
        handle: '.shangxiatuodong', // 拖动的 class
        onEnd({newIndex, oldIndex}) {
          const currRow = diseinfo.value.splice(oldIndex, 1)[0]
          diseinfo.value.splice(newIndex, 0, currRow)
          diseinfo.value.forEach((item, index) => {
            item.disDiagNo = index + 1
          })
        },//拖拽完成回调函数（新index，旧index）
      };
      Sortable.create(el, ops);
    }

    function sortableOprninfo() {
      const el = document.querySelector("#sortable-oprninfo tbody");
      const ops = {
        animation: 200, //动画时长
        handle: '.shangxiatuodong',
        onEnd({newIndex, oldIndex}) {
          const currRow = oprninfo.value.splice(oldIndex, 1)[0]
          oprninfo.value.splice(newIndex, 0, currRow)
          oprninfo.value.forEach((item, index) => {
            item.ssxh = index + 1
          })
        },//拖拽完成回调函数（新index，旧index）
      };
      Sortable.create(el, ops);
    }


    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,
      addShouShuClick,
      tianJiaXiuGaiShouShu,
      shouShuRules,
      formShouShuRef,
      delShouShu,
      baoCunXiuGai,
      shuJuDuiBi,
      shuJuDuiBiDialogRef,
      shenHeClick,
      shenHeRef,
      shenHeBoHuiClick,
      shenHeTongGuoClick,
      shenHeTongGuoShangChuanClick,
      keFouShenHe,
      shenHeQuanXian,
      feiYongDrawer,
      keShiFeiYongRef,
      baoCunXiuGaiData,
      beiZhuRef,
      baoCunHouGuanBi,
      getAdmissCond,
    }
  },

}


</script>

<style>

</style>
