<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>
            </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: {
        table_add(){
            this.$nextTick(() => {
                this.$refs.formMain.open("add")
            })
        },
        table_sync(){
            this.$confirm(`发起同步后，请耐心等待1-2分钟后再刷新当前数据列表`, '提示', {
                type: 'warning'
            }).then(async () => {
                var resp = await this.$API.category.sync.get();
                if (resp.code == 0) {
                    return this.$message.error(resp.msg);
                }
                this.$message.success(resp.msg);
                this.$emit("success");
            }).catch(() => {

            })
        },
        table_batch_status(status){
            if (this.dataSelect.length == 0) {
                return this.$message.error("请选择修改数据")
            }
            this.$confirm(`审核中的商品不支持该操作，请确认是否有勾选审核中的商品`, '提示', {
                type: 'warning'
            }).then(async () => {
                var loading = this.$loading()
                let submitData = {"id":this.dataSelect,"value":status,"field":"status","type":"batch"};
                loading.close()
                var resp = await this.$API.merGoods.batch.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");
        }
    }
}
</script>