'sort-change': ({ column, prop, order }) => {
const orderType = {
ascending: 1,
descending: -1
}
const { label } = column
if (label === '星期') {
console.log('星期')
this.tableData.sort((a, b) => {
const aXingQi = this.$tools.formatDate(a.shangBanSJ, '{a}')
const bXingQi = this.$tools.formatDate(b.shangBanSJ, '{a}')
return aXingQi.localeCompare(bXingQi) * orderType[order]
})
} else if (label === '班次') {
this.tableData.sort((a, b) => {
const aHour = this.$tools.formatDate(a.shangBanSJ, '{h}') < 12 ? '上午' : '下午'
const bHour = this.$tools.formatDate(b.shangBanSJ, '{h}') < 12 ? '上午' : '下午'
return aHour.localeCompare(bHour) * orderType[order]
})
} else {
this.tableData.sort((a, b) => {
return a[prop]?.toString().localeCompare(b[prop].toString()) * orderType[order]
})
}
// if (order === 'descending') {
// // 降序
// this.tableData.sort((a, b) => {
// console.log('a[prop]', a[prop])
// return a[prop].localeCompare(b[prop]) * orderType[order]
// })
// } else if (order === 'ascending') {
// // 升序
// this.tableData.sort((a, b) => {
// console.log('a[prop]', a[prop])
// return a[prop].localeCompare(b[prop]) * orderType[order]
// })
// }
},
03-23
362
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交