<template>
    <!-- 弹出框表单 -->
    <el-drawer
            :title="title"
            :visible.sync="open"
            :direction="direction"
            :destroy-on-close="true"
            size="50%">
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-row>
                                            <Field label="反馈问卷id号" prop="feedbackId" v-model="form.feedbackId" placeholder="请输入反馈问卷id号"/>
                            <Field label="问题内容"><editor v-model="form.content" :min-height="256"/></Field>
                            <Field label="问题类型 " prop="questionType" v-model="form.questionType" type="select" :enumData="dict.questionType" placeholder="请选择问题类型 "/>
                            <Field label="是否必填" prop="require" v-model="form.require" type="select" :enumData="dict.require" 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="handleAddFeedbackOption">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteFeedbackOption">删除</el-button>
                    </el-col>
                </el-row>

                <el-table :data="feedbackOptionList" :row-class-name="rowFeedbackOptionIndex" @selection-change="handleFeedbackOptionSelectionChange" ref="feedbackOption">
                    <el-table-column type="selection" width="50" align="center" />
                    <el-table-column label="序号" align="center" prop="index" width="50"/>
                            <el-table-column label="选项内容" prop="content">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.content" 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' v-if="pageInfo.type!='view'" noCancelBtn />
        </el-form>

    </el-drawer>
</template>

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

        },
        created() {
            this.changePath("feedback/question")
        },
        data() {
            return {
                // 子表选中数据
                checkedFeedbackOption: [],
                // 绩效问题选项表格数据
                feedbackOptionList: [],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "绩效反馈问题",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "questionType",
                    "require",
                ],
                toDate:[
                ],
                // 表单校验
                rules: {
                    content: [
                        {required: true,message: "请输入问题内容", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                }
            };
        },

        methods: {
            /** 绩效问题选项序号 */
            rowFeedbackOptionIndex({ row, rowIndex }) {
                row.index = rowIndex + 1;
            },
            /** 绩效问题选项添加按钮操作 */
            handleAddFeedbackOption() {
                let obj = {};
                obj.content = "";
                obj.remark = "";
                obj.createUserId = "";
                obj.createTime = "";
                obj.updateUserId = "";
                obj.updateTime = "";
                this.feedbackOptionList.push(obj);
            },
            /** 绩效问题选项删除按钮操作 */
            handleDeleteFeedbackOption() {
                if (this.checkedFeedbackOption.length == 0) {
                    this.$alert("请先选择要删除的绩效问题选项数据", "提示", { confirmButtonText: "确定", });
                } else {
                    this.feedbackOptionList.splice(this.checkedFeedbackOption[0].index - 1, 1);
                }
            },
            /** 单选框选中数据 */
            handleFeedbackOptionSelectionChange(selection) {
                if (selection.length > 1) {
                    this.$refs.feedbackOption.clearSelection();
                    this.$refs.feedbackOption.toggleRowSelection(selection.pop());
                } else {
                    this.checkedFeedbackOption = selection;
                }
            },
            // 渲染前置处理
            beforeRender(data) {
                if(data.entity.feedbackOptionList) {
                    this.feedbackOptionList = data.entity.feedbackOptionList;
                }
                return data
            },
            /** 编辑 */
            edit(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="feedback/question/edit";
                this.getData();
                this.pageInfo.type="edit"
                this.title = "修改绩效反馈问题";
            },
            /** 新增 */
            add(row) {
                this.reset()
                this.urls.currUrl = "feedback/question/add";
                this.getData();
                this.pageInfo.type="add"
                this.title = "新增绩效反馈问题";
            },
            /** 查看*/
            view(row) {
                this.reset()
                this.query = { id: row.id };
                this.urls.currUrl ="feedback/question/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 = {
                    feedbackId : 0,
                    content : "",
                    questionType : 0,
                    require : 0,
                    remark : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
