Newer
Older
xc-business-system / src / views / quality / internal / dissatisfied / components / checkDialog.vue
<!-- 内部审核检查表 -->
<script lang="ts" setup name="TemplateDialog">
import { ElMessage } from 'element-plus'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getInspectList } from '@/api/quality/internal/inspect'
import { SCHEDULE } from '@/utils/scheduleDict'
import { getSearchDept } from '@/api/quality/supervise/record'
import { getDictByCode } from '@/api/system/dict'
import useUserStore from '@/store/modules/user'
const emits = defineEmits(['add'])
const dialogFormVisible = ref(false)
const userStore = useUserStore()
const { proxy } = getCurrentInstance() as any
const listQuery = ref({
  approvalStatus: '0',
  creatorName: userStore.name,
  bizLabCode: '',
  createTimeEnd: '',
  createTimeStart: '',
  deptId: '',
  fileCode: '',
  fileName: '',
  offset: 1,
  limit: 5,
})
// 开始结束时间
const datetimerange = ref()
watch(() => datetimerange.value, (newVal) => {
  listQuery.value.createTimeStart = ''
  listQuery.value.createTimeEnd = ''
  if (Array.isArray(newVal)) {
    if (newVal.length) {
      listQuery.value.createTimeStart = `${newVal[0]} 00:00:00`
      listQuery.value.createTimeEnd = `${newVal[1]} 23:59:59`
    }
  }
})
// 列表数据
const tableList = ref([])
const total = ref(0)
const loadingTable = ref(true)
// 列
const columns = ref<TableColumn[]>([
  { text: '文件编号', value: 'fileCode', align: 'center' },
  { text: '文件名称', value: 'fileName', align: 'center' },
  { text: '实验室', value: 'bizLabCodeName', align: 'center' },
  { text: '受审核部门', value: 'deptName', align: 'center' },
  { text: '创建人', value: 'creatorName', align: 'center' },
  { text: '创建时间', value: 'createTime', align: 'center' },
])
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getInspectList({ ...listQuery.value, formId: SCHEDULE.INTERNAL_AUDIT_CHECKLIST_APPROVAL }).then((response) => {
    tableList.value = response.data.rows
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  }).catch(() => {
    loadingTable.value = false
  })
}
// 搜索
const searchList = () => {
  fetchData(true)
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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
  }
  searchList()
}
// 重置查询条件
const clearList = () => {
  datetimerange.value = []
  listQuery.value = {
    approvalStatus: '0',
    // creatorName: '',
    bizLabCode: '',
    createTimeEnd: '',
    createTimeStart: '',
    deptId: '',
    fileCode: '',
    fileName: '',
    offset: 1,
    limit: 5,
  }
  searchList()
}
// 单选选中
const checkoutList = ref<any[]>([])
const checkSelect = (val: any) => {
  checkoutList.value = val
}
// 点击保存
const submitForm = () => {
  if (checkoutList.value.length) {
    emits('add', checkoutList.value[0])
    dialogFormVisible.value = false
  }
  else {
    ElMessage.warning('内部审核检查表')
  }
}
// 取消
const resetForm = () => {
  dialogFormVisible.value = false
}
// 初始化
const initDialog = () => {
  dialogFormVisible.value = true
  searchList()
}
defineExpose({ initDialog })
const labelList = ref<{ id: string; value: string; name: string }[]>()// 实验室
const deptList = ref<{ deptName: string; deptId: string }[]>([]) // 部门列表
const deptAllList = ref<{ deptName: string; deptId: string }[]>([]) // 部门列表
const fetchDict = () => {
  // 获取实验室字典
  getDictByCode('bizLabCode').then((res) => {
    labelList.value = res.data
  })
  getSearchDept({ labCode: '' }).then((res) => {
    deptList.value = res.data
    deptAllList.value = res.data
  })
}
fetchDict()
watch(() => listQuery.value.bizLabCode, (newVal) => {
  if (newVal) {
    listQuery.value.deptId = ''
    getSearchDept({ labCode: newVal }).then((res) => {
      deptList.value = res.data
    })
  }
  else {
    deptList.value = deptAllList.value
  }
}, {
  deep: true,
})
</script>

<template>
  <el-dialog v-model="dialogFormVisible" title="内部审核检查表" width="65%">
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="searchList" @clear="clearList">
      <search-item>
        <el-input
          v-model="listQuery.fileCode"
          placeholder="文件编号"
        />
      </search-item>
      <search-item>
        <el-input
          v-model="listQuery.fileName"
          placeholder="文件名称"
        />
      </search-item>
      <search-item>
        <el-select
          v-model="listQuery.bizLabCode"
          placeholder="实验室"
          class="short-input"
          filterable
        >
          <el-option v-for="item in labelList" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-select
          v-model="listQuery.deptId"
          placeholder="受审核部门"
          class="short-input"
          filterable
        >
          <el-option v-for="item in deptList" :key="item.deptId" :label="item.deptName" :value="item.deptId" />
        </el-select>
      </search-item>
      <!-- <search-item>
        <el-input
          v-model="listQuery.creatorName"
          placeholder="创建人"
        />
      </search-item> -->
      <search-item>
        <el-date-picker
          v-model="datetimerange" type="daterange" value-format="YYYY-MM-DD"
          format="YYYY-MM-DD" range-separator="至" start-placeholder="创建开始时间" end-placeholder="创建结束时间"
        />
      </search-item>
    </search-area>
    <table-container>
      <!-- <template #btns-right>
        <icon-button icon="icon-add" title="新建" type="primary" />
        <icon-button icon="icon-export" title="导出" type="primary" />
      </template> -->
      <normal-table
        :data="tableList" :total="total" :query="listQuery" :columns="columns" :list-loading="loadingTable"
        :is-showmulti-select="false" :is-multi="false" @change="changePage" @multi-select="checkSelect"
      >
        <template #preColumns>
          <el-table-column label="序号" width="55" align="center">
            <template #default="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="submitForm">确认</el-button>
        <el-button @click="resetForm">
          取消
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

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