import { reactive } from 'vue'
import dayjs from 'dayjs'

// 月计划列表搜索表单配置
export const buildFormColumns = (
    inspectionStationOptions,
    majorOptions,
    businessTypeOptions,
    riskLevelOptions,
) => [
    {
        type: 'month',
        prop: 'monthlyPlan',
        placeholder: '请选择月份',
        defaultValue: dayjs().format('YYYY-MM'), // 默认当前月份
    },
    {
        type: 'select',
        prop: 'inspectionStationId',
        placeholder: '请选择运检站',
        options: inspectionStationOptions.map((item) => ({
            label: item.value,
            value: item.id,
        })),
    },
    {
        type: 'input',
        prop: 'keyWord',
        placeholder: '请输入关键字',
    },
    {
        type: 'select',
        prop: 'planMajorId',
        placeholder: '请选择专业',
        options: majorOptions.map((item) => ({
            label: item.planMajorName,
            value: item.planMajorId,
        })),
    },
    {
        type: 'select',
        prop: 'businessTypeId',
        placeholder: '请选择业务类型',
        options: businessTypeOptions.map((item) => ({
            label: item.planMajorName,
            value: item.planMajorId,
        })),
    },
    {
        type: 'select',
        prop: 'riskLevel',
        placeholder: '请选择风险等级',
        options: riskLevelOptions,
    },
]

// 月计划列表表格列
export const tableColumns = [
    { prop: 'inspectionStationName', label: '运检站', fixed: true, width: '200' },
    { prop: 'planMajorName', label: '专业', fixed: true },
    { prop: 'businessTypeName', label: '业务类型', fixed: true },
    { prop: 'projectName', label: '项目名称', fixed: true, width: '200' },
    { prop: 'workContent', label: '工作任务', width: '200' },
    { prop: 'riskLevel', label: '风险等级' },
    { prop: 'planCategoryName', label: '类别' },
    { prop: 'workAmount', label: '工作量', width: '200', slot: 'workAmount' },
    { prop: 'towerBaseNumber', label: ' 塔基数' },
    { prop: 'plannedStartTime', label: '计划开始时间', width: '140' },
    { prop: 'plannedEndTime', label: '计划结束时间', width: '140' },
    {
        prop: 'planPersonnel',
        label: '计划投入管理人员数量',
        formatter: (row) => {
            return row.personneltList?.length || ''
        },
    },

    { prop: 'planCarNum', label: '计划投入管理人员车辆数' },
    { prop: 'planSkilledWorkerNum', label: '计划投入熟练工人员数量' },
    {
        prop: 'planSkilledWorkerDay',
        label: '计划投入熟练工人员工日',
        // 使用dayjs 根据开始时间和结束时间计算出工日 * 计划投入熟练工人员工日
        formatter: (row) => {
            return (
                (dayjs(row.plannedEndTime).diff(dayjs(row.plannedStartTime), 'day') + 1) *
                    row.planSkilledWorkerDay || ''
            )
        },
    },
    { prop: 'planAuxiliaryWorkerNum', label: '计划投入辅助工人员数量' },
    {
        prop: 'planAuxiliaryWorkerDay',
        label: '计划投入辅助工人员工日',
        // 使用dayjs 根据开始时间和结束时间计算出工日 * 计划投入熟练工人员工日
        formatter: (row) => {
            return (
                (dayjs(row.plannedEndTime).diff(dayjs(row.plannedStartTime), 'day') + 1) *
                    row.planAuxiliaryWorkerDay || ''
            )
        },
    },
    { prop: 'planSubCarNum', label: '计划投入分包车辆数' },
    { prop: 'actualWorkingDay', label: '实际工作天数' },
]

export const dialogConfig = reactive({
    outerVisible: false,
    outerTitle: '添加计划任务',
    outerWidth: '70%', // 根据图片缩小宽度更美观
    minHeight: '70vh',
    maxHeight: '90vh',
})

export default {
    tableColumns,
    dialogConfig,
    buildFormColumns,
}
