// 引入Day.js库
const dayjs = require('dayjs');
// 获取本月日期列表的函数
function getDatesInMonth() {
    let year = dayjs().year()
    let month = dayjs().month()
    const dates = [];
    const startDate = dayjs(new Date(year, month, 1));
    const endDate = dayjs(new Date(year, month + 1, 1)).subtract(1, 'day');
    let currentDate = startDate;
    while (currentDate.isBefore(endDate) || currentDate.isSame(endDate, 'day')) {
        dates.push(currentDate.format('YYYY-MM-DD'));
        currentDate = currentDate.add(1, 'day');
    }
    return dates;
}

let statusOpt = [
      { label: '生产中', value: '5' },
      { label: '已完成', value: '6' },
      { label: '已延期', value: '7' },
    ]

let daysOpt = [
    { label: '已延期', value: -1},
    { label: '已完成', value: 0},
]

export const columns = [

    {
        columnKey: 'index',
        label: '序号',
        type: 'index',
        width: 55,
        align: 'center',
        showOverflowTooltip: true,
        fixed: 'left'
    },
    {
        prop: 'batchNo',
        label: '批次号',
        align: 'center',
        showOverflowTooltip: true,
    },
    {
        prop: 'code',
        label: '生产工单编码',
        align: 'center',
        showOverflowTooltip: true,
    },
    {
        prop: 'status',
        label: '工单状态',
        align: 'center',
        showOverflowTooltip: true,
        formatter: (row) => {
            let result = statusOpt.find(item => item.value == row.status)
            return result ? result.label : ''
        }
    },
    {
        prop: 'planStartTime',
        label: '计划开始时间',
        minWidth: '120',
        align: 'center',
        showOverflowTooltip: true,
    },
    {
        prop: 'planCompleteTime',
        label: '计划完成时间',
        minWidth: '120',
        align: 'center',
        showOverflowTooltip: true,
    },
    {
        prop: 'productName',
        label: '产品名称',
        align: 'center',
        showOverflowTooltip: true,
    }, {
        prop: 'productCode',
        label: '产品编码',
        align: 'center',
        showOverflowTooltip: true,
    }, 
    // {
    //     prop: 'specification',
    //     label: '规格型号',
    //     align: 'center',
    //     showOverflowTooltip: true,
    // }, 
    {
        prop: 'formingNum',
        label: '数量（个）',
        align: 'center',
        showOverflowTooltip: true,
    }, {
        prop: 'taskName',
        label: '生产工序',
        align: 'center',
        showOverflowTooltip: true,
    }, {
        prop: 'days',
        label: '交期状态',
        align: 'center',
        showOverflowTooltip: true,
        formatter: (row) => {
            let result = daysOpt.find(item => item.value == row.days)
            return result ? result.label : row.days ? '剩余' + row.days + '天' : ''
        }
    },

];

export const barOption = (series, itemStyle = {}) => {
    return {
        tooltip: {
            formatter: (item) => {
                return item.name + "：" + item.seriesName + " " + item.value + '个'
            },
            trigger: 'item'
        },
        legend: {
            // bottom: '2%',
            itemGap: window.innerHeight * 0.014,

            textStyle: {
                fontSize: window.innerHeight * 0.013,
            }
        },
        color: ['#1890ff'],
        xAxis: {
            type: 'category',
            data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月',],
            axisLabel: {
                fontSize: window.innerHeight * 0.012,
            }

        },
        yAxis: [
            {
                type: 'value',
                name: '(个)',
                nameTextStyle: {
                    align: 'center',
                    color: "#333",
                    fontSize: window.innerHeight * 0.012,
                    padding: [0, 20, -3, 0]
                },
            }
        ],
        series
    }
}

export const pieOption = (data) => {
    return {
        color: ['#398f4e', '#458ef7', '#fdc537', '#fe6869', '#975fe6'],
        tooltip: {
            formatter: '{b}：{c}' + '%',
            trigger: 'item'
        },
        legend: {
            orient: 'horizontal',
            left: 'right',
            right: '15%',
            bottom: '5%',
            itemGap: window.innerHeight * 0.018,
            textStyle: {
                fontSize: window.innerHeight * 0.014,
            }
        },
        series: [
            {
                center: ['50%', '40%'],
                label: {
                    position: 'outside',
                    show: true,
                    formatter: (item) => {
                        return item.name + "：" + item.value + '%'
                    },
                    fontSize: window.innerHeight * 0.014,
                    // color:"#fff"
                },
                labelLine: {
                    show: true,

                },
                type: 'pie',
                radius: '60%',
                itemStyle: {
                    borderWidth: 0,
                    shadowBlur: 10,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                },
                data
            }
        ]
    }
}

