<template>
    <basic-container>
        <avue-crud :option="option" :table-loading="loading" :data="data" 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">
            <template #menu-left>
                <el-button type="primary" @click="batchSet()">批量填报</el-button>
            </template>
            <template #menu="scope">
                <el-button type="text" @click="handleView(scope.row, 'view')">详情</el-button>
                <el-button type="text" @click="handleView(scope.row, 'add')"
                    v-show="scope.row.status == 1 || scope.row.status == 4">
                    填报
                </el-button>
                <el-button type="text" v-show="scope.row.status == 3"
                    @click="handleView(scope.row, 'drug')">领药</el-button>
                <el-button type="text" v-show="scope.row.status == 2"
                    @click="handleView(scope.row, 'check')">审核</el-button>
                <el-button type="text" v-show="scope.row.status == 0"
                    @click="receiveFn(scope.row, 'receive')">接收</el-button>
                <el-button type="text" v-show="scope.row.status == 3"
                    @click="revocationReview(scope.row, 'receive')">撤回</el-button>
                <!-- <el-button type="text" v-show="scope.row.status == 5"
                    @click="reportFn(scope.row, 'receive')">检验报告</el-button> -->
            </template>
            <template #userId="{ row }">
                {{ row.testMan.userName }}
            </template>
            <template #taskMethod="{ row }">
                {{ row.taskMethodName }}
            </template>
        </avue-crud>
        <dispose-dialog v-if="showDialog" :dialog-type="dialogType" :show-dialog="showDialog" :row-id="rowId"
            :row-obj="rowObj" @closeDialog="closeDialog"></dispose-dialog>

        <batchDialog v-if="batchDialog" @closeDialog="closeDialog" :show-dialog="batchDialog"></batchDialog>
    </basic-container>
</template>

<script>
import disposeDialog from './components/disposeDialog.vue';
import batchDialog from './components/batchDialog.vue';
export default {
    components: {
        disposeDialog,
        batchDialog
    },
    data() {
        return {
            data: [],
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            showDialog: false,
            rowId: '',
            rowObj: {},
            issueDialog: false,
            form: {},
            formRules: {
                userId: [{ required: true, message: '请选择检测员', trigger: 'blur' }],
            },
            query: {},
            loading: true,
            issueForm: {},
            option: {
                tip: false,
                height: 'auto',
                calcHeight: 32,
                // simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                searchIcon: true,
                searchIndex: 3,
                columnSort: true,
                tree: false,
                border: true,
                index: true,
                selection: true,
                viewBtn: false,
                delBtn: false,
                addBtn: false,
                editBtn: false,
                editBtnText: '修改',
                viewBtnText: '详情',
                viewBtnIcon: ' ',
                delBtnIcon: ' ',
                editBtnIcon: ' ',
                labelWidth: 120,
                // menuWidth: 330,
                dialogWidth: 600,
                dialogClickModal: false,
                searchEnter: true,
                filterBtn: true,
                searchShowBtn: false,
                excelBtn: true,
                showOverflowTooltip: true,
                align: 'center',
                column: [
                    {
                        label: '任务编号',
                        prop: 'taskCode',
                        search: false,
                        sortable: true,
                        filter: true,
                        addDisplay: false,
                        editDisplay: false,
                        viewDisplay: false,
                        span: 24,
                        rules: [
                            {
                                required: true,
                                message: '请输入任务编号',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '作业中心',
                        prop: 'wcName',
                        sortable: true,
                        filter: true,
                        span: 24,
                        search: false,
                        rules: [
                            {
                                required: true,
                                message: '请输入作业中心',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '槽号',
                        prop: 'slotNo',
                        search: true,
                        sortable: true,
                        filter: true,
                        hide: true,
                        span: 24,
                        rules: [
                            {
                                required: true,
                                message: '请输入槽号',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '待测成分',
                        prop: 'testEle',
                        type: 'textarea',
                        search: true,
                        sortable: true,
                        filter: true,
                        span: 24,
                        rules: [
                            {
                                required: true,
                                message: '请输入待测成分',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '化验人',
                        prop: 'userId',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 24,
                    },
                    {
                        label: '状态',
                        prop: 'statusName',
                        search: false,
                        sortable: true,
                        filter: true,
                        span: 24,
                    },
                    {
                        label: '任务下发时间',
                        prop: 'taskTime',
                        search: false,
                        sortable: true,
                        editDisplay: false,
                        filter: true,
                        addDisplay: false,
                        span: 24,
                        rules: [
                            {
                                required: true,
                                message: '请输入任务下发时间',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '任务完成时间',
                        prop: 'finishTime',
                        search: false,
                        sortable: true,
                        editDisplay: false,
                        filter: true,
                        addDisplay: false,
                        span: 24,
                        rules: [
                            {
                                required: true,
                                message: '请输入任务完成时间',
                                trigger: 'blur',
                            },
                        ],
                    },
                ]
            },
            selectionList: [],
            dialogType: '',
            batchDialog: false,
        }
    },
    mounted() { },
    methods: {
        batchSet() {
            this.batchDialog = true
        },
        // 查看详情
        handleView(row, type) {
            this.dialogType = type
            this.rowId = row.id
            this.rowObj = row
            this.showDialog = true
        },
        // 关闭弹窗
        closeDialog() {
            this.batchDialog = false
            this.showDialog = false
        },
        // 多选
        selectionChange(list) {
            this.selectionList = list;
        },
        selectionClear() {
            this.selectionList = [];
            this.$refs.crud.toggleSelection();
        },
        rowUpdate(row, index, done, loading) {

        },
        rowSave(row, done, loading) {

        },
        // 批量下发
        handleIssue() {
            if (this.selectionList.length == 0) {
                this.$message.error('请至少选择一条数据')
            } else {
                this.issueDialog = true
            }
        },
        // 单个下发
        issueRow(row) {
            this.issueDialog = true
        },
        searchReset() {
            this.query = {};
            this.onLoad(this.page);
        },
        searchChange(params, done) {
            this.query = params;
            this.page.currentPage = 1;
            this.onLoad(this.page, params);
            done();
        },
        receiveFn(row, index, done) {
            this.$confirm('确定接收任务吗?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {

            })
        },
        revocationReview() {
            //  this.$confirm('确认是否撤销审核通过的数据?', {
            //     confirmButtonText: '确定',
            //     cancelButtonText: '取消',
            //     type: 'warning',
            // }).then(() => {

            // })
            this.$prompt('请输入原因', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputValidator: (value) => {//校验
                    if (!value) {
                        return '输入内容不能为空！'
                    }
                }
            }).then(({ value }) => {

                this.$message({
                    type: 'success',
                    message: '撤回成功'
                });

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '取消输入'
                });
            });
        },
        reportFn() {
            this.$confirm('是否下载检验报告?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {

            })
        },
        rowDel(row, index, done) {
            this.$confirm('确定将选择数据删除?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => {

            })
        },
        // 下发
        submit() {
            this.$refs.issueForm.validate(valid => {
                if (valid) {
                    this.issueDialog = false
                }
            })
        },
        currentChange(currentPage) {
            this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
            this.page.pageSize = pageSize;
        },
        refreshChange() {
            this.onLoad(this.page, this.query);
        },
        onLoad() {
            this.loading = true
            this.data = [
                {
                    id: '6',
                    taskCode: 'CYSYXXXXXXXXX',
                    slotNo: '#25', wcName: '化学镀镍作业中心', testEle: '氰化钠',
                    proContent: 32,
                    targetValue: 40,
                    targetLowerLimit: 4,
                    drugMatterCode: 'XXXX',
                    drugName: 'XXXX',
                    addPoints: 45,
                    drugMatterName: "XXXX",
                    targetUpperLimit: 45,
                    testMan: {
                        userId: '',
                        userName: '张三',
                        testEle: '张三'
                    }, taskMethod: 1, taskMethodName: '需求生成',
                    status: 0,
                    statusName: '待接收',
                    taskTime: '2025-01-22 12:23:35',
                    testTime: '2025-01-22',
                    needAdd: 444,
                    actualAdd: 444,
                    initialInspectionTime: '2025-01-23 11:12:23',
                    finishTime: '',
                    finishReason: '',
                    meterNum: 32,
                    condNum: 181,
                    auditResult: 1,
                    auditResultName: '审核通过',
                    auditOpinion: '审核通过',
                    auditUser: '张三',
                    auditTime: '2025-01-25 15:33:26',
                    drugBatch: '1002',
                    drugRecipient: '',
                    drugRecipientName: '张三',
                    drugTime: '2025-01-25 11:23:56',
                    meterNumTwo: 32,
                    condNumTwo: 32,
                    recheckUser: '李四',
                    recheckTime: '2025-01-26 11:23:23',
                    recheckSubmit: '2025-01-26 11:23:23'
                },
                {
                    id: '1',
                    taskCode: 'CYSYXXXXXXXXX',
                    slotNo: '#21', wcName: '化学镀镍作业中心', testEle: '氰化钠',
                    proContent: 32,
                    targetValue: 40,
                    targetLowerLimit: 4,
                    drugMatterCode: 'XXXX',
                    drugName: 'XXXX',
                    addPoints: 45,
                    drugMatterName: "XXXX",
                    targetUpperLimit: 45,
                    testMan: {
                        userId: '',
                        userName: '张三',
                        testEle: '张三'
                    }, taskMethod: 1, taskMethodName: '周期生成',
                    status: 1,
                    statusName: '待检测',
                    taskTime: '2025-01-22 12:23:35',
                    testTime: '2025-01-22',
                    needAdd: 444,
                    actualAdd: 444,
                    initialInspectionTime: '2025-01-23 11:12:23',
                    finishTime: '',
                    finishReason: '',
                    meterNum: 32,
                    condNum: 181,
                    auditResult: 1,
                    auditResultName: '审核通过',
                    auditOpinion: '审核通过',
                    auditUser: '张三',
                    auditTime: '2025-01-25 15:33:26',
                    drugBatch: '1002',
                    drugRecipient: '',
                    drugRecipientName: '张三',
                    drugTime: '2025-01-25 11:23:56',
                    meterNumTwo: 32,
                    condNumTwo: 32,
                    recheckUser: '李四',
                    recheckTime: '2025-01-26 11:23:23',
                    recheckSubmit: '2025-01-26 11:23:23'
                },
                {
                    id: '2',
                    taskCode: 'CYSYXXXXXXXXX',
                    slotNo: '#22', wcName: '化学镀镍作业中心', testEle: '氰化钠',
                    proContent: 32,
                    targetValue: 40,
                    targetLowerLimit: 4,
                    drugMatterCode: 'XXXX',
                    drugName: 'XXXX',
                    addPoints: 45,
                    drugMatterName: "XXXX",
                    targetUpperLimit: 45,
                    testMan: {
                        userId: '',
                        userName: '张三',
                        testEle: '张三'
                    }, taskMethod: 1, taskMethodName: '周期生成',
                    status: 4,
                    statusName: '待复检',
                    taskTime: '2025-01-22 12:23:35',
                    testTime: '2025-01-22',
                    needAdd: 444,
                    actualAdd: 444,
                    initialInspectionTime: '2025-01-23 11:12:23',
                    finishTime: '',
                    finishReason: '',
                    meterNum: 32,
                    condNum: 181,
                    auditResult: 1,
                    auditResultName: '审核通过',
                    auditOpinion: '审核通过',
                    auditUser: '张三',
                    auditTime: '2025-01-25 15:33:26',
                    drugBatch: '1002',
                    drugRecipient: '',
                    drugRecipientName: '张三',
                    drugTime: '2025-01-25 11:23:56',
                    meterNumTwo: 32,
                    condNumTwo: 32,
                    recheckUser: '李四',
                    recheckTime: '2025-01-26 11:23:23',
                    recheckSubmit: '2025-01-26 11:23:23'
                },
                {
                    id: '3',
                    taskCode: 'CYSYXXXXXXXXX',
                    slotNo: '#23', wcName: '化学镀镍作业中心', testEle: '氰化钠',
                    proContent: 32,
                    targetValue: 40,
                    targetLowerLimit: 4,
                    drugMatterCode: 'XXXX',
                    drugName: 'XXXX',
                    addPoints: 45,
                    drugMatterName: "XXXX",
                    targetUpperLimit: 45,
                    testMan: {
                        userId: '',
                        userName: '张三',
                        testEle: '张三'
                    }, taskMethod: 1, taskMethodName: '周期生成',
                    status: 5,
                    statusName: '已完成',

                    taskTime: '2025-01-22 12:23:35',
                    testTime: '2025-01-22',
                    needAdd: 444,
                    actualAdd: 444,
                    initialInspectionTime: '2025-01-23 11:12:23',
                    finishTime: '',
                    finishReason: '',
                    meterNum: 32,
                    condNum: 181,
                    auditResult: 1,
                    auditResultName: '审核通过',
                    auditOpinion: '审核通过',
                    auditUser: '张三',
                    auditTime: '2025-01-25 15:33:26',
                    drugBatch: '1002',
                    drugRecipient: '',
                    drugRecipientName: '张三',
                    drugTime: '2025-01-25 11:23:56',
                    meterNumTwo: 32,
                    condNumTwo: 32,
                    recheckUser: '李四',
                    recheckTime: '2025-01-26 11:23:23',
                    recheckSubmit: '2025-01-26 11:23:23'
                },
                {
                    id: '4',
                    taskCode: 'CYSYXXXXXXXXX',
                    slotNo: '#24', wcName: '化学镀镍作业中心', testEle: '氰化钠',
                    proContent: 32,
                    targetValue: 40,
                    targetLowerLimit: 4,
                    drugMatterCode: 'XXXX',
                    drugName: 'XXXX',
                    addPoints: 45,
                    drugMatterName: "XXXX",
                    targetUpperLimit: 45,
                    testMan: {
                        userId: '',
                        userName: '张三',
                        testEle: '张三'
                    }, taskMethod: 1, taskMethodName: '周期生成',
                    status: 3,
                    statusName: '待加药',
                    taskTime: '2025-01-22 12:23:35',
                    testTime: '2025-01-22',
                    needAdd: 444,
                    actualAdd: 444,
                    initialInspectionTime: '2025-01-23 11:12:23',
                    finishTime: '',
                    finishReason: '',
                    meterNum: 32,
                    condNum: 181,
                    auditResult: 1,
                    auditResultName: '审核通过',
                    auditOpinion: '审核通过',
                    auditUser: '张三',
                    auditTime: '2025-01-25 15:33:26',
                    drugBatch: '1002',
                    drugRecipient: '',
                    drugRecipientName: '张三',
                    drugTime: '2025-01-25 11:23:56',
                    meterNumTwo: 32,
                    condNumTwo: 32,
                    recheckUser: '李四',
                    recheckTime: '2025-01-26 11:23:23',
                    recheckSubmit: '2025-01-26 11:23:23'
                },
                {
                    id: '5',
                    taskCode: 'CYSYXXXXXXXXX',
                    slotNo: '#25', wcName: '化学镀镍作业中心', testEle: '氰化钠',
                    proContent: 32,
                    targetValue: 40,
                    targetLowerLimit: 4,
                    drugMatterCode: 'XXXX',
                    drugName: 'XXXX',
                    addPoints: 45,
                    drugMatterName: "XXXX",
                    targetUpperLimit: 45,
                    testMan: {
                        userId: '',
                        userName: '张三',
                        testEle: '张三'
                    }, taskMethod: 1, taskMethodName: '需求生成',
                    status: 2,
                    statusName: '加药量待审核',
                    taskTime: '2025-01-22 12:23:35',
                    testTime: '2025-01-22',
                    needAdd: 444,
                    actualAdd: 444,
                    initialInspectionTime: '2025-01-23 11:12:23',
                    finishTime: '',
                    finishReason: '',
                    meterNum: 32,
                    condNum: 181,
                    auditResult: 1,
                    auditResultName: '审核通过',
                    auditOpinion: '审核通过',
                    auditUser: '张三',
                    auditTime: '2025-01-25 15:33:26',
                    drugBatch: '1002',
                    drugRecipient: '',
                    drugRecipientName: '张三',
                    drugTime: '2025-01-25 11:23:56',
                    meterNumTwo: 32,
                    condNumTwo: 32,
                    recheckUser: '李四',
                    recheckTime: '2025-01-26 11:23:23',
                    recheckSubmit: '2025-01-26 11:23:23'
                },
                {
                    id: '6',
                    taskCode: 'CYSYXXXXXXXXX',
                    slotNo: '#25', wcName: '化学镀镍作业中心', testEle: '氰化钠',
                    proContent: 32,
                    targetValue: 40,
                    targetLowerLimit: 4,
                    drugMatterCode: 'XXXX',
                    drugName: 'XXXX',
                    addPoints: 45,
                    drugMatterName: "XXXX",
                    targetUpperLimit: 45,
                    testMan: {
                        userId: '',
                        userName: '张三',
                        testEle: '张三'
                    }, taskMethod: 1, taskMethodName: '需求生成',
                    status: 6,
                    statusName: '加药量待审核',
                    taskTime: '2025-01-22 12:23:35',
                    testTime: '2025-01-22',
                    needAdd: 444,
                    actualAdd: 444,
                    initialInspectionTime: '2025-01-23 11:12:23',
                    finishTime: '',
                    finishReason: '',
                    meterNum: 32,
                    condNum: 181,
                    auditResult: 1,
                    auditResultName: '审核通过',
                    auditOpinion: '审核通过',
                    auditUser: '张三',
                    auditTime: '2025-01-25 15:33:26',
                    drugBatch: '1002',
                    drugRecipient: '',
                    drugRecipientName: '张三',
                    drugTime: '2025-01-25 11:23:56',
                    meterNumTwo: 32,
                    condNumTwo: 32,
                    recheckUser: '李四',
                    recheckTime: '2025-01-26 11:23:23',
                    recheckSubmit: '2025-01-26 11:23:23'
                },

            ]
            this.page.total = this.data.length
            this.loading = false
            setTimeout(() => {
                this.selectionClear();
            }, 500)
        }
    }
}
</script>

<style></style>