<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="问题id号" prop="questionId" v-model="form.questionId" placeholder="请输入问题id号"/>
                            <Field label="用户id号" prop="staffId" v-model="form.staffId" placeholder="请输入用户id号"/>
                            <Field label="适用于单选选择" prop="optionId" v-model="form.optionId" placeholder="请输入适用于单选选择"/>
                            <Field label="适用于问题内容，如果是多选，则以逗号做分割内容。"><editor v-model="form.content" :min-height="256"/></Field>
                            <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="handleAddAnswerOption">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteAnswerOption">删除</el-button>
                    </el-col>
                </el-row>

                <el-table :data="answerOptionList" :row-class-name="rowAnswerOptionIndex" @selection-change="handleAnswerOptionSelectionChange" ref="answerOption">
                    <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="optionId">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.optionId" placeholder="请输入选项id号" />
                                </template>
                            </el-table-column>
                            <el-table-column label="选项内容" prop="optionContent">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.optionContent" 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: "FeedbackAnswerDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("feedback/answer")
        },
        data() {
            return {
                // 子表选中数据
                checkedAnswerOption: [],
                // 绩效问题回答选项表格数据
                answerOptionList: [],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "绩效问题回答",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                ],
                toDate:[
                ],
                // 表单校验
                rules: {
                    content: [
                        {required: true,message: "请输入适用于问题内容，如果是多选，则以逗号做分割内容。", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                }
            };
        },

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