<template>
  <xc-dialog-v2 v-model="dialog" title="合理用药提示"
                :manual-shutdown="true">
    <div style="width: 100%;height: 500px">
      <iframe :src="rationalUse.ShowUrl"/>
    </div>
    <template #footer>
      <el-button type="danger" @click="dialog = false">close</el-button>
      <el-button type="primary" @click="continueToSubmit">继续提交</el-button>
    </template>
  </xc-dialog-v2>
</template>

<script setup name='RationalDrugUseWindow'>
import {auditingInterface, rationalUseOfMedicine} from "@/api/heliyongyao/rational-use";
import XcDialogV2 from "@/components/xiao-chan/dialog/XcDialogV2.vue";
import {xcMessage} from "@/utils/xiaochan-element-plus";
import {stringIsBlank} from "@/utils/blank-utils";

const emit = defineEmits(['submit'])

let dialog = $ref(false)
let rationalUse = $ref({})

const check = async (patNo, times) => {
  rationalUse = await rationalUseOfMedicine(patNo, times)
  console.log(rationalUse)
  if (rationalUse.result_lv > 0) {
    dialog = true
    return false
  }
  return true
}


const continueToSubmit = async () => {
  let temp = await auditingInterface(rationalUse.getResultUrl)
  if ((temp.success && temp.resultcode === 0) || temp.resultcode === -1) {
    // 审核通过
    xcMessage.success(temp.sh_msg ? temp.sh_msg : '审核通过。');
    emit('submit')
    dialog = false
  } else if (temp.success && temp.resultcode === 1) {
    // 审核不通过
    xcMessage.error(temp.sh_msg);
  } else if (temp.resultcode === 0 && !temp.success) {
    // 待审核中
    xcMessage.error('请点击继续保存后，等待审核完成，点击继续提交。');
  }
}

defineExpose({
  check
})

</script>

<style scoped lang="scss">
iframe {
  width: 100%;
  height: 100%;
}
</style>
