<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="员工ID" prop="staffId" v-model="form.staffId" placeholder="请输入员工ID"/>
                            <Field label="员工姓名" prop="staffName" v-model="form.staffName" placeholder="请输入员工姓名"/>
                            <Field label="工号" prop="workNum" v-model="form.workNum" placeholder="请输入工号"/>
                            <Field label="所属部门" prop="deptId" v-model="form.deptId" placeholder="请输入所属部门"/>
                            <Field label="所属部门名称" prop="deptName" v-model="form.deptName" placeholder="请输入所属部门名称"/>
                            <Field label="职位ID" prop="positionId" v-model="form.positionId" placeholder="请输入职位ID"/>
                            <Field label="职位名称" prop="positionName" v-model="form.positionName" placeholder="请输入职位名称"/>
                            <Field label="所属考勤组ID" prop="attendanceGroupId" v-model="form.attendanceGroupId" placeholder="请输入所属考勤组ID"/>
                            <Field label="所属考勤组名称" prop="attendanceGroupName" v-model="form.attendanceGroupName" placeholder="请输入所属考勤组名称"/>
                            <Field label="班次ID" prop="shiftsId" v-model="form.shiftsId" placeholder="请输入班次ID"/>
                            <Field label="班次名称" prop="shiftsName" v-model="form.shiftsName" placeholder="请输入班次名称"/>
                            <Field label="打卡日期" prop="attendanceDate" v-model="form.attendanceDate" type="date" />
                            <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="handleAddAttendanceRecordDetail">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteAttendanceRecordDetail">删除</el-button>
                    </el-col>
                </el-row>

                <el-table :data="attendanceRecordDetailList" :row-class-name="rowAttendanceRecordDetailIndex" @selection-change="handleAttendanceRecordDetailSelectionChange" ref="attendanceRecordDetail">
                    <el-table-column type="selection" width="50" align="center" />
                    <el-table-column label="序号" align="center" prop="index" width="50"/>
                            <el-table-column label="班次ID" prop="shiftsId">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.shiftsId" placeholder="请输入班次ID" />
                                </template>
                            </el-table-column>
                            <el-table-column label="班次名称" prop="shiftsName">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.shiftsName" placeholder="请输入班次名称" />
                                </template>
                            </el-table-column>
                            <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="goWorkResult">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.goWorkResult" 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="offWorkResult">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.offWorkResult" 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 {
                // 子表选中数据
                checkedAttendanceRecordDetail: [],
                // 考勤打卡记录详细信息表格数据
                attendanceRecordDetailList: [],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "考勤打卡记录信息",
                // 是否显示弹出层
                open: false,
                toString:[
                ],
                // 表单校验
                rules: {
                    staffName: [
                        {required: true,message: "请输入员工姓名", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                    createTime: [
                        {required: true,message: "请选择创建时间" },
                    ],
                }
            };
        },

        methods: {
            /** 考勤打卡记录详细信息序号 */
            rowAttendanceRecordDetailIndex({ row, rowIndex }) {
                row.index = rowIndex + 1;
            },
            /** 考勤打卡记录详细信息添加按钮操作 */
            handleAddAttendanceRecordDetail() {
                let obj = {};
                obj.shiftsId = "";
                obj.shiftsName = "";
                obj.goWorkDate = "";
                obj.goWorkResult = "";
                obj.offWorkDate = "";
                obj.offWorkResult = "";
                obj.remark = "";
                obj.createUserId = "";
                obj.createTime = "";
                obj.updateUserId = "";
                obj.updateTime = "";
                this.attendanceRecordDetailList.push(obj);
            },
            /** 考勤打卡记录详细信息删除按钮操作 */
            handleDeleteAttendanceRecordDetail() {
                if (this.checkedAttendanceRecordDetail.length == 0) {
                    this.$alert("请先选择要删除的考勤打卡记录详细信息数据", "提示", { confirmButtonText: "确定", });
                } else {
                    this.attendanceRecordDetailList.splice(this.checkedAttendanceRecordDetail[0].index - 1, 1);
                }
            },
            /** 单选框选中数据 */
            handleAttendanceRecordDetailSelectionChange(selection) {
                if (selection.length > 1) {
                    this.$refs.attendanceRecordDetail.clearSelection();
                    this.$refs.attendanceRecordDetail.toggleRowSelection(selection.pop());
                } else {
                    this.checkedAttendanceRecordDetail = selection;
                }
            },
            // 渲染前置处理
            beforeRender(data) {
                if(data.entity.attendanceRecordDetailList) {
                    this.attendanceRecordDetailList = data.entity.attendanceRecordDetailList;
                }
                return data
            },
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="attendance/record/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改考勤打卡记录信息";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "attendance/record/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增考勤打卡记录信息";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="attendance/record/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 = {
                    staffId : null,
                    staffName : "",
                    workNum : "",
                    deptId : null,
                    deptName : "",
                    positionId : null,
                    positionName : "",
                    attendanceGroupId : null,
                    attendanceGroupName : "",
                    shiftsId : null,
                    shiftsName : "",
                    attendanceDate : null,
                    remark : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
