Newer
Older
xc-business-system / src / views / quality / correct / handle / index.vue
<!-- 纠正措施处理单列表 -->
<script name="QualityCorret" lang="ts" setup>
import { getDictByCode } from '@/api/system/dict'
import type { TableColumn } from '@/components/NormalTable/table_interface'
// 查询条件
const listQuery = ref({
  startTime: '',
  endTime: '',
  checked: false,
  offset: 1,
  limit: 20,
})
// 开始结束时间
const datetimerange = ref()
watch(() => datetimerange.value, (newVal) => {
  listQuery.value.startTime = ''
  listQuery.value.endTime = ''
  if (Array.isArray(newVal)) {
    if (newVal.length) {
      listQuery.value.startTime = `${newVal[0]} 00:00:00`
      listQuery.value.endTime = `${newVal[1]} 23:59:59`
    }
  }
})
// 列表数据
const tableList = ref([])
const total = ref(0)
const loadingTable = ref(true)
const checkoutList = ref<string[]>([])// 选中的内容
// 列
const columns = ref<TableColumn[]>([
  { text: '处理单编号', value: 'standardNo', align: 'center' },
  { text: '处理单名称', value: 'standardNo', align: 'center' },
  { text: '提出人', value: 'standardNo', align: 'center' },
  { text: '记录时间', value: 'standardNo', align: 'center' },
])
// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  tableList.value = []
  total.value = 0
  loadingTable.value = false
  // getStandardList(listQuery.value).then((response) => {
  //   list.value = response.data.rows.map((item: { lastReviewDate: string; agreementAmount: number }) => {
  //     return {
  //       ...item,
  //       lastReviewDate: item.lastReviewDate ? dayjs(item.lastReviewDate).format('YYYY-MM-DD') : item.lastReviewDate, // 最近复查日期
  //     }
  //   })
  //   total.value = parseInt(response.data.total)
  //   loadingTable.value = false
  // }).catch(() => {
  //   loadingTable.value = false
  // })
}
// 搜索
const searchList = () => {
  fetchData(true)
}

// 重置查询条件
const clearList = () => {
  datetimerange.value = []
  listQuery.value = {
    startTime: '',
    endTime: '',
    checked: false,
    offset: 1,
    limit: 20,
  }
}
// 多选发生改变时
function handleSelectionChange(e: any) {
  checkoutList.value = e.map((item: { id: string }) => item.id)
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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)
}
// 右上角菜单
const buttonBoxActive = 'QualityCorrect'
const menu = ref<any[]>([])
const active = ref<string>('全部')
// 查询字典
const getDict = async () => {
  // loadingTable.value = true
  // 审批状态
  const res = await getDictByCode('approvalStatus')
  // 制作右上角的菜单
  const tempMenu = ['全部', '已审批', '待审批', '审批', '草稿箱', '审批中', '已通过', '未通过', '已取消']
  tempMenu.forEach((item) => {
    const tempFindData = res.data.find((e: { name: string; value: string }) => e.name === item)
    if (tempFindData) {
      menu.value.push({
        name: tempFindData.name,
        id: `${tempFindData.value}`,
      })
      // active.value = tempFindData
    }
  })
}
const changeCurrentButton = (val: string) => {
  active.value = val
  window.sessionStorage.setItem(buttonBoxActive, val)
  clearList() // 刷新
}
// 新建
const $router = useRouter()
const handler = (type: string, row: any) => {
  $router.push({
    path: `/correcthandle/${type}`,
  })
}
onMounted(async () => {
  await getDict()
  if (window.sessionStorage.getItem(buttonBoxActive)) {
    active.value = window.sessionStorage.getItem(buttonBoxActive)!
  }
  else {
    active.value = menu.value.find(item => item.name === '全部')!.id as string // 全部
  }
  searchList()
})
</script>

<template>
  <app-container>
    <!-- 右上角按钮集合 -->
    <button-box :active="active" :menu="menu" @change-current-button="changeCurrentButton" />
    <search-area :need-clear="true" @search="searchList" @clear="clearList">
      <search-item>
        <el-input
          v-model="listQuery.storageLocation"
          placeholder="处理单编号"
        />
      </search-item>
      <search-item>
        <el-select
          v-model="listQuery.storageLocation"
          placeholder="实验室代码"
          class="short-input"
          filterable
          style="width: 100%;"
        >
          <el-option v-for="item in []" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-select
          v-model="listQuery.storageLocation"
          placeholder="责任部门"
          class="short-input"
          filterable
          style="width: 100%;"
        >
          <el-option v-for="item in []" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </search-item>
      <search-item>
        <el-input
          v-model="listQuery.storageLocation"
          placeholder="提出人"
        />
      </search-item>
      <search-item>
        <el-select
          v-model="listQuery.storageLocation"
          placeholder="输入来源"
          class="short-input"
          filterable
          style="width: 100%;"
        >
          <el-option v-for="item in []" :key="item.id" :label="item.name" :value="item.value" />
        </el-select>
      </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 v-if="active === '0'" #btns-right>
        <icon-button icon="icon-add" title="新建" type="primary" @click="handler('create', {})" />
        <icon-button icon="icon-export" title="导出" type="primary" />
      </template>
      <normal-table
        :data="tableList" :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">
            <template #default="scope">
              {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
        <template #columns>
          <el-table-column
            v-if="active === '0'"
            label="关联不符合要求情况分析报告"
            align="center"
          >
            <template #default="{ row }">
              {{ row }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="active !== '0'"
            label="审批状况"
            align="center"
          >
            <template #default="{ row }">
              {{ row }}
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            fixed="right"
          >
            <template #default="{ row }">
              <el-button
                size="small"
                type="primary"
                link
              >
                详情 {{ row }}
              </el-button>
              <el-button
                size="small"
                type="primary"
                link
              >
                编辑
              </el-button>
              <el-button
                v-if="active === '1'"
                size="small"
                type="danger"
                link
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>