<template>
    <el-drawer v-model="visible" size="800px" destroy-on-close :close-on-click-modal="false" :with-header="false">
        <el-container class="flex-column">
            <div class="drawer-detail-main">
                <div class="drawer-detail-header">
                    <div class="drawer-detail-header-body">
                        <div class="drawer-detail-header-left">{{titleMap[mode]}}</div>
                        <div class="drawer-detail-header-left">
                            <el-button type="default" icon="el-icon-close" @click="visible=false"></el-button>
                        </div>
                    </div>
                </div>
            </div>
            <el-main>
                <el-form ref="dialogForm" :model="formData" :rules="rules" label-width="100px" label-position="top">
                    <el-form-item label="投诉事项">
                        <el-input v-model="formData.question" readonly disabled clearable placeholder="请输入"></el-input>
                        <div class="el-form-item-msg"></div>
                    </el-form-item>
                    <el-form-item label="投诉订单">
                        <el-input v-model="formData.order_sn" readonly disabled clearable placeholder="请输入"></el-input>
                        <div class="el-form-item-msg"></div>
                    </el-form-item>
                    <el-form-item label="回复" prop="remark" v-if="formData.status == 0">
                        <sc-editor v-model="formData.remark" placeholder="请输入" :height="400"></sc-editor>
                        <div class="el-form-item-msg"></div>
                    </el-form-item>
                    
                </el-form>
            </el-main>
            <el-footer>
                <el-button @click="visible=false" size="large">取 消</el-button>
                <el-button size="large" type="primary" :loading="isSaveing" @click="submitEdit()">保 存</el-button>
            </el-footer>
        </el-container>
    </el-drawer>
</template>

<script>
import { defineAsyncComponent } from 'vue';
const scEditor = defineAsyncComponent(() => import('@/components/scEditor'));
export default {
    components: {
        scEditor
    },
    data(){
        return {
            loading: false,
            isSaveing: false,
            mode:"add",
            titleMap:{
                add:"投诉回复",
                edit:"投诉回复"
            },
            visible:false,
            formData:{},
            rules:{
                remark: [
                    {required: true, message: '请输入'}
                ],
            }
        }
    },
    methods:{
        quickGoods(){
            this.quickData.visible = true;
        },
        open(mode = 'add'){
            this.mode = mode;
            this.visible = true;
            return this
        },
        //表单注入数据
        setData(data){
            this.formData = JSON.parse(JSON.stringify(data));
        },
        async submitEdit(){
            var loading = this.$loading()
            this.isSaveing = true;
            var resp = await this.$API.complaint.save.post(this.formData)
            this.isSaveing = false;
            loading.close();
            if (resp.code == 0) return this.$message.error(resp.msg);
            this.$message.success(resp.msg);
            this.visible = false;
            this.formData = {};
            this.$emit("success");
        }
    }
}
</script>

<style>
.goods-live{width: 100%;margin-top: 10px;}
.flex-loading{display: flex;flex-direction: column;flex: 1;}
</style>