<template>
    <div id="edit-card-form-box">
        <el-dialog title="会员协议配置" :visible.sync="editRightFormVisible" width="900px" id="edit-member-right-show" v-loading="submitLoading" :element-loading-text="loadingText">
            <el-form ref="rightForm" :model="form" label-width="100px" id="edit-member-right-form">
                <el-form-item label="会员权益:"  prop="rights">
                    <el-input v-model="form.rights" type="textarea" rows='6' placeholder="" ></el-input>
                </el-form-item>
            </el-form>
            
            <div slot="footer" class="dialog-footer">
                <el-button @click="editRightFormVisible = false">取消</el-button>
                <el-button
                type="primary"
                @click="submitForm('rightForm')"
                >保 存
                </el-button>
            </div>
        </el-dialog>  
    </div>
</template>

<script>
import {EditRight} from "@/api/member/member";

export default {
    name:'EditCardRightForm',
    props:{
        form:{
            rights:'',
        },
    },
    data(){
        return {
            editRightFormVisible:false,
            loadingText:'',
            submitLoading:false,
            
        }
    },
    methods:{
        open:function(){
            this.editRightFormVisible = true;
        },
        resetForm:function(formName) {
            if (typeof(this.$refs[formName]) !='undefined') {
                this.$refs[formName].resetFields();
            }
        },
        submitForm:function(formName){
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.loadingText = "正在保存...";
                    this.submitLoading = true;
                    EditRight(this.form).then(response=>{
                        var res = response.data;
                        if(res.state === 1) {
                            // this.$emit('update-right', res.data.right.rights);
                            this.editRightFormVisible = false;
                            this.$message.success("编辑成功");
                        }else {
                            this.$message.error(res.msg);
                        }
                        this.submitLoading = false;
                    }).catch(e=>{
                        this.submitLoading = false;
                    });
                } else {
                    return false;
                }
            });
        },
    },
    computed: {
    
    },
}
</script>
