Newer
Older
xc-business-system / src / views / equipement / standard / checkData / dialog / selectStandardEquipmentDialog.vue
dutingting on 3 Jan 14 KB 需求开发+10
<!-- 选择标准装置下的标准配套设备 -->
<script lang="ts" setup name="SelectStandardEquipmentDialog">
import { ElMessage } from 'element-plus'
import { ref } from 'vue'
import dayjs from 'dayjs'
import type { DateModelType } from 'element-plus'
import { getEquipmentList, getStandardList } from '@/api/equipment/standard/book'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { SCHEDULE } from '@/utils/scheduleDict'
import { getDictByCode } from '@/api/system/dict'
import useUserStore from '@/store/modules/user'

const props = defineProps({
  isMulti: { // 是否多选
    type: Boolean,
    default: false, // 默认单选
  },
})
// 用户信息
const emits = defineEmits(['confirm'])
const user = useUserStore()
const dialogFormVisible = ref(false)
const standardId = ref('') // 标准装置id
// 查询条件
const listQuery = ref({
  approvalStatus: '0', //	审批状态类型code,导出接口不用传
  deptId: '', //		部门id
  formId: SCHEDULE.STANDARD_BOOK_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
  groupCode: '', // 	部门
  inUseStatus: '', //	在用状态
  labCode: '', //	实验室名称
  lastChangeDateStart: '', //	最近变更日期开始
  lastChangeDateEnd: '', //	最近变更日期结束
  lastReviewDateStart: '', //	最近复查日期开始
  lastReviewDateEnd: '', //	最近复查日期结束
  nextReviewDateStart: '', //	下次复查日期开始
  nextReviewDateEnd: '', //	下次复查日期结束
  majorType: '', //	专业类别
  standardName: '', //	计量标准装置名称
  standardNo: '', //	计量标准证书号
  storageLocation: '', //	存放地点(字典code)
  technologyFileName: '', //	依据技术文件名称
  groupeCode: '',
  offset: 1,
  limit: props.isMulti ? 5 : 20,

})
// 多选选中的内容
const checkoutList = ref([])
const loadingTable = ref(false)
const list = ref([]) // 表格数据
const total = ref(0)
const columns = ref<TableColumn[]>([
  { text: '计量标准证书号', value: 'standardCertNo', align: 'center', width: '160' },
  { text: '计量标准装置名称', value: 'standardName', align: 'center', width: '220' },
  { text: '实验室', value: 'labCodeName', align: 'center', width: '120' },
  { text: '部门', value: 'groupCodeName', align: 'center', width: '120' },
  { text: '专业类别', value: 'majorTypeName', align: 'center', width: '120' },
  { text: '最近复查日期', value: 'lastReviewDate', align: 'center', width: '120' },
  { text: '下次复查日期', value: 'nextReviewDate', align: 'center', width: '120' },
  { text: '在用状态', value: 'manageStatusName', align: 'center' },
  { text: '最近变更日期', value: 'lastChangeDate', align: 'center', width: '120' },
  { text: '标准证书', value: 'standardCertFile', align: 'center' },
])
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据
const selectStandardId = ref('') // 选择的标准装置id
const selectStandardName = ref('') // 选择的标准装置名称
const selectStandardAlias = ref('') // 选择的标准装置名称
const belongStandardEquipment = ref('') // 检校标准装置code
// -----------------------------------------字典--------------------------------------------------------------
const storageLocationList = ref({}) as any // 存放地点{1: 新建}
const standardMap = ref({}) as any// 检校标准装置
const useDeptList = ref([]) // 所属部门列表
const labDeptList = ref([]) // 实验室
// 查询字典
const getDict = async () => {
  // 实验室
  getDictByCode('bizGroupCodeEquipment').then((response) => {
    labDeptList.value = response.data
  })

  // 部门
  getDictByCode('bizGroupCode').then((response) => {
    useDeptList.value = response.data
  })
  // 存放地点
  getDictByCode('bizStorageLocation').then((response) => {
    storageLocationList.value = response.data
  })
  const res = await getDictByCode('bizStandardEquipmentType')
  res.data.forEach((item: { value: string; name: string }) => {
    standardMap.value[`${item.name}`] = item.value
  })
}
// -----------------------------------配套设备---------------------------------------------------
const equipmentList = ref([]) as any // 配套设备
const equipmentLoadingTable = ref(false) // 配套设备loading
const checkoutEquipmentList = ref([]) as any // 选好的配套设备
const equipmentColumns = ref<TableColumn[]>([ // 表头
  { text: '统一编号', value: 'equipmentNo', align: 'center', required: true },
  { text: '计量标准的主标准器及配套设备名称', value: 'equipmentName', align: 'center' },
  { text: '规格型号', value: 'model', align: 'center' },
  { text: '出厂编号', value: 'manufactureNo', align: 'center' },
  { text: '生产厂家', value: 'manufacturer', align: 'center' },
  { text: '测量范围', value: 'measureRange', align: 'center' },
  { text: '不确定度或允许误差极限或准确度等级', value: 'uncertainty', align: 'center' },
  { text: '核查项分类名称', value: 'itemCategoryName', align: 'center' },
])

// 选择配套设备
const handleSelectionChange = (val: any) => {
  checkoutEquipmentList.value = val
}
// ----------------------------------------标准装置----------------------------------------------------

// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getStandardList(listQuery.value).then((response) => {
    list.value = response.data.rows.map((item: any) => {
      return {
        ...item,
        lastReviewDate: item.lastReviewDate ? dayjs(item.lastReviewDate).format('YYYY-MM-DD') : item.lastReviewDate, // 最近复查日期
        nextReviewDate: item.nextReviewDate ? dayjs(item.nextReviewDate).format('YYYY-MM-DD') : item.nextReviewDate, // 下次复查日期
        lastChangeDate: item.lastChangeDate ? dayjs(item.lastChangeDate).format('YYYY-MM-DD') : item.lastChangeDate, // 最近变更日期
      }
    })
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 重置
const clearList = () => {
  listQuery.value = {
    approvalStatus: '0', //	审批状态类型code,导出接口不用传
    deptId: '', //		部门id
    formId: SCHEDULE.STANDARD_BOOK_APPROVAL, // 表单id(流程定义对应的表单id,等价于业务id),导出接口不用传
    groupCode: '', // 	部门
    inUseStatus: '', //	在用状态
    labCode: '', //	实验室名称
    lastChangeDateStart: '', //	最近变更日期开始
    lastChangeDateEnd: '', //	最近变更日期结束
    lastReviewDateStart: '', //	最近复查日期开始
    lastReviewDateEnd: '', //	最近复查日期结束
    nextReviewDateStart: '', //	下次复查日期开始
    nextReviewDateEnd: '', //	下次复查日期结束
    majorType: '', //	专业类别
    standardName: '', //	计量标准装置名称
    standardNo: '', //	计量标准证书号
    storageLocation: '', //	存放地点(字典code)
    technologyFileName: '', //	依据技术文件名称
    groupeCode: '',
    offset: 1,
    limit: props.isMulti ? 5 : 20,
  }
  dateRange.value = ['', '']
  fetchData()
}
// 搜索
const search = () => {
  fetchData(true)
}
// 选中
const rowClick = (val: any) => {
  checkoutList.value = val
  equipmentLoadingTable.value = true
  selectStandardId.value = val.id // 选好的标准装置id
  selectStandardName.value = val.standardName // 选好的标准装置名称(这个是标准装置中的别名)
  selectStandardAlias.value = val.standardAlias // 选好的标准装置别名(这个是标准装置中的名称)
  belongStandardEquipment.value = standardMap.value[val.standardName] // 检校标准装置
  // 请求标准装置下的配套设备
  getEquipmentList({
    standardId: val.id, // 标准装置id
    standardName: val.standardName, // 选好的标准装置name
    offset: 1,
    limit: 999999,
  }).then((res) => { // 请求
    const tempArr = [] as any
    res.data.rows.forEach((item: any) => {
      if (!item.technicalTargetList.length) {
        tempArr.push(item)
      }
      else {
        let tempUncertainty = '' // 不确定度
        let tempMeasureRange = '' // 测量范围
        item.technicalTargetList.forEach((i: any) => {
          tempUncertainty = `${tempUncertainty}${i.uncertainty}; `
          tempMeasureRange = `${tempMeasureRange}${i.measureRange}; `
        })
        tempArr.push({
          ...item,
          uncertainty: tempUncertainty,
          measureRange: tempMeasureRange,
        })
      }
    })
    equipmentList.value = tempArr
    equipmentLoadingTable.value = false
  })
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number;page?: number }) => {
  if (val && val.size) {
    listQuery.value.limit = val.size
  }
  if (val && val.page) {
    listQuery.value.offset = val.page
  }
  search()
}

// ---------------------------------------------------------------------------------------------
// 点击确定
const confirmSelect = () => {
  if (!checkoutEquipmentList.value.length) {
    ElMessage.warning('请选择设备')
  }
  else {
    if (!checkoutEquipmentList.value[0].itemCategoryId || !checkoutEquipmentList.value[0].itemCategoryName) {
      ElMessage.warning('此设备未配置核查项,请检查')
      return false
    }

    emits('confirm', checkoutEquipmentList.value, selectStandardId.value, selectStandardName.value, belongStandardEquipment.value, selectStandardAlias.value)
    dialogFormVisible.value = false
  }
}
// 取消
const resetForm = () => {
  dialogFormVisible.value = false
  clearList()
}
// 初始化
const initDialog = async (labCodeParam = '', groupCodeParam = '') => {
  equipmentList.value = [] // 清空配套设备
  getDict().then(() => {
    dialogFormVisible.value = true
    listQuery.value.labCode = labCodeParam
    listQuery.value.groupCode = groupCodeParam
    fetchData()
  })
}

defineExpose({ initDialog })
</script>

<template>
  <el-dialog v-if="dialogFormVisible" v-model="dialogFormVisible" title="选择标准装置下的标准配套设备" width="90%">
    <el-row :gutter="16">
      <el-col :span="12">
        <!-- 筛选条件 -->
        <search-area :need-clear="true" @search="search" @clear="clearList">
          <search-item>
            <el-input v-model.trim="listQuery.standardNo" placeholder="计量标准证书号" class="short-input" clearable />
          </search-item>
          <search-item>
            <el-input v-model.trim="listQuery.standardName" placeholder="计量标准装置名称" class="short-input" clearable />
          </search-item>
          <search-item>
            <el-select
              v-model="listQuery.labCode"
              placeholder="实验室"
              class="short-input"
              filterable
              clearable
            >
              <el-option v-for="item in labDeptList" :key="item.id" :label="item.name" :value="item.value" />
            </el-select>
          </search-item>
          <search-item>
            <el-select
              v-model="listQuery.groupCode"
              placeholder="部门"
              class="short-input"
              filterable
              clearable
            >
              <el-option v-for="item in useDeptList" :key="item.id" :label="item.name" :value="item.value" />
            </el-select>
          </search-item>
          <search-item>
            <el-select
              v-model="listQuery.majorType"
              placeholder="专业类别"
              class="short-input"
              filterable
              clearable
            >
              <el-option v-for="item in majorTypeList" :key="item.id" :label="item.name" :value="item.value" />
            </el-select>
          </search-item>
          <search-item>
            <el-select
              v-model="listQuery.inUseStatus"
              placeholder="在用状态"
              class="short-input"
              filterable
              clearable
            >
              <el-option v-for="item in bizStandardManagerStateList" :key="item.id" :label="item.name" :value="item.value" />
            </el-select>
          </search-item>
        </search-area>

        <!-- 查询结果Table显示 -->
        <div style="padding: 12px;">
          <normal-table
            :data="list"
            :total="total"
            :columns="columns"
            :query="listQuery"
            is-showmulti-select
            :list-loading="loadingTable"
            :is-multi="props.isMulti"
            :height="360"
            :page-sizes="[5, 10, 20, 30, 50, 100, 150, 200]"
            @change="changePage"
            @row-click="rowClick"
          >
            <!-- 序号 -->
            <template #preColumns>
              <el-table-column label="#" width="55" align="center" fixed>
                <template #default="scope">
                  {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
                </template>
              </el-table-column>
            </template>
          </normal-table>
        </div>
      </el-col>
      <el-col :span="12">
        <!-- 筛选条件 -->
        <!-- <search-area :need-clear="true" @search="search" @clear="clearList">
          <search-item>
            <el-input v-model.trim="listQuery.standardName" placeholder="设备名称" class="short-input" clearable />
          </search-item>
        </search-area> -->

        <!-- 查询结果Table显示 -->
        <div style="padding: 12px;">
          <normal-table
            :data="equipmentList"
            :total="total"
            :columns="equipmentColumns"
            :query="listQuery"
            is-showmulti-select
            :list-loading="equipmentLoadingTable"
            :is-multi="props.isMulti"
            :height="416"
            :pagination="false"
            @multi-select="handleSelectionChange"
          >
            <!-- 序号 -->
            <template #preColumns>
              <el-table-column label="#" width="55" align="center" fixed>
                <template #default="scope">
                  {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
                </template>
              </el-table-column>
            </template>
          </normal-table>
        </div>
      </el-col>
    </el-row>
    <h5 style="color: red;margin: 0 10px;">
      注意:先选择左侧的标准装置查询标准配套设备, 设备展示在右侧
    </h5>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="confirmSelect">确认</el-button>
        <el-button @click="resetForm">
          取消
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
:deep(.el-radio__label) {
  display: none;
}
</style>