<template>
    <fieldset>
        <legend>
            <el-tag type="info">按需操作</el-tag>
        </legend>
        <div class="op-header">
            <div class="left-panel">
                <el-button icon="el-icon-plus" type="primary" @click="addData()">新增分类</el-button>
                <el-button icon="el-icon-unlock" @click="table_batch_status(1)" :disabled="dataSelect.length>0?false:true">启用</el-button>
                <el-button icon="el-icon-lock" type="danger" @click="table_batch_status(2)" :disabled="dataSelect.length>0?false:true">禁用</el-button>
            </div>
        </div>
    </fieldset>
    <formMain ref="formMain" @success="handleSuccess"></formMain>
</template>

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

        }
    },
    methods: {
        addData(){
            this.$nextTick(() => {
                this.$refs.formMain.open()
            })
        },
        async table_batch_status(status){
            if (this.dataSelect.length == 0) {
                return this.$message.error("请选择修改数据")
            }
            var loading = this.$loading()
            let submitData = {"id":this.dataSelect,"value":status,"field":"status","type":"batch"};
            loading.close()
            var resp = await this.$API.category.batch.post(submitData);
            if (resp.code == 0) {
                return this.$message.error(resp.msg);
            }
            this.$message.success(resp.msg);
            this.$emit("success");
        },
        handleSuccess(){
            this.$emit("success");
        },
        table_add(){
            this.$nextTick(() => {
                this.$refs.formMain.open("add")
            })
        },
    }
}
</script>