<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_audit()">新建价格</el-button>
                <!-- <el-button type="primary" icon="el-icon-download" @click="table_export()">导出</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: {
        async table_clear(){
            if (this.dataSelect.length == 0) {
                return this.$message.error("请选择修改数据")
            }
            let submitData = {"id":this.dataSelect,"value":0,"field":"store_id","type":"batch"};
            var resp = await this.$API.merStore.save.post(submitData);
            if (resp.code == 0) {
                return this.$message.error(resp.msg);
            }
            this.$message.success(resp.msg);
            this.$emit("success");
        },
        async table_batch_status(status){
            if (this.dataSelect.length == 0) {
                return this.$message.error("请选择修改数据")
            }
            let submitData = {"id":this.dataSelect,"value":status,"field":"status","type":"batch"};
            var resp = await this.$API.merStore.save.post(submitData);
            if (resp.code == 0) {
                return this.$message.error(resp.msg);
            }
            this.$message.success(resp.msg);
            this.$emit("success");
        },
        table_del(data){
            this.$confirm(`确定要执行删除吗`, '提示', {
                type: 'warning'
            }).then(async ()=>{
                var resp = await this.$API.merGoods.del.post({"id":this.dataSelect,"type":"batch"});
                if (resp.code == 0) {
                    return this.$message.warning(resp.msg);
                }
                this.$message.success(resp.msg);
                this.$emit("success");
            }).catch(()=>{})
        },
        handleSuccess(){
            this.$emit("success");
        },
        table_audit(){
            if (this.dataSelect.length == 0) {
                return this.$message.error("请选择修改数据")
            }
            this.$nextTick(() => {
                this.$refs.formMain.open("batch").setData(this.dataSelect)
            })
        },
    }
}
</script>