<template>
    <scTable ref="table" :apiObj="list.apiObj" :params="searchKey" @selectionChange="selectionChange" row-key="id">
        <el-table-column type="selection" width="50" fixed="left"></el-table-column>
        
        <el-table-column label="类型" prop="certificate_id">
            <template #default="scope">
                {{scope.row.type==1?'普通':'复印'}}
            </template>
        </el-table-column>
        <el-table-column label="支持纸张" prop="certificate_id">
            <template #default="scope">
                <el-tag type="danger" v-if="scope.row.paper_size">{{ scope.row.paper_size }}</el-tag>
                <span class="status-danger" v-else>未设置</span>
            </template>
        </el-table-column>
        <el-table-column label="参数设置" prop="certificate_id">
            <template #default="scope">
                {{ colorData[scope.row.color] }} - {{ duplexData[scope.row.duplex] }}
            </template>
        </el-table-column>
        <el-table-column label="单价(元)" prop="certificate_id">
            <template #default="scope">
                {{ scope.row.price }}元
            </template>
        </el-table-column>
        <el-table-column label="操作" width="120" align="right" fixed="right">
            <template #default="scope">
                <el-button-group>
                    <el-button text type="warning" size="small" @click="table_edit(scope.row)">编辑</el-button>
                    <el-button text type="danger" size="small" @click="table_del(scope.row)">删除</el-button>
                </el-button-group>
            </template>
        </el-table-column>
    </scTable>
    <formMain ref="formMain" @success="handleSuccess"></formMain>
</template>

<script>
import formMain from "./form";
export default {
    components: {
        formMain
    },
    props: {
        type: { type: String, default: "1" }
    },
    data(){
        return {
            colorData:['','彩色','黑白'],
            duplexData:['','单面','双面'],
            list: {
                apiObj: this.$API.mPrice.list
            },
            visible:false,
            dataSelect:[],
            dataSelectFull:[],
            searchKey:{
                type:this.type
            }
        }
    },
    methods:{
        table_edit(data){
            this.$nextTick(() => {
                this.$refs.formMain.open("edit",this.type).setData(data)
            })
        },
        table_del(data){
            this.$confirm("确定要删除该数据吗？","删除确认",{type: 'warning'}).then(async ()=>{
                var resp = await this.$API.mPrice.del.post({"id":data.id,"type":""});
                if (resp.code == 0) {
                    return this.$message.error(resp.msg)
                }
                this.$message.success(resp.msg)
                this.$refs.table.refresh()
            }).catch(()=>{});
        },
        refresh(){
            this.$refs.table.refresh()
        },
        upData(data){
            this.$refs.table.upData(data)
        },
        handleSuccess(){
            this.$refs.table.refresh()
        },
    }
}
</script>