<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="周二是否考勤" prop="tuesday" v-model="form.tuesday" type="select" :enumData="dict.tuesday" placeholder="请选择周二是否考勤"/>
                            <Field label="周三是否考勤" prop="wednesday" v-model="form.wednesday" type="select" :enumData="dict.wednesday" placeholder="请选择周三是否考勤"/>
                            <Field label="周四是否考勤" prop="thursday" v-model="form.thursday" type="select" :enumData="dict.thursday" placeholder="请选择周四是否考勤"/>
                            <Field label="周五是否考勤" prop="friday" v-model="form.friday" type="select" :enumData="dict.friday" placeholder="请选择周五是否考勤"/>
                            <Field label="周六是否考勤" prop="saturday" v-model="form.saturday" type="select" :enumData="dict.saturday" placeholder="请选择周六是否考勤"/>
                            <Field label="周日是否考勤" prop="sunday" v-model="form.sunday" type="select" :enumData="dict.sunday" placeholder="请选择周日是否考勤"/>
                            <Field label="法定节假日自动排休" prop="holidays" v-model="form.holidays" type="select" :enumData="dict.holidays" placeholder="请选择法定节假日自动排休"/>
                            <Field label="工作时长，单位小时" prop="workTime" v-model="form.workTime" 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="handleAddAttendanceGroupFreeworkSpecial">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteAttendanceGroupFreeworkSpecial">删除</el-button>
                    </el-col>
                </el-row>

                <el-table :data="attendanceGroupFreeworkSpecialList" :row-class-name="rowAttendanceGroupFreeworkSpecialIndex" @selection-change="handleAttendanceGroupFreeworkSpecialSelectionChange" ref="attendanceGroupFreeworkSpecial">
                    <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 {
                // 子表选中数据
                checkedAttendanceGroupFreeworkSpecial: [],
                // 考勤组考勤自由工时特殊日期配置表格数据
                attendanceGroupFreeworkSpecialList: [],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "考勤组考勤自由工时配置",
                // 是否显示弹出层
                open: false,
                toString:[
                    "monday",
                    "tuesday",
                    "wednesday",
                    "thursday",
                    "friday",
                    "saturday",
                    "sunday",
                    "holidays",
                ],
                // 表单校验
                rules: {
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 考勤组考勤自由工时特殊日期配置序号 */
            rowAttendanceGroupFreeworkSpecialIndex({ row, rowIndex }) {
                row.index = rowIndex + 1;
            },
            /** 考勤组考勤自由工时特殊日期配置添加按钮操作 */
            handleAddAttendanceGroupFreeworkSpecial() {
                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.attendanceGroupFreeworkSpecialList.push(obj);
            },
            /** 考勤组考勤自由工时特殊日期配置删除按钮操作 */
            handleDeleteAttendanceGroupFreeworkSpecial() {
                if (this.checkedAttendanceGroupFreeworkSpecial.length == 0) {
                    this.$alert("请先选择要删除的考勤组考勤自由工时特殊日期配置数据", "提示", { confirmButtonText: "确定", });
                } else {
                    this.attendanceGroupFreeworkSpecialList.splice(this.checkedAttendanceGroupFreeworkSpecial[0].index - 1, 1);
                }
            },
            /** 单选框选中数据 */
            handleAttendanceGroupFreeworkSpecialSelectionChange(selection) {
                if (selection.length > 1) {
                    this.$refs.attendanceGroupFreeworkSpecial.clearSelection();
                    this.$refs.attendanceGroupFreeworkSpecial.toggleRowSelection(selection.pop());
                } else {
                    this.checkedAttendanceGroupFreeworkSpecial = selection;
                }
            },
            // 渲染前置处理
            beforeRender(data) {
                if(data.entity.attendanceGroupFreeworkSpecialList) {
                    this.attendanceGroupFreeworkSpecialList = data.entity.attendanceGroupFreeworkSpecialList;
                }
                return data
            },
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="attendance/group/freework/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改考勤组考勤自由工时配置";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "attendance/group/freework/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增考勤组考勤自由工时配置";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="attendance/group/freework/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,
                    tuesday : 0,
                    wednesday : 0,
                    thursday : 0,
                    friday : 0,
                    saturday : 0,
                    sunday : 0,
                    holidays : 1,
                    workTime : 0,
                    remark : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
