<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="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="questionType" v-model="form.questionType" type="select" :enumData="dict.questionType" 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="handleAddFeedbackAnswerOption">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteFeedbackAnswerOption">删除</el-button>
                    </el-col>
                </el-row>

                <el-table :data="feedbackAnswerOptionList" :row-class-name="rowFeedbackAnswerOptionIndex" @selection-change="handleFeedbackAnswerOptionSelectionChange" ref="feedbackAnswerOption">
                    <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>

        </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";
    import Editor from '@/components/Editor';
    export default {
        mixins: [form],
        components: {
            dialogShow ,
            Editor,
        },
        data() {
            return {
                // 子表选中数据
                checkedFeedbackAnswerOption: [],
                // 绩效问题回答选项表格数据
                feedbackAnswerOptionList: [],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "绩效问题回答",
                // 是否显示弹出层
                open: false,
                toString:[
                    "questionType",
                ],
                // 表单校验
                rules: {
                    content: [
                        {required: true,message: "请输入适用于问题内容为文本内容", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                }
            };
        },

        methods: {
            /** 绩效问题回答选项序号 */
            rowFeedbackAnswerOptionIndex({ row, rowIndex }) {
                row.index = rowIndex + 1;
            },
            /** 绩效问题回答选项添加按钮操作 */
            handleAddFeedbackAnswerOption() {
                let obj = {};
                obj.optionId = "";
                obj.optionContent = "";
                obj.remark = "";
                obj.createUserId = "";
                obj.createTime = "";
                obj.updateUserId = "";
                obj.updateTime = "";
                this.feedbackAnswerOptionList.push(obj);
            },
            /** 绩效问题回答选项删除按钮操作 */
            handleDeleteFeedbackAnswerOption() {
                if (this.checkedFeedbackAnswerOption.length == 0) {
                    this.$alert("请先选择要删除的绩效问题回答选项数据", "提示", { confirmButtonText: "确定", });
                } else {
                    this.feedbackAnswerOptionList.splice(this.checkedFeedbackAnswerOption[0].index - 1, 1);
                }
            },
            /** 单选框选中数据 */
            handleFeedbackAnswerOptionSelectionChange(selection) {
                if (selection.length > 1) {
                    this.$refs.feedbackAnswerOption.clearSelection();
                    this.$refs.feedbackAnswerOption.toggleRowSelection(selection.pop());
                } else {
                    this.checkedFeedbackAnswerOption = selection;
                }
            },
            // 渲染前置处理
            beforeRender(data) {
                if(data.entity.feedbackAnswerOptionList) {
                    this.feedbackAnswerOptionList = data.entity.feedbackAnswerOptionList;
                }
                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,
                    questionType : 1,
                    content : "",
                    remark : "",
                };
                this.resetForm("form");
            },
            resetForm(refName) {
                if (this.$refs[refName]) {
                    this.$refs[refName].resetFields();
                }
            },
        },
    };
</script>
