Newer
Older
xc-metering-front / src / views / tested / subpackage / certificate / index.vue
liyaguang on 28 Aug 2023 5 KB feat(*): 分包管理完成
<!-- 分包证书 -->
<script lang="ts" setup name="SubpackageCertificate">
import { reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { deleteCertificate, getListPage } from '@/api/eqpt/subpackage/certificate'
const { proxy } = getCurrentInstance() as any
const listQuery = reactive({
  certificateName: '',
  certificateNo: '',
  createTimeEnd: '',
  createTimeStart: '',
  equipmentName: '',
  equipmentNo: '',
  subcontractorName: '',
  offset: 1,
  limit: 20,
})
const datetimerange = ref()
watch(() => datetimerange.value, (newVal) => {
  if (newVal.length === 2) {
    listQuery.createTimeStart = newVal[0]
    listQuery.createTimeEnd = newVal[1]
  }
}, {
  deep: true,
})
const columns = ref([
  {
    text: '证书号',
    value: 'certificateNo',
    align: 'center',
  },
  {
    text: '证书名称',
    value: 'certificateName',
    align: 'center',
  },
  {
    text: '样品编号',
    value: 'equipmentNo',
    align: 'center',
  },
  {
    text: '样品名称',
    value: 'equipmentName',
    align: 'center',
  },
  {
    text: '型号',
    value: 'equipmentModel',
    align: 'center',
  },
  {
    text: '出厂编号',
    value: 'equipmentManufactureNo',
    align: 'center',
  },
  {
    text: '检测单位',
    value: 'subcontractorName',
    align: 'center',
  },
  {
    text: '创建时间',
    value: 'createTime',
    align: 'center',
  },
])
const list = ref([])
const total = ref(0)
const listLoading = ref(true)

// 获取数据
const fetchData = (isNowPage = true) => {
  listLoading.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.offset = 1
  }
  getListPage(listQuery).then((response) => {
    list.value = response.data.rows
    total.value = parseInt(response.data.total)
    listLoading.value = false
  })
}
fetchData()
// 查询数据
const search = () => {
  fetchData(false)
}
// 重置
const reset = () => {
  datetimerange.value = ''
  listQuery.certificateName = ''
  listQuery.certificateNo = ''
  listQuery.createTimeEnd = ''
  listQuery.createTimeStart = ''
  listQuery.equipmentName = ''
  listQuery.equipmentNo = ''
  listQuery.subcontractorName = ''
  listQuery.offset = 1
  listQuery.limit = 20
  search()
}
// 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
const changePage = (val: { size: number; page: number }) => {
  if (val && val.size) {
    listQuery.limit = val.size
  }
  if (val && val.page) {
    listQuery.offset = val.page
  }
  fetchData()
}
const $router = useRouter()
// 新建编辑操作
const handler = (row: any, type: string) => {
  $router.push({
    path: `/pcertificatepage/${type}`,
    query: {
      row: JSON.stringify(row),
      id: row.id,
    },
  })
}
// 删除
const delHandler = (row: any) => {
  ElMessageBox.confirm(
    '确认删除吗?',
    '确认',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    },
  ).then(() => {
    deleteCertificate(row.id).then((res) => {
      ElMessage.success('操作成功')
      search()
    })
  })
}
</script>

<template>
  <app-container>
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="search" @clear="reset">
      <search-item>
        <el-input v-model.trim="listQuery.certificateNo" placeholder="证书号" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.certificateName" placeholder="证书名称" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.equipmentNo" placeholder="受检设备编号" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.equipmentName" placeholder="受检设备名称" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.subcontractorName" placeholder="检测单位" clearable />
      </search-item>
      <search-item>
        <el-date-picker
          v-model="datetimerange" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss"
          format="YYYY-MM-DD HH:mm:ss" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间"
        />
      </search-item>
    </search-area>
    <table-container>
      <template #btns-right>
        <icon-button icon="icon-add" title="新增" @click="handler({}, 'create')" />
      </template>
      <!-- 普通表格 -->
      <normal-table
        :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="listLoading"
        :is-showmulti-select="true" @change="changePage"
      >
        <template #columns>
          <el-table-column label="操作" width="160" align="center">
            <template #default="scope">
              <el-button link type="primary" size="small" @click="handler(scope.row, 'detail')">
                查看
              </el-button>
              <el-button link type="primary" size="small" @click="handler(scope.row, 'update')">
                编辑
              </el-button>
              <el-button link type="danger" size="small" @click="delHandler(scope.row)">
                删除
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>