import { getDict } from "@/utils/dictionary";
import { toDate } from "@/utils/date";
import { time2str } from "@/utils/index";
export default {
    data() {
        return {
            page: 1,
            total: 10,
            size: 10,
            tableData: [],
            searchInfo: {
				isFinish:0
            }
        }
    },
    watch: {
        
    },
    methods: {
        filterDict(value, type) {
            const rowLabel = this[type + "Options"] && this[type + "Options"].filter(item => item.value == value)
            return rowLabel && rowLabel[0] && rowLabel[0].label
        },
        async getDict(type) {
            const dicts = await getDict(type)
            this[type + "Options"] = dicts
            return dicts
        },
        handleSizeChange(val) {
            this.size = val
            this.getTableData()
        },
        handleCurrentChange(val) {
            this.page = val
            this.getTableData()
        },
		handleSelectAll( table ) {
			console.log("handleSelectAll", table)
		    this[table].forEach(item => {
		      item._selected = true
		    })
		},
		handleSelectNull( table ) {
			console.log("handleSelectNull", table)
		    this[table].forEach(item => {
		      item._selected = false
		    })
		},
		handleChangeItem( table, index, cb ) {
		    this[table][index] = cb( this[table][index])
		},
        async getTableData(page = this.page, size = this.size) {
			let from = (page-1) * size
            let param = { size, from, ...this.searchInfo }
            const table = await this.listApi(param)
            if (table.code == 200) {
                this.tableData = table.data.list.map(item=>{
					item.edit = false
					item._selected = false
					return item;
				})
                this.total = table.data.total
            }
        }
    }
}