<template>
    <!-- 机具成套设备主列表 -->
    <div>
        <TableModel
            ref="tbRef"
            :config="config"
            :sendApi="getCompleteSetToolsApi"
            :sendParams="sendParams"
        >
            <template slot="export">
                <el-row class="mb8">
                    <el-button
                        type="primary"
                        size="mini"
                        @click="handleAddComplete()"
                        >新 增</el-button
                    >
                </el-row>
            </template>

            <!-- 列表操作栏 -->
            <template slot="handle" slot-scope="{ data }">
                <el-button
                    type="text"
                    icon="el-icon-edit"
                    @click="handleEdit(data)"
                    >编辑</el-button
                >
                <el-button
                    type="text"
                    icon="el-icon-delete"
                    style="color: #f56c6c"
                    @click="handleDelete(data)"
                    >删除</el-button
                >
            </template>
        </TableModel>
    </div>
</template>

<script>
import TableModel from '@/components/TableModel'
import {
    getCompleteSetToolsApi,
    delCompleteSetToolsApi,
} from '@/api/store/completeTools.js'
import { config, getDeviceTypeTreeFun } from './config'
export default {
    components: {
        TableModel,
    },
    data() {
        return {
            config,
            getCompleteSetToolsApi,
            sendParams: {
                companyId: 101,
            },
            getDeviceTypeTreeFun,
        }
    },
    created() {
        this.getDeviceTypeTreeFun()
    },
    methods: {
        // 新增
        handleAddComplete() {
            this.$emit('handleAddComplete')
        },
        // 编辑
        handleEdit(data) {
            this.$emit('handleAddComplete', data)
        },
        // 删除
        handleDelete(data) {
            this.$confirm('是否确定删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            })
                .then(() => {
                    delCompleteSetToolsApi({
                        id: data.id,
                        wholeTypeName: data.wholeTypeName,
                    })
                        .then((res) => {
                            console.log(res, '删除结果---')
                            this.$message({
                                type: 'success',
                                message: '删除成功!',
                            })

                            this.$refs.tbRef.getList()
                        })
                        .catch((err) => {
                            this.$message({
                                type: 'error',
                                message: '删除失败!',
                            })
                        })
                })
                .catch(() => {})
        },
    },
}
</script>