FactoryCalendar.js 7.22 KB
layui.config({
    base: "/js/",
    version: 4444
}).use(["system", "vue"], function () {
    var form = layui.form,
        $ = layui.jquery,
        table = layui.table,
        element = layui.element,
        system = layui.system,
        sysU = new system.u(),
        areaName = "Planned",
        tableName = "FactoryCalendar",
        vueApp = null;
    var app = {
        data: {
            tableIns: null,
            selectData: $("#selectData"),
            content: $(".content"),
            factoryCalendarDesc: $("#factoryCalendarDesc"),

            calendarEl: document.getElementById("calendar"),
            calendarObj: null
        },
        methods: {
            initVue: function () {
                vueApp = new Vue({
                    el: '#factoryCalendarDesc',
                    data: {
                        statrCalendarDay: "",
                        endCalendarDay: "",
                        actionClass: "",
                        isWeekday: "",
                        shiftCode: "",

                        shiftName: "",
                        actionRange: "",
                        effectiveDate: "",
                        deadlineDate: "",
                        remarks: "",

                        timeSpanStart: "",
                        timeSpanEnd: "",
                        state: "",

                        selectAll: false,
                        nowdate:"",
                        noProductiontime: []
                    },
                    methods: {
                        //设置线体是否工作日
                        setLineWork: (item) => {
                            var ajaxConfig = {
                                data: item,
                                url: `/${areaName}/${tableName}/SetCalendarLineList`,
                                success: function (result) {
                                    setTimeout(() => { app.methods.setFromHide(result); });
                                    app.methods.factoryCalendarViewDesc(vueApp.nowdate);
                                }
                            };
                            sysU.ajax(ajaxConfig);

                        },
                        setLineWorkAll: (selectAll) => {
                            vueApp.noProductiontime.forEach(x => {
                                x.Weekday = vueApp.selectAll;    
                            }); 
                            var ajaxConfig = {
                                data: {
                                    datetime: vueApp.nowdate,
                                    lineCode: vueApp.noProductiontime.GetArrValue("lineCode"),
                                    Weekday: vueApp.selectAll
                                },
                                url: `/${areaName}/${tableName}/SetCalendarLineList`,
                                success: function (result) {
                                    app.methods.setFromHide(result); 
                                }
                            };
                            sysU.ajax(ajaxConfig);
                        }
                    }
                });
            },

            //获取日历数据,并初始化日历
            getFactoryCalendarList: function (value, date, endDate, thisInfo) {
                var ajaxConfig = {
                    data: { datetime: value, condition: "month" },
                    url: `/${areaName}/${tableName}/GetFactoryCalendarList`,
                    success: function (result) {
                        if (sysU.successBefore(result)) return;
                        app.methods.initCalendar(value, result);
                        setTimeout(() => { app.methods.setFromHide(result); });
                    }
                };
                sysU.ajax(ajaxConfig);
            },

            initCalendar: (initialDate, result) => {
                $(app.data.calendarEl).empty();
                app.data.calendarObj = new FullCalendar.Calendar(app.data.calendarEl, {
                    plugins: ['interaction', 'dayGrid', 'timeGrid'],
                    dayMaxEvents: true,
                    height: app.data.content.height() - 50,
                    locale: "zh-cn",
                    header: null,
                    defaultDate: initialDate,
                    selectable: true,
                    selectMirror: true,
                    select: function (e) {
                        vueApp.nowdate = e.startStr;
                        app.methods.factoryCalendarViewDesc(e.startStr);
                    },
                    //查看明细此处 e.event._def.xxxx
                    eventClick: function (e) {
                        //var id = e.event._def.publicId;
                    },
                    editable: true,
                    eventLimit: true, // allow "more" link when too many events
                    events: result
                });
                app.data.calendarObj.render();
            },

            //日历明细点击,右侧明细
            factoryCalendarViewDesc: (date) => {
                var ajaxConfig = {
                    data: {
                        datetime:date,
                        condition:"day"
                    },
                    url: `/${areaName}/${tableName}/GetFactoryCalendarList`,
                    success: function (result) {
                        var flag = 0;
                        result.data.forEach(x => {
                            x["datetime"] = date;
                            if (x.Weekday == true) {
                                flag++;
                            }
                        });
                        vueApp.selectAll = flag == result.data.length;
                        vueApp.noProductiontime = result.data;
                    }
                };
                sysU.ajax(ajaxConfig);
            },
           
            initForm: () => {
                app.data.factoryCalendarDesc.height = app.data.content.height()-100;
            },

            //设置选中颜色
            setFromHide: (result) => {
                //$(".fc-content").parent("a").hide();
                var dayBg = $("td .fc-day"),
                    dayTd = $(".fc-day-number"),
                    workList = result.data.copy();
                dayBg.removeClass("calendar-day-bg");
                dayTd.removeClass("calendar-td-color");
                for (var xp = 0; xp < workList.length; xp++) {
                    for (var i = 0; i < dayBg.length; i++) {
                        var $dayBg = $(dayBg[i]),
                            dayValue = new Date(workList[xp].start).format("yyyy-MM-dd");
                        if (dayValue == $dayBg.attr("data-date") && workList[xp].Weekday == true) {
                            $(dayTd[i]).addClass("calendar-td-color");
                            $dayBg.addClass("calendar-day-bg");
                            break;
                        }
                    }
                }
            }
        },
        registerEvent: function () {

        },
        init: function () {
            sysU.initDate(app.methods.getFactoryCalendarList);
            app.methods.getFactoryCalendarList(app.data.selectData.val());
            app.methods.initVue();
            app.methods.initForm();
        }
    };
    app.init();
});