<template>
    <el-dialog
        title="信息维护"
        append-to-body
        :modelValue="showBasic"
        width="100%"
        fullscreen
        @close="closeDialog"
    >
        <avue-crud
            :option="option"
            :table-loading="loading"
            :data="data"
            v-model:search="search"
            v-model:page="page"
            v-model="form"
            ref="crud"
            @row-update="rowUpdate"
            @row-save="rowSave"
            @row-del="rowDel"
            @search-change="searchChange"
            @search-reset="searchReset"
            @selection-change="selectionChange"
            @current-change="currentChange"
            @size-change="sizeChange"
            @refresh-change="refreshChange"
            @on-load="onLoad"
        ></avue-crud>
    </el-dialog>
</template>

<script>
import {getList,addBasic,editBasic,deleteBasic} from '@/api/tankSolutionSystem/reportBasic'
export default {
    props:{
        showBasic:{
            type:Boolean,
            default:false
        }
    },
    data(){
        return {
            loading:false,
            data:[],
            page:{
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            search:{},
            form:{},
            option:{
                tip: false,
                height: 'auto',
                calcHeight: 32,
                columnSort: true,
                searchShow: true,
                searchMenuSpan: 18,
                searchIcon: true,
                searchIndex: 3,
                tree: false,
                border: true,
                index: false,
                selection: true,
                viewBtn: true,
                delBtn: true,
                addBtn: true,
                editBtn: true,
                editBtnText: '修改',
                viewBtnText: '详情',
                addBtnIcon: ' ',
                viewBtnIcon: ' ',
                delBtnIcon: ' ',
                editBtnIcon: ' ',
                labelWidth: 120,
                dialogWidth: 600,
                dialogClickModal: false,
                searchEnter: true,
                filterBtn: true,
                searchShowBtn: false,
                excelBtn: true,
                showOverflowTooltip: true,
                align: 'center',
                searchLabelPosition: 'left',
                searchGutter: 24,
                searchSpan: 6,
                menuAlign: 'left',
                gridBtn: false,
                searchMenuPosition: 'right',
                column: [
                    {
                        label: '作业中心',
                        prop: 'wcId',
                        type:'select',
                        sortable: true,
                        filter: true,
                        search: true,
                        dicUrl:'/blade-desk/BA/WorkCenter/listForSelect',
                        span: 24,
                        props: {
                            label: 'wcName',
                            value: 'id',
                        },
                    },
                    {
                        label: '报告名称',
                        prop: 'namePrefix',
                        type: 'input',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 24,
                    },
                    {
                        label: '表号',
                        prop: 'reportCode',
                        type: 'input',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 24,
                    },
                    {
                        label: '规范',
                        prop: 'norm',
                        type: 'input',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 24,
                    },
                ]
            }
        }
    },
    mounted(){

    },
    methods:{
        closeDialog(){
            this.$emit('closeDialog');
        },
        // 点击删除按钮
        rowDel(row) {
            this.$confirm('确定删除此条数据?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {
                deleteBasic({ids:row.id}).then(res =>{
                    if(res.data.code == 200){
                        this.$message.success('删除成功')
                        this.onLoad()
                    }
                })
            });
        },
        rowSave(row, done, loading) {
            addBasic(row).then(res =>{
                if(res.data.code == 200){
                    this.$message.success('新增成功')
                    this.onLoad()
                    done()
                }
            }).catch(err=>{
                console.log('err----------------',err)
                done()
            })
        },
        rowUpdate(row, index, done, loading) {
            editBasic(row).then(res =>{
               this.$message.success('修改成功')
                this.onLoad()
                done() 
            })
            
        },
        searchReset() {
            this.search = {};
            this.onLoad();
        },
        searchChange(params, done) {
            this.search = params;
            this.page.currentPage = 1;
            this.onLoad();
            done();
        },
        currentChange(currentPage) {
            this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
            this.page.pageSize = pageSize;
        },
        refreshChange() {
            this.onLoad();
        },
        onLoad(){
            this.loading = true
            getList({
                current:this.page.currentPage,
                size:this.page.pageSize,
                ...this.search
            }).then(res =>{
                this.data = res.data.data.records
                this.page.total = res.data.data.total
                this.loading = false
            })
        },
    }

}
</script>

<style>

</style>