Newer
Older
xc-metering-front / src / views / tested / MeasurementBusiness / detection / components / detail.vue
liyaguang on 27 Sep 2023 4 KB feat(*): 文件流预览打印功能
<!-- 检测结果复查通知单-详情 -->
<script lang="ts" setup name="DetecTIONFormEdit">
import type { FormInstance, FormRules, UploadUserFile } from 'element-plus'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import dayjs from 'dayjs'
import detection from './detection.vue'
import { printPage } from '@/api/eqpt/MeasurementBusiness/detection'
import { printContent } from '@/utils/exportUtils'
const $route = useRoute()
const $router = useRouter()
const ruleFormRef = ref<FormInstance>() // from组件
// 显示标题
const textMap: { [key: string]: string } = {
  update: '编辑',
  create: '新增',
  detail: '详情',
}
// 对话框类型:create,update
const dialogStatus = ref('create')
const ruleForm = ref({
  createTime: '', // 创建时间
  createUserId: '', // 创建人id
  createUserName: '', // 创建人名字
  customerId: '', // 委托方id
  customerName: '', // 委托方名称
  deviceModel: '', // 送检设备型号
  deviceName: '', // 送检设备名称
  deviceNo: '', // 送检设备编号
  id: '', // id
  labCode: '', // 实验室代码
  labCodeName: '', // 实验室代码
  noticeDate: '', // 通知日期
  noticeName: '', // 通知单名称
  noticeNo: '', // 通知单编号
  noticeUserId: '', // 通知委托方用户id
  noticeUserName: '', // 通知委托方用户名字
  returnDate: '', // 寄回日期
  submitDate: '', // 送检日期
  updateTime: '', // 更新时间
}) // 表单
// 弹窗初始化
const initDialog = () => {
  dialogStatus.value = $route.params.type as string
  ruleFormRef.value?.resetFields()
  if ($route.params.type !== 'create') {
    const data = JSON.parse($route.query.row as string)
    ruleForm.value = data
  }
}
onMounted(() => {
  initDialog()
})

// 关闭弹窗
const close = () => {
  $router.back()
}
// 取消
const resetForm = (formEl: FormInstance | undefined) => {
  formEl?.resetFields()
  close()
}
// 打印
const print = () => {
  printPage({ id: $route.query.id, pdf: true }).then((res) => {
    // pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.js'
    printContent(res.data)
  })
}
</script>

<template>
  <app-container style="overflow: hidden;">
    <detail-page :title="`检测结果复查通知单-${textMap[dialogStatus]}`">
      <template #btns>
        <el-button type="primary" @click="print">
          打印
        </el-button>
        <el-button type="info" @click="resetForm(ruleFormRef)">
          关闭
        </el-button>
      </template>
    </detail-page>
    <detail-block-com>
      <el-form ref="ruleFormRef" :model="ruleForm" :class="$route.path.includes('detail') ? 'isDetail' : ''" label-position="right" label-width="120px" class="form" :disabled="$route.path.includes('detail')">
        <el-row :gutter="24" class="marg">
          <el-col :span="6">
            <el-form-item label="通知单编号" prop="noticeNo">
              <el-input v-model.trim="ruleForm.noticeNo" placeholder="通知单编号" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="通知单名称" prop="noticeName">
              <el-input v-model.trim="ruleForm.noticeName" placeholder="通知单名称" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="创建人" props="createUserName">
              <el-input v-model.trim="ruleForm.createUserName" placeholder="创建人" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="创建时间">
              <el-input v-model.trim="ruleForm.createTime" placeholder="创建时间" disabled />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </detail-block-com>
    <detail-block-com><detection :data="ruleForm" /></detail-block-com>
  </app-container>
</template>

<style lang="scss" scoped>
// 详情页面隐藏小红点
.isDetail {
  ::v-deep {
    .el-form-item.is-required:not(.is-no-asterisk) .el-form-item__label-wrap > .el-form-item__label::before,
    .el-form-item.is-required:not(.is-no-asterisk) > .el-form-item__label::before {
      content: "";
      display: none;
    }
  }
}
</style>