<template>
    <div class="random">
        <select-option @query="handleQuery" @changeDialogFormVisible="changeDialogFormVisible"/>
        <data-table ref="table"  @approveStatus="approveStatus"/>
        <el-dialog :visible.sync="approveVisible" v-if="approveData" title="审核" :width="'340px'">
            <approve-status-v2 :data="approveData" @changeApproveVisible="changeApproveVisible"></approve-status-v2>
        </el-dialog>
    </div>
</template>

<script>
    import SelectOption from './component/SelectOption.vue'
    import DataTable from './component/DataTable.vue'
    import ApproveStatusV2 from '@/component/ApproveStatusV2'
    import DispatchUsers from '@/component/DispatchUsers'
    import {removeOneJob} from '@/api/job'


    export default {
        components: {
            SelectOption,
            DataTable,
            ApproveStatusV2,
        },
        data() {
            return {
                dialogFormVisible: false,
                editObject: null,
                approveVisible: false,
                title: '新增',
                dispatchVisible: false,
                approveData: null,
                jobId: null,
            }
        },
        methods: {
            changeDispatchVisible() {
                this.dispatchVisible = !this.dispatchVisible;
            },
            //分配人员
            dispatchUser(id) {
                this.jobId = id;
                this.changeDispatchVisible();
            },
            changeApproveVisible() {
                this.approveVisible = !this.approveVisible;
                this.approveData = null;
                this.resetForm();
            },
            resetForm() {
                if (this.$refs.table) {
                    this.$refs.table.resetForm()
                }
            },
            handleQuery(data) {
                if (this.$refs.table) {
                    this.$refs.table.resetForm(data)
                }
            },
            changeDialogFormVisible() {
                // this.$message.info("id:" + id)
                this.dialogFormVisible = !this.dialogFormVisible;
                this.editObject = null
                this.title = '新增'
            },
            approveStatus(data) {
                this.approveVisible = true;
                this.approveData = data;
            },
            editData(data) {
                this.editObject = data;
                this.title = '编辑';
                this.dialogFormVisible = !this.dialogFormVisible;
            },
            deleteData(id) {
                this.$confirm('删除, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    removeOneJob(id).then(res => {
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '取消删除'
                    });
                });
            }
        }
    }
</script>