Newer
Older
xc-business-system / src / views / business / taskMeasure / certificate / detail.vue
<!-- 证书审批管理详情页 -->
<script name="certificateDetail" lang="ts" setup>
import { ElMessage, ElMessageBox } from 'element-plus'
import type { Ref } from 'vue'
import type { FormInstance, FormRules, UploadUserFile } from 'element-plus'
import type { IForm } from './certificate-interface'
import certificateBasic from './components/basic.vue'
import certificateChangeRecord from './components/changeRecord.vue'
import certificateApprovalRecord from './components/approvalRecord.vue'
import useUserStore from '@/store/modules/user'
import {
  cancelApproval,
  refuseApproval,
} from '@/api/business/taskMeasure/certificate'
const textMap: { [key: string]: string } = {
  edit: '编辑',
  add: '新建',
  detail: '详情',
}// 页面类型字典
const user = useUserStore() // 用户信息
const pageType = ref('add') // 页面类型: add, edit, detail
const infoId = ref('') // id
const ruleFormRef = ref() // 表单ref
const $router = useRouter()
const approvalStatusName = ref('') // 审批状态名称
const processId = ref('') // 流程实例id
const taskId = ref('') // 任务id,用于同意、驳回、拒绝审批
const showApprovalButton = ref(true) // 是否展示审批按钮
const approvalDialog = ref() // 审批对话ref
// -------------------------------------标签--------------------------------------------------
const radioMenus = ref([ // 标签内容
  { name: '基本信息', value: 'certificate-basic' },
  // { name: '修改记录', value: 'certificate-change-record' },
  { name: '审批详情', value: 'certificate-approval-record' },
])
const current = ref('certificate-basic') // 选择的tab 默认基本信息

// -----------------------------------------路由参数----------------------------------------
// 从路由中获取页面类型参数
const $route = useRoute()
if ($route.params && $route.params.type) {
  pageType.value = $route.params.type as string
  if ($route.params.id) {
    infoId.value = $route.params.id as string
  }
}
console.log('页面类型', pageType.value, 'infoId', infoId.value)
// --------------------------------------------按钮----------------------------------------------
// 点击证书报告打印
const printReport = () => {
  ElMessage.info('敬请期待')
}

// 点击原始记录打印
const printRecord = () => {
  ElMessage.info('敬请期待')
}

// 点击提交
const submitForm = () => {
  ElMessage.info('敬请期待')
}

// 点击保存
const saveForm = (formEl: FormInstance | undefined) => {
}

// 点击关闭
const close = () => {
  $router.back()
}

// -------------------------------------------审批----------------------------------------

// 审批结束回调
const approvalSuccess = () => {
  showApprovalButton.value = false
}

// 审批
const handleApprove = (val: string) => {
  if (val === '取消') {
    const params = {
      processInstanceId: processId.value!,
      comments: '',
      id: infoId.value,
    }
    ElMessageBox.confirm(
      '确认取消该审批吗?',
      '提示',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      },
    )
      .then(() => {
        cancelApproval(params).then((res) => {
          ElMessage({
            type: 'success',
            message: '已取消',
          })
          showApprovalButton.value = false
        })
      })
  }
  else if (val === '同意') {
    approvalDialog.value.initDialog('agree', taskId.value)
  }
  else if (val === '拒绝') {
    approvalDialog.value.initDialog('refuse', taskId.value, infoId.value)
  }
}

// 拒绝
const refuse = (comments: string, taskId: string, id: string) => {
  const params = {
    id,
    taskId, // 任务id
    comments, // 拒绝原因
  }
  refuseApproval(params).then((res) => {
    ElMessage({
      type: 'success',
      message: '已拒绝',
    })
    showApprovalButton.value = false
  })
}
// -----------------------------------------------钩子-----------------------------
watch(() => approvalStatusName.value, (val) => {
  if (val === '全部' || val === '草稿箱' || pageType.value === 'add') { // 全部草稿箱把审批详情删了
    if (radioMenus.value[radioMenus.value.length - 1].value === 'certificate-approval-record') {
      radioMenus.value.pop()
    }
    console.log(radioMenus.value)
  }
  else { // 非全部和草稿箱把审批详情加上
    if (radioMenus.value[radioMenus.value.length - 1].value !== 'certificate-approval-record') {
      radioMenus.value.push({ name: '审批详情', value: 'certificate-approval-record' })
    }
  }
})
// ----------------------------------------------------------------------------------------------
onMounted(() => {
  approvalStatusName.value = $route.query.approvalStatusName as string // 审批名称
  console.log('approvalStatusName.value', approvalStatusName.value)
})
</script>

<template>
  <app-container>
    <detail-page :title="`检定审批管理(${textMap[pageType]})`">
      <template #btns>
        <el-button v-if="pageType === 'detail'" type="primary" @click="printReport">
          证书报告打印
        </el-button>
        <el-button v-if="pageType === 'detail'" type="primary" @click="printRecord">
          原始记录打印
        </el-button>
        <el-button v-if="pageType === 'add'" type="primary" @click="submitForm">
          提交
        </el-button>
        <el-button v-if="pageType !== 'detail'" type="primary" @click="saveForm(ruleFormRef)">
          保存
        </el-button>
        <el-button type="info" @click="close">
          关闭
        </el-button>
      </template>
      <el-radio-group v-model="current">
        <el-radio-button v-for="item in radioMenus" :key="item.value" :label="item.value">
          {{ item.name }}
        </el-radio-button>
      </el-radio-group>
    </detail-page>
    <!-- 基本信息 -->
    <certificate-basic v-if="current === 'certificate-basic'" :page-type="pageType" />
    <!-- 修改记录  -->
    <!-- <certificate-change-record v-if="current === 'certificate-change-record'" :page-type="pageType" /> -->

    <!-- 审批详情 -->
    <approval-record-table v-if="current === 'certificate-approval-record'" :process-id="processId" />
    <!-- 审批弹窗 -->
    <approval-dialog ref="approvalDialog" @on-success="approvalSuccess" @refuse="refuse" />
  </app-container>
</template>