export const getTableDataPage = (param, dataArrys) => {
// param分页查询参数,dataArrys分页数据
return new Promise((resolve) => {
const { pageNum, pageSize, condition } = { ...param }
// 先查询符合条件的数据
let isSearchForm = false
const searchData = []
for(let key in condition) {
if (condition[key]) {
isSearchForm = true
}
}
if (isSearchForm) {
dataArrys.forEach(item => {
let isEqual = true
for(let key in condition) {
if (condition[key] && item[key] !== condition[key]) {
isEqual = false
}
}
if (isEqual) {
searchData.push(item)
}
})
dataArrys = searchData
}
// 再做分页,返回数据
const startIndex = pageNum === 1 ? pageNum-1: (pageNum-1)*10
const endIndex = startIndex + pageSize
let total = 0
let records = []
if (dataArrys) {
total = dataArrys.length
records = dataArrys.slice(startIndex, endIndex)
}
const pages = Math.ceil(total / pageSize)
const response = {
pageNum: pageNum,
pageSize: pageSize,
pages: pages,
data: records,
total: total,
}
resolve(response)
})
}