<template>
    <!-- 弹出框表单 -->
    <el-drawer
            :title="title"
            :visible.sync="open"
            :direction="direction"
            size="50%">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                            <Field label="考勤组名称" prop="groupName" v-model="form.groupName" placeholder="请输入考勤组名称"/>
                            <Field label="参与考勤人数" prop="personNum" v-model="form.personNum" placeholder="请输入参与考勤人数"/>
                            <Field label="类型" prop="type" v-model="form.type" type="select" :enumData="dict.type" placeholder="请选择类型"/>
                            <Field label="备注" prop="remark" v-model="form.remark" type="textarea" placeholder="请输入备注"/>
                            <Field label="未参与考勤人数" prop="personNumNo" v-model="form.personNumNo" placeholder="请输入未参与考勤人数"/>
                            <Field label="考勤方式" prop="attendanceType" v-model="form.attendanceType" type="select" :enumData="dict.attendanceType" 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="handleAddAttendanceGroupStaff">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteAttendanceGroupStaff">删除</el-button>
                    </el-col>
                </el-row>

                <el-table :data="attendanceGroupStaffList" :row-class-name="rowAttendanceGroupStaffIndex" @selection-change="handleAttendanceGroupStaffSelectionChange" ref="attendanceGroupStaff">
                    <el-table-column type="selection" width="50" align="center" />
                    <el-table-column label="序号" align="center" prop="index" width="50"/>
                            <el-table-column label="考勤组名称" prop="groupName">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.groupName" placeholder="请输入考勤组名称" />
                                </template>
                            </el-table-column>
                            <el-table-column label="员工ID" prop="staffId">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.staffId" placeholder="请输入员工ID" />
                                </template>
                            </el-table-column>
                            <el-table-column label="员工姓名" prop="staffName">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.staffName" placeholder="请输入员工姓名" />
                                </template>
                            </el-table-column>
                            <el-table-column label="是否参与考勤，" prop="partAttendance">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.partAttendance" 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>

            <form-buttons @submit='submitForm' noCancelBtn />
        </el-form>

    </el-drawer>
</template>

<script>
    import form from "@/assets/mixins/formdialog";
    export default {
        name: "AttendanceGroupDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("attendance/group")
        },
        data() {
            return {
                // 子表选中数据
                checkedAttendanceGroupStaff: [],
                // 考勤组人员信息表格数据
                attendanceGroupStaffList: [],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "考勤组信息",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "type",
                ],
                toDate:[
                ],
                // 表单校验
                rules: {
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 考勤组人员信息序号 */
            rowAttendanceGroupStaffIndex({ row, rowIndex }) {
                row.index = rowIndex + 1;
            },
            /** 考勤组人员信息添加按钮操作 */
            handleAddAttendanceGroupStaff() {
                let obj = {};
                obj.groupName = "";
                obj.staffId = "";
                obj.staffName = "";
                obj.partAttendance = "";
                obj.remark = "";
                obj.createUserId = "";
                obj.createTime = "";
                obj.updateUserId = "";
                obj.updateTime = "";
                this.attendanceGroupStaffList.push(obj);
            },
            /** 考勤组人员信息删除按钮操作 */
            handleDeleteAttendanceGroupStaff() {
                if (this.checkedAttendanceGroupStaff.length == 0) {
                    this.$alert("请先选择要删除的考勤组人员信息数据", "提示", { confirmButtonText: "确定", });
                } else {
                    this.attendanceGroupStaffList.splice(this.checkedAttendanceGroupStaff[0].index - 1, 1);
                }
            },
            /** 单选框选中数据 */
            handleAttendanceGroupStaffSelectionChange(selection) {
                if (selection.length > 1) {
                    this.$refs.attendanceGroupStaff.clearSelection();
                    this.$refs.attendanceGroupStaff.toggleRowSelection(selection.pop());
                } else {
                    this.checkedAttendanceGroupStaff = selection;
                }
            },
            // 渲染前置处理
            beforeRender(data) {
                if(data.entity.attendanceGroupStaffList) {
                    this.attendanceGroupStaffList = data.entity.attendanceGroupStaffList;
                }
                return data
            },
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="attendance/group/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改考勤组信息";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "attendance/group/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增考勤组信息";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="attendance/group/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 = {
                    groupName : "",
                    personNum : null,
                    type : null,
                    remark : "",
                    personNumNo : null,
                    attendanceType : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
