<template>
  <xc-dialog-v2 v-model="dialog" title="特殊医嘱">
    <div v-if="props.yzData.orderCode === czCode">
       <span>
          请输入处置医嘱名称:
      </span>
      <el-input
          v-model="props.yzData.orderName"
          type="textarea"
          :maxlength="50"
          show-word-limit/>
    </div>
    <div v-if="props.yzData.orderCode === zkCode">
      <span>
          请输入转科科室:
      </span>
      <el-select v-model="props.yzData.zkObj"
                 filterable
                 @change="zkChange">
        <el-option v-for="(item, index) in zkList"
                   :key="item.value"
                   :label="item.wardName + '|' + item.smallName"
                   :value="item.value">
          <span>{{ item.wardName }}</span>
          <el-divider direction="vertical"></el-divider>
          <span>{{ item.smallName }}</span>
        </el-option>
      </el-select>
    </div>
    <div v-if="props.yzData.kjywFlag === 1">
      用药方式：
      <el-select v-model="props.yzData.yyfs"
                 id="yz_yyfs"
                 style="width: 120px" @change="kangJunYaoYongYaoFangShiGaiBian">
        <el-option v-for="item in kangJunYaoWuYongYaoFangShi" :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-select
          v-model="props.yzData.ssqk"
          id="yz_ssqk"
          :disabled="props.yzData.yyfs !== 1 && props.yzData.yyfs !== 2 && props.yzData.yyfs !== null"
          clearable
          style="width: 120px"
          @clear="props.yzData.ssqk = null"
      >
        <el-option v-for="item in kangJunYaoWuQieKou" :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-select
          id="yz_yysj"
          v-model="props.yzData.yysj"
          :disabled="props.yzData.yyfs !== 1 && props.yzData.yyfs !== 2 && props.yzData.yyfs !== null"
          clearable
          style="width: 120px"
          @clear="props.yzData.yysj = null">
        <el-option v-for="item in kangJunYaoWuYongYaoShiJian" :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>
    </div>
    <template #footer>
      <el-button @click="cancel">取消</el-button>
      <el-button @click="dialog = false">确认</el-button>
    </template>
  </xc-dialog-v2>
</template>

<script setup name='YzDialog'>
import XcDialogV2 from "@/components/xiao-chan/dialog/XcDialogV2";
import {yiZhuData, zkList} from "@/views/hospitalization/zhu-yuan-yi-sheng/public-js/zhu-yuan-yi-sheng";
import {kangJunYaoWuQieKou, kangJunYaoWuYongYaoFangShi, kangJunYaoWuYongYaoShiJian} from '@/data'

const props = defineProps({
  yzData: {
    type: Object,
    default: {
      orderCode: '06054'
    }
  }
})

// 专科医嘱
const zkCode = '06286'
// 处置医嘱
const czCode = '06054'

const specialOrders = ['06286', '06054']

const dialog = ref(false)

const zkChange = () => {
  let zk = JSON.parse(props.yzData.zkObj)
  props.yzData.zkWardCode = zk.wardCode
  props.yzData.zkDeptCode = zk.smallCode
  props.yzData.orderName = `转科医嘱转至${zk.wardName}(小科室:${zk.smallName})`
}

/*  这里是抗菌药物，选择了除了 1和 2 的其他都可以不用填写 */
const kangJunYaoYongYaoFangShiGaiBian = (val) => {
  if (val !== 1 || val !== 2) {
    props.yzData.ssqk = null
    props.yzData.yysj = null
  }
}


const openOrClose = (val) => {
  if (yiZhuData.value.statusFlag !== '1') {
    return
  }

  if (val) {
    if (specialOrders.includes(yiZhuData.value.orderCode)) {
      dialog.value = true
    } else if (yiZhuData.value.kjywFlag === 1) {
      dialog.value = true
    }
  } else {
    dialog.value = val
  }
}

const cancel = () => {
  if (yiZhuData.value.orderCode === '06054') {
    yiZhuData.value.orderName = '处置医嘱'
  }
  dialog.value = false
}

defineExpose({
  openOrClose
})

</script>

<style lang="scss" scoped>

</style>
