Newer
Older
xc-business-system / src / views / equipement / standard / checkItemClassification / list.vue
<!-- 核查项分类管理列表 -->
<script lang="ts" setup name="checkItemClassificationList">
import type { Ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { IList, IListQuery } from './checkItemClassification-interface'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getDictByCode } from '@/api/system/dict'
import type { dictType } from '@/global'
import { delCheckItemClassification, getCheckItemClassificationList } from '@/api/equipment/standard/checkItemClassification'
const $router = useRouter()
const loadingTable = ref(false)
const operateWidth = ref('180') // 操作栏的宽度
// 查询条件
const listQuery: Ref<IListQuery> = ref({
  belongStandardEquipment: '', // 核查标准装置
  categoryName: '', // 核查项分类名称
  categoryNo: '', // 核查项分类编号
  equipmentType: '', // 标准装置分类
  limit: 20,
  offset: 1,
})

// 表头
const columns = ref<TableColumn[]>([
  { text: '标准装置分类', value: 'equipmentTypeName', align: 'center', width: '120' },
  { text: '核查标准装置', value: 'belongStandardEquipmentName', align: 'center' },
  { text: '核查项分类名称', value: 'categoryName', align: 'center' },
])
const list = ref<IList[]>([]) // 列表
const total = ref(0) // 数据总条数
const checkoutList = ref<string[]>([]) // 选中的内容
// ------------------------------------------字典----------------------------------------------
const equipmentTypeList = ref<dictType[]>([])// 标准装置分类
const standardList = ref<dictType[]>([])// 检校标准装置
const standardMap = ref({}) as any// 检校标准装置

async function getDict() {
  // 标准装置分类
  getDictByCode('bizEquipmentCategory').then((response) => {
    equipmentTypeList.value = response.data
  })

  // 检校标准装置
  const res = await getDictByCode('bizStandardEquipmentType')
  res.data.forEach((item: { value: string; name: string }) => {
    standardMap.value[`${item.value}`] = item.name
  })
  standardList.value = res.data
}
// ---------------------------------------------------------------------------------------------

// 多选发生改变时
function handleSelectionChange(e: any) {
  checkoutList.value = e.map((item: { id: string }) => item.id)
}

// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getCheckItemClassificationList(listQuery.value).then((response) => {
    list.value = response.data.rows.map((item: any) => {
      return {
        ...item,
        belongStandardEquipmentName: standardMap.value[`${item.belongStandardEquipment}`],
      }
    })
    total.value = parseInt(response.data.total)
    loadingTable.value = false
  })
}

// 清除条件
const clearList = () => {
  listQuery.value = {
    belongStandardEquipment: '', // 核查标准装置
    categoryName: '', // 核查项分类名称
    categoryNo: '', // 核查项分类编号
    equipmentType: '', // 标准装置分类
    limit: 20,
    offset: 1,
  }
  fetchData()
}

// 搜索
const searchList = () => {
  fetchData(true)
}

// 新建
const add = () => {
  $router.push({
    path: 'checkItemClassification/add',
  })
}

// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
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 handleEdit = (row: IList, type: 'detail' | 'edit' | 'del') => {
  if (type === 'del') { // 删除
    ElMessageBox.confirm(
      '确认删除吗?',
      '提示',
      {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      },
    )
      .then(() => {
        loadingTable.value = true
        delCheckItemClassification({ id: row.id }).then((res) => {
          ElMessage.success('已删除')
          loadingTable.value = false
          fetchData()
        })
      })
  }
  else {
    $router.push({
      path: `checkItemClassification/${type}/${row.id}`,
      query: {
        ...row,
      },
    })
  }
}

// ---------------------------------------钩子----------------------------------------------
onMounted(async () => {
  getDict().then(() => {
    fetchData(false)
  })
})
</script>

<template>
  <div>
    <!-- 布局 -->
    <app-container>
      <search-area :need-clear="true" @search="searchList" @clear="clearList">
        <search-item>
          <el-select
            v-model="listQuery.equipmentType"
            placeholder="标准装置分类"
            class="short-input"
            filterable
          >
            <el-option v-for="item in equipmentTypeList" :key="item.id" :label="item.name" :value="item.value" />
          </el-select>
        </search-item>
        <search-item>
          <el-select
            v-model="listQuery.belongStandardEquipment"
            placeholder="核查标准装置"
            filterable
            class="short-input"
          >
            <el-option v-for="item in standardList" :key="item.id" :label="item.name" :value="item.value" />
          </el-select>
        </search-item>
        <search-item>
          <el-input v-model.trim="listQuery.categoryName" placeholder="核查项分类名称" class="short-input" clearable />
        </search-item>
      </search-area>
      <table-container>
        <template #btns-right>
          <icon-button icon="icon-add" title="新建" type="primary" @click="add" />
        </template>
        <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">
              <template #default="scope">
                {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }}
              </template>
            </el-table-column>
          </template>
          <template #columns>
            <el-table-column
              label="操作"
              align="center"
              fixed="right"
              :width="operateWidth"
            >
              <template #default="{ row }">
                <el-button
                  size="small"
                  type="primary"
                  link
                  @click="handleEdit(row, 'detail')"
                >
                  详情
                </el-button>
                <el-button
                  size="small"
                  link
                  type="primary"
                  @click="handleEdit(row, 'edit')"
                >
                  编辑
                </el-button>
                <el-button
                  size="small"
                  link
                  type="danger"
                  @click="handleEdit(row, 'del')"
                >
                  删除
                </el-button>
              </template>
            </el-table-column>
          </template>
        </normal-table>
      </table-container>
    </app-container>
  </div>
</template>