Newer
Older
xc-business-system / src / views / workbench / components / checkManage.vue
<!-- 核查管理 -->
<script lang="ts" setup name="CheckManage">
import { ElMessage } from 'element-plus'
// import { position } from 'html2canvas/dist/types/css/property-descriptors/position'
import { getDictByCode } from '@/api/system/dict'
import type { deptType, dictType } from '@/global'
import { getCheckData } from '@/api/workBench/checkData'
import useUserStore from '@/store/modules/user'
import { getCheckDataList } from '@/api/equipment/standard/checkData'
const user = useUserStore() // 用户信息
const loading = ref(false)
const showEmpty = ref(false)
const labCode = ref('') // 实验室代码
const groupCode = ref('') as any // 组别代码
const isAdministrator = ref('0') // 是不是超级管理员
const emptyDisc = ref('') // 描述文字
const list = ref([]) as any // 表格数据
const columns = [
  { text: '被核查标准库名称', value: 'standardEquipmentName', align: 'center', required: true },
  { text: '最近一次核查时间', value: 'checkDate', align: 'center', required: true, width: '120' },
]

const checkRecordTotal = ref('-') // 核查记录总数
const checkRecordTotalYear = ref('-') // 核查记录总数(本年度)
const checkRecordTotalQuarter = ref('-') // 核查记录总数(本季度)

// ------------------------------------------字典----------------------------------------------
const groupCodeList = ref([]) as any // 组别
const labCodeList = ref<dictType[]>([]) // 实验室

function getDict() {
  // 组别
  getDictByCode('bizGroupCode').then((response) => {
    const tempMenu = ['电学电源组', '热工力学组', '无线电脉冲组']
    tempMenu.forEach((item) => {
      const tempFindData = response.data.find((e: { name: string; value: string }) => e.name === item)
      if (tempFindData) {
        groupCodeList.value.push({
          name: tempFindData.name,
          id: `${tempFindData.id}`,
          value: `${tempFindData.value}`,
        })
      }
    })
    groupCodeList.value.unshift({
      id: 'all',
      name: '全部',
      value: null,
    })
  })

  // 实验室
  getDictByCode('bizGroupCodeEquipment').then((response) => {
    labCodeList.value = response.data
  })
}
getDict()

// 点击新建核查数据
// const addCheckData = (row: any) => {
//   $router.push({
//     path: '/standard/checkData/add',
//   })
// }
// --------------------------------------------获取数据----------------------------------------------
// 获取核查总数等
const fetchCheckData = () => {
  getCheckData({
    endDate: '',	// 结束日期(检校设备分析/检校结果分析查询条件)
    groupCode: groupCode.value,	//	组别编号(当是管理组人员时,为下拉选择的组别)
    labCode: labCode.value,	//	实验室编号
    startDate: '',	//	起始日期(检校设备分析/检校结果分析查询条件)
  }).then((res) => {
    if (res.data && res.data.length) {
      const indexCheckRecordTotal = res.data.findIndex((item: { dimension: string }) => item.dimension === '核查记录总数') // 核查记录总数
      if (indexCheckRecordTotal !== -1) {
        checkRecordTotal.value = res.data[indexCheckRecordTotal].amount
      }
      const indexCheckRecordTotalYear = res.data.findIndex((item: { dimension: string }) => item.dimension === '核查记录总数(本年度)') // 核查记录总数(本年度)
      if (indexCheckRecordTotalYear !== -1) {
        checkRecordTotalYear.value = res.data[indexCheckRecordTotalYear].amount
      }
      const indexCheckRecordTotalQuarter = res.data.findIndex((item: { dimension: string }) => item.dimension === '核查记录总数(本季度)') // 核查记录总数(本季度)
      if (indexCheckRecordTotalQuarter !== -1) {
        checkRecordTotalQuarter.value = res.data[indexCheckRecordTotalQuarter].amount
      }
      // loading.value = false
    }
  })
}

// 获取核查数据列表
function fetchCheckDataList() {
  loading.value = true
  getCheckDataList({
    checkDateEnd: '', // 核查日期结束
    checkDateStart: '', // 核查日期开始
    checkEquipmentModel: '', // 核查标准设备型号
    checkEquipmentName: '', // 核查标准设备名称
    createUserName: '', // 核查员
    dataNo: '', // 数据编号
    equipmentModel: '', // 被核查设备规格型号
    equipmentName: '', // 被核查设备名称
    standardEquipmentName: '', // 被核查标准库名称
    equipmentManufactureNo: '', // 被核查设备出厂编号
    recordNo: '', // 核查记录
    limit: 999999,
    offset: 1,
  }).then((response) => {
    list.value = response.data.rows
    loading.value = false
  })
}

const fetchData = () => {
  loading.value = true
  fetchCheckData()
  fetchCheckDataList()
}

// ----------------------------------------------钩子------------------------------------------------
// 改变实验室\组别
const changeSelect = () => {
  if (!showEmpty.value && (isAdministrator.value === '1' || (user.bizLabCode && user.groupNo))) {
    fetchData()
  }
}

onMounted(() => {
  // 检校结果分析
  isAdministrator.value = user.roleTips.includes('administrator') ? '1' : '0' // 是否是超级管理员
  console.log('是否是超级管理员', user.roleTips, isAdministrator.value)
  if (isAdministrator.value === '1') { // 超级管理员
    labCode.value = user.bizLabCode || 'H' // 有实验室就默认本人实验室,没有实验室就默认海口
    groupCode.value = null // 超级管理员默认查看全部
    fetchData()
  }
  else { // 不是超级管理员
    if (!user.bizLabCode) { // 没有实验室
      emptyDisc.value = '此用户非超级管理员且无实验室,无权限查看'
      showEmpty.value = true
    }
    else if (!user.groupNo) { // 有实验室但没有组
      emptyDisc.value = '此用户非超级管理员且无组别,无权限查看'
      showEmpty.value = true
    }
    else { // 有实验室且有组
      showEmpty.value = false
      if (user.groupNo === 'GL') { // 综合管理组
        labCode.value = user.bizLabCode // 实验室
        // 综合管理组默认查实验室下面的所有数据,不筛选组别
        groupCode.value = ''
        // 综合管理组可以查看待分发
      }
      else { // 其他组
        labCode.value = user.bizLabCode // 实验室
        // 其他组默认筛选自己组
        groupCode.value = user.groupNo
      }
      fetchData()
    }
  }
})
</script>

<template>
  <el-empty v-show="showEmpty" style="height: 100%;" :description="emptyDisc" />
  <div v-show="!showEmpty" class="workBench-measure-manage">
    <!-- 超级管理员才可以筛选实验室 -->
    <el-select v-model="labCode" :disabled="isAdministrator === '0'" style="width: 130px;position: absolute; top: 5px;right: 150px;" class="short-input" placeholder="实验室" clearable @change="changeSelect">
      <el-option v-for="item in labCodeList" :key="item.id" :label="item.name" :value="item.value" />
    </el-select>
    <!-- 综合管理组才可以筛选组别 -->
    <el-select v-model="groupCode" :disabled="isAdministrator === '0' && user.groupNo !== 'GL'" style="width: 130px;position: absolute; top: 5px;right: 10px;" class="short-input" placeholder="组别" clearable @change="changeSelect">
      <el-option v-for="item in groupCodeList" :key="item.id" :label="item.name" :value="item.value" />
    </el-select>
    <div v-loading="loading" style="display: flex;flex-direction: column;width: 100%;height: 100%;">
      <!-- 核查记录统计 -->
      <div style="height: 40px;display: flex;margin: 16px 0;justify-content: space-around;">
        <div style="display: flex;margin-right: 20px;">
          <el-icon :size="30" color="#3d7eff">
            <svg-icon name="icon-check" />
          </el-icon>
          <div>
            <div style="font-size: 14px;">
              核查记录总数
            </div>
            <div style="margin-left: 10px;color: #000;font-weight: 600;">
              {{ checkRecordTotal }}
            </div>
          </div>
        </div>
        <div style="display: flex;">
          <el-icon :size="30" color="#f88070">
            <svg-icon name="icon-check" />
          </el-icon>
          <div>
            <div style="font-size: 14px;">
              核查记录总数(本年度)
            </div>
            <div style="margin-left: 10px;color: #000;font-weight: 600;">
              {{ checkRecordTotalYear }}
            </div>
          </div>
        </div>
        <div style="display: flex;">
          <el-icon :size="30" color="#10d069">
            <svg-icon name="icon-check" />
          </el-icon>
          <div>
            <div style="font-size: 14px;">
              核查记录总数(本季度)
            </div>
            <div style="margin-left: 10px;color: #000;font-weight: 600;">
              {{ checkRecordTotalQuarter }}
            </div>
          </div>
        </div>
      </div>
      <div class="title">
        核查列表
      </div>
      <el-table
        :data="list"
        border
        style="width: 100%;height: 100%;"
      >
        <el-table-column align="center" label="序号" width="80" type="index" />
        <el-table-column
          v-for="item in columns"
          :key="item.value"
          :prop="item.value"
          :label="item.text"
          align="center"
          :width="item.width"
          show-overflow-tooltip
        />
        <!-- <el-table-column label="操作" align="center" fixed="right" width="110">
          <template #default="{ row }">
            <el-button size="small" link type="primary" @click="addCheckData(row)">
              新建核查数据
            </el-button>
          </template>
        </el-table-column> -->
      </el-table>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.workBench-measure-manage {
  width: 100%;
  height: 100%;
  overflow: auto;
  box-sizing: border-box;

  .title {
    font-size: 16px;
    padding: 0;
    margin: 0 0 6px;
  }
}
</style>