Newer
Older
xc-business-system / src / views / resource / file / methodConfirm / selectMethodDialog.vue
dutingting on 29 Nov 12 KB 临时提交
<!-- 选择测试校准检定方法查新记录表下的测试校准检定方法 -->
<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 { detailMethodNovelty, getNoveltySearchList } from '@/api/resource/fileNovelty'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { SCHEDULE } from '@/utils/scheduleDict'
import type { IDictType } from '@/commonInterface/resource-interface'
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 labCodeDict = ref<Array<IDictType>>([]) // 实验室
const groupCodeDict = ref<Array<IDictType>>([]) // 部门
const noveltyResultDict = ref<IDictType[]>([]) // 查新结果
const noveltyStatusDict = ref<IDictType[]>([]) // 查新状态
// 获取字典
const fetchDict = () => {
  getDictByCode('bizLabCode').then((res) => {
    if (res.code === 200) {
      labCodeDict.value = res.data
    }
  })
  getDictByCode('bizGroupCode').then((res) => {
    if (res.code === 200) {
      groupCodeDict.value = res.data
    }
  })
  getDictByCode('bizNoveltyResult').then((res) => {
    if (res.code === 200) {
      noveltyResultDict.value = res.data
    }
  })
  getDictByCode('bizNoveltyStatus').then((res) => {
    if (res.code === 200) {
      noveltyStatusDict.value = res.data
    }
  })
}
fetchDict()
// 查询条件--左侧
const listQueryLeft = ref({
  approvalStatus: '0', //	审批状态类型code,导出接口不用传
  formId: SCHEDULE.NOVELTY_SEARCH_RECORD_LIST_APPROVAL,
  groupCode: '', // 	组别代码
  labCode: '', //	实验室名称
  formNo: '', // 文件编号
  formName: '', // 文件名称
  noveltyResult: '', // 查新结果
  createUserName: '', // 查新人
  noveltyDateStart: '',
  noveltyDateEnd: '',
  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: 'labCodeName', align: 'center' },
  { text: '部门', value: 'groupCodeName', align: 'center' },
  { text: '文件编号', value: 'formNo', align: 'center' },
  { text: '文件名称', value: 'formName', align: 'center' },
  { text: '查新结果', value: 'noveltyResult', align: 'center' },
  { text: '更新比例', value: 'searchRatio', align: 'center' },
  { text: '查新人', value: 'createUserName', align: 'center' },
  { text: '查新日期', value: 'noveltyDate', align: 'center' },
])
const dateRangeLeft = ref<[DateModelType, DateModelType]>([])// 筛选时间段数据
watch(() => dateRangeLeft.value, (newVal) => {
  listQueryLeft.value.noveltyDateStart = ''
  listQueryLeft.value.noveltyDateEnd = ''
  if (Array.isArray(newVal)) {
    if (newVal.length) {
      listQueryLeft.value.noveltyDateStart = `${newVal[0]} 00:00:00`
      listQueryLeft.value.noveltyDateEnd = `${newVal[1]} 23:59:59`
    }
  }
}, {
  deep: true,
})

// -----------------------------------测试校准检定方法---------------------------------------------------
// 查询条件--右侧
const listQueryRight = ref({
  noveltyStatus: '', // 查新状态
})
const methodsList = ref([]) as any // 测试校准检定方法
const methodsAllList = ref([]) as any // 测试校准检定方法
const methodsLoadingTable = ref(false) // 测试校准检定方法loading
const checkoutMethodsList = ref([]) as any // 选好的测试校准检定方法
const methodsColumns = ref<TableColumn[]>([ // 表头
  { text: '实验室', value: 'labCodeName', align: 'center' },
  { text: '部门', value: 'groupCodeName', align: 'center' },
  { text: '文件编号', value: 'fileNo', align: 'center' },
  { text: '文件名称', value: 'fileName', align: 'center' },
  { text: '查新状态', value: 'noveltyResultName', align: 'center' },
  { text: '最新查新时间', value: 'latestNoveltyDate', align: 'center' },
])
// 选好方法
const rowClickRight = (val: any) => {
  console.log(val, 'val')
  checkoutMethodsList.value = val
}
//
const searchRight = () => {
  if (!listQueryRight.value.noveltyStatus) {
    methodsList.value = methodsAllList.value
    return
  }
  methodsList.value = methodsAllList.value.filter((item: any) => item.noveltyStatus === listQueryRight.value.noveltyStatus)
}
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQueryLeft.value.offset = 1
  }
  getNoveltySearchList(listQueryLeft.value).then((response) => {
    list.value = response.data.rows
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 重置
const clearListLeft = () => {
  listQueryLeft.value = {
    approvalStatus: '0', //	审批状态类型code,导出接口不用传
    formId: SCHEDULE.NOVELTY_SEARCH_RECORD_LIST_APPROVAL,
    groupCode: '', // 	组别代码
    labCode: '', //	实验室名称
    formNo: '', // 文件编号
    formName: '', // 文件名称
    noveltyResult: '', // 查新结果
    createUserName: '', // 查新人
    noveltyDateStart: '',
    noveltyDateEnd: '',
    offset: 1,
    limit: props.isMulti ? 5 : 20,
  }
  dateRangeLeft.value = ['', '']
  fetchData()
}
const clearListRight = () => {
  listQueryRight.value.noveltyStatus = ''
  methodsList.value = methodsAllList.value
}
// 搜索
const search = () => {
  fetchData(true)
}
// 选中
const rowClick = (val: any) => {
  checkoutList.value = val
  console.log(val, 'val')
  detailMethodNovelty({ id: val.id }).then((res) => {
    methodsList.value = res.data.logList
    methodsAllList.value = res.data.logList
  })
  // methodsList.value = val.logList.map((item: any) => ({ ...item, id: item.fileId || Math.random() }))
  // methodsAllList.value = val.logList
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size?: number; page?: number }) => {
  if (val && val.size) {
    listQueryLeft.value.limit = val.size
  }
  if (val && val.page) {
    listQueryLeft.value.offset = val.page
  }
  search()
}

// ---------------------------------------------------------------------------------------------
// 点击确定
const confirmSelect = () => {
  if (!checkoutMethodsList.value.length) {
    ElMessage.warning('请选择测试校准检定方法')
    return
  }
  // 返回第1项为选择的测试校准检定方法查新记录表,第2项为测试校准检定方法
  emits('confirm', checkoutList.value, checkoutMethodsList.value)
  dialogFormVisible.value = false
}
// 取消
const resetForm = () => {
  dialogFormVisible.value = false
  clearListLeft()
  clearListRight()
}
// 初始化
const initDialog = async () => {
  methodsList.value = [] // 清空配套智能模型
  dialogFormVisible.value = true
  // 获取当前用户 实验室部门等信息
  listQueryLeft.value.labCode = user.bizLabCode
  listQueryLeft.value.groupCode = user.groupNo
  listQueryLeft.value.noveltyResult = '1'
  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="clearListLeft">
          <search-item width="150px">
            <el-select v-model="listQueryLeft.labCode" placeholder="实验室" clearable disabled>
              <el-option v-for="item in labCodeDict" :key="item.id" :value="item.value" :label="item.name" />
            </el-select>
          </search-item>
          <search-item width="150px">
            <el-select v-model="listQueryLeft.groupCode" placeholder="部门" clearable disabled>
              <el-option v-for="item in groupCodeDict" :key="item.id" :value="item.value" :label="item.name" />
            </el-select>
          </search-item>
          <search-item width="150px">
            <el-input
              v-model.trim="listQueryLeft.formNo" placeholder="文件编号" class="short-input" clearable
              style="width: 150px;"
            />
          </search-item>
          <search-item width="150px">
            <el-input
              v-model.trim="listQueryLeft.formName" placeholder="文件名称" class="short-input" clearable
              style="width: 150px;"
            />
          </search-item>
          <search-item width="150px">
            <el-select v-model="listQueryLeft.noveltyResult" placeholder="查新结果" clearable disabled>
              <el-option v-for="item in noveltyResultDict" :key="item.id" :value="item.value" :label="item.name" />
            </el-select>
          </search-item>
          <search-item width="150px">
            <el-input
              v-model.trim="listQueryLeft.createUserName" placeholder="查新人" class="short-input" clearable
              style="width: 150px;"
            />
          </search-item>
          <search-item>
            <el-date-picker
              v-model="dateRangeLeft" type="daterange" range-separator="至" format="YYYY-MM-DD"
              value-format="YYYY-MM-DD" start-placeholder="查新时间(开始)" end-placeholder="查新时间(结束)" class="short-input"
            />
          </search-item>
        </search-area>

        <!-- 查询结果Table显示 -->
        <div style="padding: 12px;">
          <normal-table
            :data="list" :total="total" :columns="columns" :query="listQueryLeft" 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">
                  {{ (listQueryLeft.offset - 1) * listQueryLeft.limit + scope.$index + 1 }}
                </template>
              </el-table-column>
            </template>
          </normal-table>
        </div>
      </el-col>
      <el-col :span="12">
        <!-- 筛选条件 -->
        测试校准检定方法
        <search-area :need-clear="true" @search="searchRight" @clear="clearListRight">
          <search-item width="150px">
            <el-select v-model="listQueryRight.noveltyStatus" placeholder="查新状态" clearable>
              <el-option v-for="item in noveltyStatusDict" :key="item.id" :value="item.value" :label="item.name" />
            </el-select>
          </search-item>
        </search-area>

        <!-- 查询结果Table显示 -->
        <div style="padding: 12px;">
          <normal-table
            :data="methodsList" :total="total" :columns="methodsColumns" :query="listQueryRight"
            :list-loading="methodsLoadingTable" :is-multi="false" :height="416" :pagination="false"
            @multi-select="rowClickRight"
          >
            <!-- 序号 -->
            <template #preColumns>
              <el-table-column label="#" width="55" align="center" fixed>
                <template #default="scope">
                  {{ 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>