Newer
Older
xc-business-system / src / views / equipement / standard / build / edit.vue
<!-- 建标管理详情 -->
<script lang="ts" setup name="standardBuildEdit">
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import { ref } from 'vue'
import standardBuildApproveBasic from './components/basic.vue'
import { getDictByCode } from '@/api/system/dict'
import type { dictType } from '@/global'
import { UploadFile } from '@/api/file'
import { approvalDelete, cancelApproval, refuseApproval, uploadStandardFile } from '@/api/equipment/standard/build'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
const { proxy } = getCurrentInstance() as any
const $router = useRouter() // 关闭页面使用
const approvalStatusName = ref('') // 审批状态名称
const processId = ref('') // 流程实例id
const taskId = ref('') // 任务id,用于同意、驳回、拒绝审批
const textMap: { [key: string]: string } = {
  edit: '编辑',
  add: '新建',
  detail: '详情',
}// 字典
const pageType = ref('add') // 页面类型: add, edit, detail
const infoId = ref('') // 列表id
const $route = useRoute() // 路由参数
const approvalDialog = ref() // 审批对话ref
const showApprovalButton = ref(true) // 是否展示审批按钮
const showRefuseEditButton = ref(true) // 是否展示未通过编辑按钮
const showSubmitButton = ref(false) // 提交按钮是否禁用
const standardBuildApproveBasicRef = ref() // 基本信息组件ref
// -----------------------------------------------路由参数---------------------------------
if ($route.params && $route.params.type) {
  pageType.value = $route.params.type as string
  if ($route.params.id) {
    infoId.value = $route.params.id as string
  }
}
// -------------------------------------标签--------------------------------------------------
const radioMenus = ref([ // 标签内容
  { name: '基本信息', value: 'standardBuild-approve-basic' },
  { name: '审批详情', value: 'standardBuild-approval-record' },
])
const current = ref('standardBuild-approve-basic') // 选择的tab 默认基本信息

// -----------------------------------------按钮--------------------------------------------------
// 关闭新增页面的回调
const close = () => {
  $router.back()
}
// 点击提交
const handleSubmit = () => {
  standardBuildApproveBasicRef.value.submitForm(processId.value, infoId.value)
}
// 点击保存
const saveForm = () => {
  standardBuildApproveBasicRef.value.saveForm()
}
// 新建保存成功
const addSuccess = (id: string) => {
  infoId.value = id
  // pageType.value = 'detail' // 详情模式-不可编辑
  showSubmitButton.value = true // 保存成功显示提交按钮
}
// 提交成功
const submitSuccess = () => {
  pageType.value = 'detail' // 详情模式-不可编辑
  showRefuseEditButton.value = false // 隐藏提交按钮
}

// 点击删除--已取消
const del = () => {
  approvalDelete({ id: infoId.value, taskId: taskId.value }).then(() => {
    ElMessage.success('已删除')
    close()
  })
}

// 点击编辑
const handleEdit = () => {
  pageType.value = 'edit' // 编辑模式
}

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

// 审批结束回调
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
  })
}

// ------------------------------------------------------------------------------------------------
// 点击编辑此标准装置按钮
const editStandard = () => {
  console.log(standardBuildApproveBasicRef.value.form)
  sessionStorage.setItem('showRemindSave', '0')
  sessionStorage.setItem('updatedGradeFromBuild', '0') // 从建标管理跳转过去量值有没有保存操作完成
  sessionStorage.setItem('updatedBasicFromBuild', '0') // 从建标管理跳转过去基本信息有没有保存操作完成
  const tempForm = standardBuildApproveBasicRef.value.form
  $router.push({
    path: `/standard/edit/${tempForm.standardId}`,
    query: {
      ...tempForm,
      approvalStatusName: '全部', // 审批状态名称
      standardId: tempForm.standardId,
      fromPage: 'standardBuildDetail',
      buildStandardName: tempForm.applyName, // 建标申请名称
      buildStandardId: tempForm.id, // 建标申请表id relationPdfFile
      quantityPdfFile: tempForm.relationPdfFile, // 量值溯源与传递等级关系图word版
      quantityWordFile: tempForm.relationFile, // 量值溯源与传递等级关系图pdf版
    },
  })
}

// -----------------------------------------------钩子------------------------------------------
watch(() => approvalStatusName.value, (val) => {
  if (val === '草稿箱' || pageType.value === 'add' || `${$router.options.history.state.back}`.includes('workbench')) { // 草稿箱、新建把审批详情删了
    if (radioMenus.value[radioMenus.value.length - 1].value === 'standardBuild-approval-record') {
      radioMenus.value.pop()
    }
    console.log(radioMenus.value)
  }
  else { // 非新建和草稿箱把审批详情加上
    if (radioMenus.value[radioMenus.value.length - 1].value !== 'standardBuild-approval-record') {
      radioMenus.value.push({ name: '审批详情', value: 'standardBuild-approval-record' })
    }
  }
})
const showEditStandard = ref(false) // 是否显示编辑标准装置按钮
onMounted(async () => {
  // fetchUserList() // 获取用户列表
  approvalStatusName.value = $route.query.approvalStatusName as string // 审批状态名字
  processId.value = $route.query.processId as string // 流程实例id
  taskId.value = $route.query.taskId as string // 任务id用于审批
  const lastPage = `${$router.options.history.state.back}` // 上一页的路径
  if (lastPage.includes('workbench') && $route.query.fromWorkBench === 'work') { // 从工作台来跳转过来显示编辑标准装置按钮
    showEditStandard.value = true
  }
})
</script>

<template>
  <app-container>
    <detail-page :title="`建标管理 (${textMap[pageType]})`">
      <template #btns>
        <el-button v-if="pageType === 'detail' && showEditStandard" type="primary" @click="editStandard">
          编辑此标准装置
        </el-button>
        <el-button v-if="pageType === 'detail' && approvalStatusName === '待审批' && showApprovalButton" type="primary" @click="handleApprove('同意')">
          同意
        </el-button>
        <el-button v-if="pageType === 'detail' && approvalStatusName === '待审批' && showApprovalButton" type="danger" @click="handleApprove('拒绝')">
          拒绝
        </el-button>
        <el-button v-if="pageType === 'detail' && approvalStatusName === '审批中' && showApprovalButton" type="info" @click="handleApprove('取消')">
          取消
        </el-button>
        <el-button
          v-if="pageType === 'add' || (pageType === 'edit' && approvalStatusName !== '未通过' && approvalStatusName !== '已取消' && approvalStatusName !== '全部')"
          type="primary"
          :disabled="!showSubmitButton"
          @click="handleSubmit"
        >
          提交
        </el-button>
        <el-button v-if="approvalStatusName !== '已审批' && pageType === 'detail' && approvalStatusName === '未通过' && showRefuseEditButton" type="primary" @click="handleEdit">
          编辑
        </el-button>
        <el-button v-if="pageType !== 'detail'" type="primary" @click="saveForm">
          保存
        </el-button>
        <el-button v-if="approvalStatusName === '已取消'" type="danger" @click="del">
          删除
        </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"
          :disabled="!infoId"
        >
          {{ item.name }}
        </el-radio-button>
      </el-radio-group>
    </detail-page>
    <!-- 基本信息 -->
    <standard-build-approve-basic
      v-if="current === 'standardBuild-approve-basic'"
      :id="infoId"
      ref="standardBuildApproveBasicRef"
      :page-type="pageType"
      :approval-status-name="approvalStatusName"
      @add-success="addSuccess"
      @submit-success="submitSuccess"
    />
  </app-container>
  <!-- 审批详情 -->
  <approval-record-table v-if="current === 'standardBuild-approval-record'" :process-id="processId" />
  <!-- 审批弹窗 -->
  <approval-dialog ref="approvalDialog" @on-success="approvalSuccess" @refuse="refuse" />
</template>