<template>
    <fieldset>
        <legend>
            <el-tag type="info">按需操作</el-tag>
        </legend>
        <div class="op-header">
            <div class="left-panel">
                <el-button type="primary" icon="el-icon-plus" @click="table_add()">新建折扣</el-button>
                <el-button type="danger" icon="el-icon-delete" :disabled="dataSelect.length>0?false:true" @click="table_del()">批量删除</el-button>
            </div>
        </div>
    </fieldset>
    <formMain ref="formMain" @success="handleSuccess"></formMain>
</template>

<script>
import formMain from './form';
export default {
    components: {
        formMain
    },
    props: {
        type: { type: String, default: "1" },
        dataSelect: { type: Array, default: () => [] },
        dataSelectFull: { type: Array, default: () => [] }
    },
    data(){
        return {

        }
    },
    methods: {
        table_del(){
            if (this.dataSelect.length == 0) {
                return this.$message.error("请选择操作数据")
            }
            this.$confirm("确定要执行删除吗？","提示",{type:"warning"}).then(async ()=>{
                let submitData = {"id":this.dataSelect,"type":"batch"};
                var resp = await this.$API.mDiscount.del.post(submitData);
                if (resp.code == 0) {
                    return this.$message.error(resp.msg)
                }
                this.$message.success(resp.msg)
                this.$emit("success");
            }).catch(()=>{});
        },
        handleSuccess(){
            this.$emit("success");
        },
        table_add(){
            this.$nextTick(() => {
                this.$refs.formMain.open("add")
            })
        },
        table_audit(){
            if (this.dataSelect.length == 0) {
                return this.$message.error("请选择修改数据")
            }
            this.$nextTick(() => {
                this.$refs.formMain.open("batch").setData(this.dataSelect)
            })
        },
    }
}
</script>