<template>
    <!-- 弹出框表单 -->
    <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                                            <Field label="考勤组" prop="groupId" v-model="form.groupId" placeholder="请输入考勤组"/>
                            <Field label="考勤组名称" prop="groupName" v-model="form.groupName" placeholder="请输入考勤组名称"/>
                            <Field label="周一是否考勤" prop="monday" v-model="form.monday" type="select" :enumData="dict.monday" placeholder="请选择周一是否考勤"/>
                            <Field label="周一班次ID" prop="mondayClassId" v-model="form.mondayClassId" placeholder="请输入周一班次ID"/>
                            <Field label="周一班次名称" prop="mondayClassName" v-model="form.mondayClassName" placeholder="请输入周一班次名称"/>
                            <Field label="周二是否考勤" prop="tuesday" v-model="form.tuesday" type="select" :enumData="dict.tuesday" placeholder="请选择周二是否考勤"/>
                            <Field label="周二班次ID" prop="tuesdayClassId" v-model="form.tuesdayClassId" placeholder="请输入周二班次ID"/>
                            <Field label="周二班次名称" prop="tuesdayClassName" v-model="form.tuesdayClassName" placeholder="请输入周二班次名称"/>
                            <Field label="周三是否考勤" prop="wednesday" v-model="form.wednesday" type="select" :enumData="dict.wednesday" placeholder="请选择周三是否考勤"/>
                            <Field label="周三班次ID" prop="wednesdayClassId" v-model="form.wednesdayClassId" placeholder="请输入周三班次ID"/>
                            <Field label="周三班次名称" prop="wednesdayClassName" v-model="form.wednesdayClassName" placeholder="请输入周三班次名称"/>
                            <Field label="周四是否考勤" prop="thursday" v-model="form.thursday" type="select" :enumData="dict.thursday" placeholder="请选择周四是否考勤"/>
                            <Field label="周四班次ID" prop="thursdayClassId" v-model="form.thursdayClassId" placeholder="请输入周四班次ID"/>
                            <Field label="周四班次名称" prop="thursdayClassName" v-model="form.thursdayClassName" placeholder="请输入周四班次名称"/>
                            <Field label="周五是否考勤" prop="friday" v-model="form.friday" type="select" :enumData="dict.friday" placeholder="请选择周五是否考勤"/>
                            <Field label="周五班次ID" prop="fridayClassId" v-model="form.fridayClassId" placeholder="请输入周五班次ID"/>
                            <Field label="周五班次名称" prop="fridayClassName" v-model="form.fridayClassName" placeholder="请输入周五班次名称"/>
                            <Field label="周六是否考勤" prop="saturday" v-model="form.saturday" type="select" :enumData="dict.saturday" placeholder="请选择周六是否考勤"/>
                            <Field label="周六班次ID" prop="saturdayClassId" v-model="form.saturdayClassId" placeholder="请输入周六班次ID"/>
                            <Field label="周六班次名称" prop="saturdayClassName" v-model="form.saturdayClassName" placeholder="请输入周六班次名称"/>
                            <Field label="周日是否考勤" prop="sunday" v-model="form.sunday" type="select" :enumData="dict.sunday" placeholder="请选择周日是否考勤"/>
                            <Field label="周日班次ID" prop="sundayClassId" v-model="form.sundayClassId" placeholder="请输入周日班次ID"/>
                            <Field label="周日班次名称" prop="sundayClassName" v-model="form.sundayClassName" placeholder="请输入周日班次名称"/>
                            <Field label="法定节假日自动排休" prop="holidays" v-model="form.holidays" type="select" :enumData="dict.holidays" placeholder="请选择法定节假日自动排休"/>
                            <Field label="备注" prop="remark" v-model="form.remark" type="textarea" placeholder="请输入备注"/>

            </el-row>
                <el-divider content-position="center">考勤组考勤固定班制特殊日期配置信息</el-divider>
                <br/>
                <el-row :gutter="10" class="mb8">
                    <el-col :span="1.5">
                        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddAttendanceGroupFixedworkSpecial">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteAttendanceGroupFixedworkSpecial">删除</el-button>
                    </el-col>
                </el-row>

                <el-table :data="attendanceGroupFixedworkSpecialList" :row-class-name="rowAttendanceGroupFixedworkSpecialIndex" @selection-change="handleAttendanceGroupFixedworkSpecialSelectionChange" ref="attendanceGroupFixedworkSpecial">
                    <el-table-column type="selection" width="50" align="center" />
                    <el-table-column label="序号" align="center" prop="index" width="50"/>
                            <el-table-column label="是否必须打卡的日期，当为1时有班次相关信息，否则有无需打卡时间段信息" prop="must">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.must" placeholder="请输入是否必须打卡的日期，当为1时有班次相关信息，否则有无需打卡时间段信息" />
                                </template>
                            </el-table-column>
                            <el-table-column label="班次ID" prop="classId">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.classId" placeholder="请输入班次ID" />
                                </template>
                            </el-table-column>
                            <el-table-column label="班次名称" prop="className">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.className" placeholder="请输入班次名称" />
                                </template>
                            </el-table-column>
                            <el-table-column label="无需打卡的日期类型" prop="addWay">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.addWay" placeholder="请输入无需打卡的日期类型" />
                                </template>
                            </el-table-column>
                            <el-table-column label="特殊时间" prop="specialTime">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.specialTime" placeholder="请输入特殊时间" />
                                </template>
                            </el-table-column>
                            <el-table-column label="时间段时候开始时间" prop="specialTimeStart">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.specialTimeStart" placeholder="请输入时间段时候开始时间" />
                                </template>
                            </el-table-column>
                            <el-table-column label="时间段结束时间" prop="specialTimeEnd">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.specialTimeEnd" placeholder="请输入时间段结束时间" />
                                </template>
                            </el-table-column>
                            <el-table-column label="备注" prop="remark">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.remark" placeholder="请输入备注" />
                                </template>
                            </el-table-column>
                            <el-table-column label="创建用户" prop="createUserId">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.createUserId" placeholder="请输入创建用户" />
                                </template>
                            </el-table-column>
                            <el-table-column label="创建时间" prop="createTime">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.createTime" placeholder="请输入创建时间" />
                                </template>
                            </el-table-column>
                            <el-table-column label="更新用户" prop="updateUserId">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.updateUserId" placeholder="请输入更新用户" />
                                </template>
                            </el-table-column>
                            <el-table-column label="更新时间" prop="updateTime">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.updateTime" placeholder="请输入更新时间" />
                                </template>
                            </el-table-column>
                </el-table>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" v-if="pageInfo.type !== 'view'" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import form from "@/assets/mixins/formdialog";
    import dialogShow from "./dialogshow";
    export default {
        mixins: [form],
        components: {
            dialogShow ,
        },
        data() {
            return {
                // 子表选中数据
                checkedAttendanceGroupFixedworkSpecial: [],
                // 考勤组考勤固定班制特殊日期配置表格数据
                attendanceGroupFixedworkSpecialList: [],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "考勤组考勤固定工时",
                // 是否显示弹出层
                open: false,
                toString:[
                    "monday",
                    "tuesday",
                    "wednesday",
                    "thursday",
                    "friday",
                    "saturday",
                    "sunday",
                    "holidays",
                ],
                // 表单校验
                rules: {
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 考勤组考勤固定班制特殊日期配置序号 */
            rowAttendanceGroupFixedworkSpecialIndex({ row, rowIndex }) {
                row.index = rowIndex + 1;
            },
            /** 考勤组考勤固定班制特殊日期配置添加按钮操作 */
            handleAddAttendanceGroupFixedworkSpecial() {
                let obj = {};
                obj.must = "";
                obj.classId = "";
                obj.className = "";
                obj.addWay = "";
                obj.specialTime = "";
                obj.specialTimeStart = "";
                obj.specialTimeEnd = "";
                obj.remark = "";
                obj.createUserId = "";
                obj.createTime = "";
                obj.updateUserId = "";
                obj.updateTime = "";
                this.attendanceGroupFixedworkSpecialList.push(obj);
            },
            /** 考勤组考勤固定班制特殊日期配置删除按钮操作 */
            handleDeleteAttendanceGroupFixedworkSpecial() {
                if (this.checkedAttendanceGroupFixedworkSpecial.length == 0) {
                    this.$alert("请先选择要删除的考勤组考勤固定班制特殊日期配置数据", "提示", { confirmButtonText: "确定", });
                } else {
                    this.attendanceGroupFixedworkSpecialList.splice(this.checkedAttendanceGroupFixedworkSpecial[0].index - 1, 1);
                }
            },
            /** 单选框选中数据 */
            handleAttendanceGroupFixedworkSpecialSelectionChange(selection) {
                if (selection.length > 1) {
                    this.$refs.attendanceGroupFixedworkSpecial.clearSelection();
                    this.$refs.attendanceGroupFixedworkSpecial.toggleRowSelection(selection.pop());
                } else {
                    this.checkedAttendanceGroupFixedworkSpecial = selection;
                }
            },
            // 渲染前置处理
            beforeRender(data) {
                if(data.entity.attendanceGroupFixedworkSpecialList) {
                    this.attendanceGroupFixedworkSpecialList = data.entity.attendanceGroupFixedworkSpecialList;
                }
                return data
            },
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="attendance/group/fixedwork/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改考勤组考勤固定工时";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "attendance/group/fixedwork/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增考勤组考勤固定工时";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="attendance/group/fixedwork/view";
                this.getData();
                this.pageInfo.type="view"
                this.title = "考勤组考勤固定工时详细";
            },
            /**取消按钮 */
            cancel() {
                this.open = false;
            },
            /**获取数据后弹框 */
            afterRender(data) {
                this.open = true;
            },

            afterSubmit(data) {
                this.open = false;
                this.$emit("ok");
            },

            // 表单重置
            reset() {
                this.form = {
                    groupId : null,
                    groupName : "",
                    monday : 0,
                    mondayClassId : null,
                    mondayClassName : "",
                    tuesday : 0,
                    tuesdayClassId : null,
                    tuesdayClassName : "",
                    wednesday : 0,
                    wednesdayClassId : null,
                    wednesdayClassName : "",
                    thursday : 0,
                    thursdayClassId : null,
                    thursdayClassName : "",
                    friday : 0,
                    fridayClassId : null,
                    fridayClassName : "",
                    saturday : 0,
                    saturdayClassId : null,
                    saturdayClassName : "",
                    sunday : 0,
                    sundayClassId : null,
                    sundayClassName : "",
                    holidays : 1,
                    remark : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
