<template>
    <div class="add-edit-dialog-container">
        <el-dialog
            :title="title"
            :visible.sync="visible"
            width="500px"
            :before-close="close"
            :close-on-click-modal="false"
        >
            <el-form :model="formData" ref="formData" :rules="rules" label-width="90px">
                <el-form-item label="敏感词:" prop="keyword" class="classify-input">
                    <el-input
                        type="textarea"
                        :rows="5"
                        placeholder="敏感词一行一个，请按要求输入"
                        v-model="formData.keyword"
                    ></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="close()">取 消</el-button>
                <el-button
                    type="primary"
                    @click="submitForm('formData')"
                    :disabled="submitBtndisabled"
                >确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import { addsensitiveWord, editsensitiveWord, textareaImport } from '@/apps/mobile/api/SensitiveWordLibrary/index';
export default {
    data() {
        return {
            title: '文本域批量添加',
            formData: {},
            visible: false,
            submitBtndisabled: false,
            rules: {
                keyword: [{ required: true, message: '请输入敏感词', trigger: 'blur' }],
            },
        };
    },
    methods: {
        open() {
            this.formData = {};
            this.visible = true;
        },
        close() {
            this.$refs['formData'].resetFields();
            this.submitBtndisabled = false;
            this.visible = false;
        },
        submitForm(formName) {
            this.$refs[formName].validate(valid => {
                if (valid) {
                    let message = '添加成功';
                    let obj = { ...this.formData };
                    obj.keyword = obj.keyword.replace(/\n/g, ',');
                    textareaImport(obj)
                        .then(res => {
                            if (res.statusCode === '1') {
                                this.completeOperation(res.message);
                            } else {
                                this.$message.warning(res.message);
                            }
                        })
                        .catch();
                }
            });
        },
        completeOperation(message) {
            this.$message({
                type: 'success',
                message,
            });
            this.close();
            this.submitBtndisabled = false;
            this.$emit('queryListData');
        },
    },
};
</script>
<style lang="stylus" scoped>
.add-edit-dialog-container {
    ::v-deep .el-input__inner {
        width: 200px;
    }

    ::v-deep .avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    ::v-deep .avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    ::v-deep .avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 80px;
        height: 80px;
        line-height: 80px;
        text-align: center;
    }

    ::v-deep .avatar {
        width: 80px;
        height: 80px;
        display: block;
    }
}
</style>
