Newer
Older
xc-business-system / src / views / business / taskMeasure / myTask / dialog / batchAddLabTaskDialog.vue
<!-- 批量增加实验室任务  -->
<script lang="ts" setup name="BatchAddLabTaskDialog">
import { ElMessage } from 'element-plus'
import type { Ref } from 'vue'
import { ref } from 'vue'
import dayjs from 'dayjs'
import type { DateModelType } from 'element-plus'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import { getDeptMeasureList } from '@/api/business/manager/task'
import type { dictType } from '@/global'
import useUserStore from '@/store/modules/user'
const emits = defineEmits(['confirm'])
// 用户信息
const user = useUserStore() // 用户信息
const listQuery = ref({
  customerName: '', //	委托方名称
  customerNo: '', //	委托方编号
  helpInstruction: '', //	辅助字段
  isUrgent: '', //	是否加急(1是0否null全部)
  manufactureNo: '', //	出厂编号
  manufacturer: '', //	生产厂家
  model: '', //	规格型号
  orderNo: '', //	任务单编号
  sampleName: '', //	受检设备名称
  sampleNo: '', //	样品编号
  startTime: '', //	要求检完时间开始
  endTime: '', //	要求检完时间结束
  measureStatus: '2', // 检测状态--2待检测
  measureValidDateStart: '', //	检定有效期开始
  measureValidDateEnd: '', //	检定有效期结束
  meterIdentify: '', // 计量标识
  traceDateStart: '', //	测试、校准或检定日期开始
  traceDateEnd: '', //	测试、校准或检定日期结束
  restrictionInstruction: '', // 限用说明
  conclusion: '', // 结论
  groupCode: '', // 实验室部门
  labCode: '', // 实验室
  glStaff: '', // 是否为综合管理组人员1/0
  offset: 1,
  limit: 20,
})

const timeRange = ref<[DateModelType, DateModelType]>(['', ''])
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])
const dateRangeCertificateValid = ref<[DateModelType, DateModelType]>(['', ''])
const dialogFormVisible = ref(false)
const checkoutList = ref([]) // 多选选中的内容
const loadingTable = ref(false) // 表格loading
const list = ref([]) // 表格数据
const total = ref(0)
const columns = ref<TableColumn[]>([
  { text: '受检设备名称', value: 'sampleName', align: 'center' },
  { text: '规格型号', value: 'sampleModel', align: 'center' },
  { text: '出厂编号', value: 'manufactureNo', align: 'center' },
  // { text: '生产厂家', value: 'manufacturer', align: 'center' },
  { text: '辅助字段', value: 'helpInstruction', align: 'center' },
  { text: '任务单编号', value: 'orderNo', align: 'center' },
  { text: '委托方', value: 'customerName', align: 'center' },
  { text: '要求检完时间', value: 'requireOverTime', align: 'center', width: '180' },
  { text: '是否加急', value: 'isUrgentName', align: 'center', width: '55px', styleFilter: (row: { isUrgentName: string }) => { return row.isUrgentName == '是' ? 'color: red' : '' } },
])
// --------------------------------------------字典--------------------------------------

const isUrgentList = ref<dictType[]>([])// 是否加急
const isUrgentMap = ref({}) as any // 是否加急{1: 是}
const meterIdentifyDict = ref({}) as any // 计量标识
const conclusionList = ref({}) as any // 检定结论

function getDict() {
  // 结论
  getDictByCode('bizConclusion').then((response) => {
    conclusionList.value = response.data
  })
  // 计量标识
  getDictByCode('eqptMeterIdentify').then((response) => {
    meterIdentifyDict.value = response.data
  })
  // 是否加急
  getDictByCode('isUrgent').then((response) => {
    isUrgentList.value = response.data
    response.data.forEach((item: any) => {
      isUrgentMap.value[`${item.value}`] = item.name
    })
  })
}

// --------------------------------------------------------------------------------------------
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  // listQuery.value.glStaff = user.roleTips.includes('administrator') ? '1' : '0' // 是否是超级管理员
  listQuery.value.glStaff = user.groupNo === 'GL' ? '1' : '0'
  listQuery.value.labCode = user.bizLabCode
  listQuery.value.groupCode = user.groupNo
  getDeptMeasureList(listQuery.value).then((res) => {
    list.value = res.data.rows.map((item: any) => {
      return {
        ...item,
        isUrgentName: `${item.isUrgent}` === '1' ? '是' : '否',
        traceDate: item.traceDate ? dayjs(item.traceDate).format('YYYY-MM-DD') : item.traceDate, // 检定日期
        certificateValid: item.certificateValid ? dayjs(item.certificateValid).format('YYYY-MM-DD') : item.certificateValid, // 证书有效期
        requireOverTime: item.requireOverTime ? dayjs(item.requireOverTime).format('YYYY-MM-DD HH:mm') : item.requireOverTime, // 要求检完时间
      }
    })
    total.value = res.data.total
    loadingTable.value = false
  })
}

// 多选选中
const handleSelectionChange = (val: any) => {
  checkoutList.value = val
}

// 点击确定
const confirmSelect = () => {
  if (!checkoutList.value.length) {
    ElMessage.warning('请选择实验室任务')
  }
  else {
    emits('confirm', checkoutList.value, true)
    dialogFormVisible.value = false
  }
}
// 取消
const resetForm = () => {
  dialogFormVisible.value = false
}
// 初始化
const initDialog = async () => {
  getDict()
  fetchData()
  dialogFormVisible.value = true
}

// 点击搜索
const searchList = () => {
  fetchData(true)
}
// 点击重置
const clearList = () => {
  listQuery.value = {
    customerName: '', //	委托方名称
    customerNo: '', //	委托方编号
    endTime: '', //	要求检完时间结束
    helpInstruction: '', //	辅助字段
    isUrgent: '', //	是否加急(1是0否null全部)
    manufactureNo: '', //	出厂编号
    manufacturer: '', //	生产厂家
    model: '', //	规格型号
    orderNo: '', //	任务单编号
    sampleName: '', //	受检设备名称
    sampleNo: '', //	样品编号
    startTime: '', //	要求检完时间开始
    measureStatus: '2', // 检测状态
    measureValidDateStart: '', //	检定有效期开始
    measureValidDateEnd: '', //	检定有效期结束
    meterIdentify: '', // 计量标识
    traceDateStart: '', //	测试、校准或检定日期开始
    traceDateEnd: '', //	测试、校准或检定日期结束
    restrictionInstruction: '', // 限用说明
    conclusion: '', // 结论
    groupCode: '', // 实验室部门
    labCode: '', // 实验室
    glStaff: '', // 是否为综合管理组人员1/0
    offset: 1,
    limit: 20,
  }
  timeRange.value = ['', '']
  dateRange.value = ['', '']
  dateRangeCertificateValid.value = ['', '']
  fetchData(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
  }
  fetchData(true)
}

watch(timeRange, (val) => { // 监听时间变化
  if (val) {
    listQuery.value.startTime = `${val[0]}`
    listQuery.value.endTime = `${val[1]}`
  }
  else {
    listQuery.value.startTime = ''
    listQuery.value.endTime = ''
  }
})

watch(dateRange, (val) => { // 监听检定日期变化
  if (val) {
    listQuery.value.traceDateStart = `${val[0]}`
    listQuery.value.traceDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.traceDateStart = ''
    listQuery.value.traceDateEnd = ''
  }
})
// 证书有效期
watch(dateRangeCertificateValid, (val) => { // 监听证书有效期变化
  if (val) {
    listQuery.value.measureValidDateStart = `${val[0]}`
    listQuery.value.measureValidDateEnd = `${val[1]}`
  }
  else {
    listQuery.value.measureValidDateStart = ''
    listQuery.value.measureValidDateEnd = ''
  }
})

defineExpose({ initDialog })
</script>

<template>
  <el-dialog v-if="dialogFormVisible" v-model="dialogFormVisible" title="选择实验室任务" width="65%">
    <search-area
      :need-clear="true"
      @search="searchList" @clear="clearList"
    >
      <search-item>
        <el-input
          v-model.trim="listQuery.sampleName"
          placeholder="受检设备名称"
          clearable
          class="short-input"
        />
      </search-item>
      <search-item v-if="listQuery.measureStatus !== '3'">
        <el-input
          v-model.trim="listQuery.model"
          placeholder="规格型号"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item v-if="listQuery.measureStatus !== '3'">
        <el-input
          v-model.trim="listQuery.manufactureNo"
          placeholder="出厂编号"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item v-if="listQuery.measureStatus !== '3'">
        <el-input
          v-model.trim="listQuery.helpInstruction"
          placeholder="辅助字段"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.orderNo"
          placeholder="任务单编号"
          clearable
          class="short-input"
        />
      </search-item>
      <search-item>
        <el-input
          v-model.trim="listQuery.customerName"
          placeholder="委托方"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item v-if="listQuery.measureStatus === '4'">
        <el-date-picker
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          start-placeholder="检定日期(开始)"
          end-placeholder="检定日期(结束)"
          class="short-input"
        />
      </search-item>
      <search-item v-if="listQuery.measureStatus === '4'">
        <el-select
          v-model="listQuery.conclusion"
          placeholder="检定结论"
          filterable
          class="full-width-input"
          clearable
        >
          <el-option v-for="item in conclusionList" :key="item.id" :label="item.name" :value="item.name" />
        </el-select>
      </search-item>
      <search-item v-if="listQuery.measureStatus === '4'">
        <el-input
          v-model.trim="listQuery.restrictionInstruction"
          placeholder="限用说明"
          class="short-input"
          clearable
        />
      </search-item>
      <search-item v-if="listQuery.measureStatus === '4'">
        <el-select
          v-model="listQuery.meterIdentify"
          class="short-input"
          placeholder="计量标识"
          clearable
        >
          <el-option v-for="item of meterIdentifyDict" :key="item.value" :label="item.name" :value="item.name" />
        </el-select>
      </search-item>
      <search-item v-if="listQuery.measureStatus === '4'">
        <el-date-picker
          v-model="dateRangeCertificateValid"
          type="daterange"
          range-separator="至"
          format="YYYY-MM-DD"
          value-format="YYYY-MM-DD"
          start-placeholder="证书有效期(开始)"
          end-placeholder="证书有效期(结束)"
          class="short-input"
        />
      </search-item>
      <search-item v-if="listQuery.measureStatus !== '4'">
        <el-date-picker
          v-model="timeRange"
          type="datetimerange"
          range-separator="至"
          format="YYYY-MM-DD HH:mm"
          value-format="YYYY-MM-DD HH:mm"
          start-placeholder="要求检完开始时间"
          end-placeholder="要求检完结束时间"
        />
      </search-item>
    </search-area>
    <!-- 查询结果Table显示 -->
    <div style="padding: 12px;">
      <normal-table
        :data="list" :total="total" :columns="columns" :query="listQuery"
        :list-loading="loadingTable" is-showmulti-select @change="changePage" @multi-select="handleSelectionChange"
      >
        <!-- 序号 -->
        <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>
    <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>