<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="className" v-model="form.className" placeholder="请输入班次名称"/>
                            <Field label="班次负责人ID" prop="classResponsiblePersonId" v-model="form.classResponsiblePersonId" placeholder="请输入班次负责人ID"/>
                            <Field label="班次负责人名称" prop="classResponsiblePersonName" v-model="form.classResponsiblePersonName" 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="handleAddAttendanceClassDetail">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteAttendanceClassDetail">删除</el-button>
                    </el-col>
                </el-row>

                <el-table :data="attendanceClassDetailList" :row-class-name="rowAttendanceClassDetailIndex" @selection-change="handleAttendanceClassDetailSelectionChange" ref="attendanceClassDetail">
                    <el-table-column type="selection" width="50" align="center" />
                    <el-table-column label="序号" align="center" prop="index" width="50"/>
                            <el-table-column label="上班打卡时间" prop="goWorkDate">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.goWorkDate" placeholder="请输入上班打卡时间" />
                                </template>
                            </el-table-column>
                            <el-table-column label="上班打卡前时间段,单位分钟" prop="goWorkDateBefore">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.goWorkDateBefore" placeholder="请输入上班打卡前时间段,单位分钟" />
                                </template>
                            </el-table-column>
                            <el-table-column label="上班打卡前时间段,单位分钟" prop="goWorkDateAfter">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.goWorkDateAfter" placeholder="请输入上班打卡前时间段,单位分钟" />
                                </template>
                            </el-table-column>
                            <el-table-column label="下班打卡时间" prop="offWorkDate">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.offWorkDate" placeholder="请输入下班打卡时间" />
                                </template>
                            </el-table-column>
                            <el-table-column label="下班打卡前时间段,单位分钟" prop="offWorkDateBefore">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.offWorkDateBefore" placeholder="请输入下班打卡前时间段,单位分钟" />
                                </template>
                            </el-table-column>
                            <el-table-column label="下班打卡前时间段,单位分钟" prop="offWorkDateAfter">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.offWorkDateAfter" 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-column label="班次名称" prop="className">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.className" 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 {
                // 子表选中数据
                checkedAttendanceClassDetail: [],
                // 考勤班次详细信息表格数据
                attendanceClassDetailList: [],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "考勤班次信息",
                // 是否显示弹出层
                open: false,
                toString:[
                ],
                // 表单校验
                rules: {
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 考勤班次详细信息序号 */
            rowAttendanceClassDetailIndex({ row, rowIndex }) {
                row.index = rowIndex + 1;
            },
            /** 考勤班次详细信息添加按钮操作 */
            handleAddAttendanceClassDetail() {
                let obj = {};
                obj.goWorkDate = "";
                obj.goWorkDateBefore = "";
                obj.goWorkDateAfter = "";
                obj.offWorkDate = "";
                obj.offWorkDateBefore = "";
                obj.offWorkDateAfter = "";
                obj.remark = "";
                obj.createUserId = "";
                obj.createTime = "";
                obj.updateUserId = "";
                obj.updateTime = "";
                obj.className = "";
                this.attendanceClassDetailList.push(obj);
            },
            /** 考勤班次详细信息删除按钮操作 */
            handleDeleteAttendanceClassDetail() {
                if (this.checkedAttendanceClassDetail.length == 0) {
                    this.$alert("请先选择要删除的考勤班次详细信息数据", "提示", { confirmButtonText: "确定", });
                } else {
                    this.attendanceClassDetailList.splice(this.checkedAttendanceClassDetail[0].index - 1, 1);
                }
            },
            /** 单选框选中数据 */
            handleAttendanceClassDetailSelectionChange(selection) {
                if (selection.length > 1) {
                    this.$refs.attendanceClassDetail.clearSelection();
                    this.$refs.attendanceClassDetail.toggleRowSelection(selection.pop());
                } else {
                    this.checkedAttendanceClassDetail = selection;
                }
            },
            // 渲染前置处理
            beforeRender(data) {
                if(data.entity.attendanceClassDetailList) {
                    this.attendanceClassDetailList = data.entity.attendanceClassDetailList;
                }
                return data
            },
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="attendance/class/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改考勤班次信息";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "attendance/class/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增考勤班次信息";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="attendance/class/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 = {
                    className : "",
                    classResponsiblePersonId : null,
                    classResponsiblePersonName : "",
                    remark : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
