<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="问卷标题" prop="title" v-model="form.title" placeholder="请输入问卷标题"/>
                            <Field label="反馈开始时间" prop="feedbackTimeStart" v-model="form.feedbackTimeStart" type="date" />
                            <Field label="反馈结束时间" prop="feedbackTimeEnd" v-model="form.feedbackTimeEnd" type="date" />
                            <Field label="邀请人数" prop="inviteNum" v-model="form.inviteNum" placeholder="请输入邀请人数"/>
                            <Field label="反馈人数" prop="feedbackNum" v-model="form.feedbackNum" placeholder="请输入反馈人数"/>
                            <Field label="状态 " prop="processStatus" v-model="form.processStatus" type="select" :enumData="dict.processStatus" placeholder="请选择状态 "/>
                            <Field label="问卷是否外链" prop="weblink" v-model="form.weblink" type="select" :enumData="dict.weblink" placeholder="请选择问卷是否外链"/>
                            <Field label="问题外链地址" prop="webUrl" v-model="form.webUrl" type="textarea" 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="handleAddFeedbackQuestion">添加</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteFeedbackQuestion">删除</el-button>
                    </el-col>
                </el-row>

                <el-table :data="feedbackQuestionList" :row-class-name="rowFeedbackQuestionIndex" @selection-change="handleFeedbackQuestionSelectionChange" ref="feedbackQuestion">
                    <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="questionType">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.questionType" placeholder="请输入问题类型 " />
                                </template>
                            </el-table-column>
                            <el-table-column label="是否必填" prop="require">
                                <template slot-scope="scope">
                                    <el-input v-model="scope.row.require" 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: "FeedbackDetail",
        mixins: [form],
        components: {

        },
        created() {
            this.changePath("feedback")
        },
        data() {
            return {
                // 子表选中数据
                checkedFeedbackQuestion: [],
                // 绩效反馈问题表格数据
                feedbackQuestionList: [],
                // 遮罩层
                loading: true,
                // 弹出层标题
                title: "绩效反馈记录信息",
                // 是否显示弹出层
                open: false,
                direction:"rtl",
                toString:[
                    "processStatus",
                    "weblink",
                ],
                toDate:[
                    "feedbackTimeStart",
                    "feedbackTimeEnd",
                ],
                // 表单校验
                rules: {
                    title: [
                        {required: true,message: "请输入问卷标题", trigger: "blur" },
                        {max: 64,message: "最多只能录入64个字符",trigger: "blur",},
                    ],
                }
            };
        },

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