Newer
Older
xc-business-system / src / views / resource / software / info / list.vue
tanyue on 30 Nov 2023 5 KB 20231130 软件修订申请
<!-- 软件一览表 -->
<script name="SoftwareInfoList" lang="ts" setup>
import type { DateModelType } from 'element-plus'
import { dayjs } from 'element-plus'
import type { IListQuery, ISoftwareInfo } from './software-info'
import type { TableColumn } from '@/components/NormalTable/table_interface'
import { getSoftwareInfoList } from '@/api/resource/software'

const { proxy } = getCurrentInstance() as any
const router = useRouter()

// 查询条件
const searchQuery = ref<IListQuery>({
  softwareName: '', // 软件名称
  softwareVersion: '',
  createUserName: '',
  updateTimeStart: '',
  updateTimeEnd: '',
  offset: 1,
  limit: 20,
})
const total = ref(0) // 数据条数
const loadingTable = ref(false) // 表格loading
const dateRange = ref<[DateModelType, DateModelType]>(['', ''])// 筛选时间段数据

// 表头
const columns = ref<TableColumn[]>([
  { text: '软件名称', value: 'softwareName', align: 'center' },
  { text: '当前版本号', value: 'softwareVersion', align: 'center', width: '200' },
  { text: '创建人', value: 'createUserName', align: 'center', width: '200' },
  { text: '更新时间', value: 'createTime', align: 'center', width: '200' },
])
const softwareList = ref<Array<ISoftwareInfo>>([]) // 表格数据

// 逻辑
// 详情
const detail = (row: ISoftwareInfo) => {
  router.push({
    query: {
      type: 'detail',
      id: row.id,
    },
    path: 'software/detail',
  })
}

// 详情
const update = (row: ISoftwareInfo) => {
  router.push({
    query: {
      type: 'update',
      id: row.id,
    },
    path: 'software/detail',
  })
}

// 数据查询
function fetchData(isNowPage = false) {
  loadingTable.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    searchQuery.value.offset = 1
  }
  getSoftwareInfoList(searchQuery.value).then((response) => {
    if (response.code === 200) {
      softwareList.value = response.data.rows.map((item: ISoftwareInfo) => {
        return {
          ...item,
        }
      })
      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) {
    searchQuery.value.limit = val.size
  }
  if (val && val.page) {
    searchQuery.value.offset = val.page
  }
  fetchData(true)
}

// 重置
const reset = () => {
  searchQuery.value = {
    softwareName: '', // 软件名称
    softwareVersion: '',
    createUserName: '',
    updateTimeStart: '',
    updateTimeEnd: '',
    offset: 1,
    limit: 20,
  }
  fetchData(true)
}

const getDict = async () => {

}

watch(dateRange, (val) => {
  if (val) {
    searchQuery.value.updateTimeStart = dayjs(val[0]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[0]).format('YYYY-MM-DD')
    searchQuery.value.updateTimeEnd = dayjs(val[1]).format('YYYY-MM-DD') === 'Invalid Date' ? '' : dayjs(val[1]).format('YYYY-MM-DD')
  }
  else {
    searchQuery.value.updateTimeStart = ''
    searchQuery.value.updateTimeEnd = ''
  }
})

onMounted(async () => {
  await getDict()
  searchList()
})
</script>

<template>
  <app-container>
    <!-- 筛选条件 -->
    <search-area :need-clear="true" @search="searchList" @clear="reset">
      <search-item>
        <el-input v-model="searchQuery.softwareName" placeholder="软件名称" clearable />
      </search-item>
      <search-item>
        <el-input v-model="searchQuery.softwareVersion" placeholder="软件版本" clearable />
      </search-item>
      <search-item>
        <el-input v-model="searchQuery.createUserName" placeholder="创建人" clearable />
      </search-item>
      <search-item>
        <el-date-picker v-model="dateRange" type="daterange" start-placeholder="更新时间(开始)" end-placeholder="更新时间(结束)" />
      </search-item>
    </search-area>

    <!-- 表格数据展示 -->
    <table-container title="软件一览表">
      <!-- 表格区域 -->
      <normal-table
        id="reportTabel"
        :data="softwareList" :total="total" :columns="columns"
        :query="{ limit: searchQuery.limit, offset: searchQuery.offset }"
        :list-loading="loadingTable"
        @change="changePage"
      >
        <template #preColumns>
          <el-table-column label="序号" width="55" align="center">
            <template #default="scope">
              {{ (searchQuery.offset - 1) * searchQuery.limit + scope.$index + 1 }}
            </template>
          </el-table-column>
        </template>
        <template #columns>
          <el-table-column fixed="right" label="操作" align="center" width="130">
            <template #default="{ row }">
              <el-button size="small" type="primary" link @click="detail(row)">
                详情
              </el-button>
              <el-button size="small" type="primary" link @click="update(row)">
                编辑
              </el-button>
            </template>
          </el-table-column>
        </template>
      </normal-table>
    </table-container>
  </app-container>
</template>