<template>
    <basic-container>
        <avue-crud :option="option" :table-loading="loading" :data="data" v-model:page="page" :before-open="beforeOpen"
            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="addReview(1,null)">零件模式</el-button>
            <el-button type="primary"  @click="addReview(2,null)">装配模式</el-button> -->
            </template>
            <template #menu-right>
                <el-button type="primary" plain   @click="openZlSystem">质量系统 </el-button>
            </template>
            <template #menu="{ row }">
                <el-button type="text" @click="addReview(row.trialType, row.id)">详情</el-button>
                <el-button type="text" v-if="row.status == 0 || row.status == -1" @click="hearingFn(row.trialType, row.id)">提交</el-button>
            </template>
            <!-- <template #proNo="{ row }">
                {{ row.prWorkCheck.prWorkPlan.prWorkOrder.pjYieldOrder.partCode }}
            </template>
            <template #proName="{ row }">
                {{ row.prWorkCheck.prWorkPlan.prWorkOrder.pjYieldOrder.partName }}
            </template>
            <template #proClass="{ row }">
                {{ row.prWorkCheck.prWorkPlan.prWorkOrder.pjYieldOrder.productType }}
            </template>
            <template #identification="{ row }">
                {{ row.prWorkCheck.prWorkPlan.prWorkOrder.pjYieldOrder.productType }}
            </template>
            <template #batchNo="{ row }">
                {{ row.prWorkCheck.prWorkPlan.prWorkOrder.pjYieldOrder.batchNo }}
            </template>
            <template #qualifiedQty="{ row }">
                {{ row.prWorkCheck.prWorkPlan.qualifiedQty }}
            </template>
            <template #unqualQty="{ row }">
                {{ row.prWorkCheck.prWorkPlan.unqualifiedQty }}
            </template>
            <template #userName="{ row }">
                {{ row.createMan.userName }}
            </template> -->
            <template #proNo-form="{ type }">
                <span v-show="type == 'view'">
                    {{ form.prWorkCheck.prWorkPlan.prWorkOrder.pjYieldOrder.partCode }}
                </span>
            </template>
            <template #proName-form="{ type }">
                <span v-show="type == 'view'">
                    {{ form.prWorkCheck.prWorkPlan.prWorkOrder.pjYieldOrder.partName }}
                </span>
            </template>
            <template #proClass-form="{ type }">
                <span v-show="type == 'view'">
                    {{ form.prWorkCheck.prWorkPlan.prWorkOrder.pjYieldOrder.productType }}
                </span>
            </template>
            <template #identification-form="{ type }">
                <span v-show="type == 'view'">
                    {{ form.prWorkCheck.prWorkPlan.prWorkOrder.pjYieldOrder.productType }}
                </span>
            </template>
            <template #batchNo-form="{ type }">
                <span v-show="type == 'view'">
                    {{ form.prWorkCheck.prWorkPlan.prWorkOrder.pjYieldOrder.batchNo }}
                </span>
            </template>
            <template #qualifiedQty-form="{ type }">
                <span v-show="type == 'view'">
                    {{ form.prWorkCheck.prWorkPlan.qualifiedQty }}
                </span>
            </template>
            <template #unqualQty-form="{ type }">
                <span v-show="type == 'view'">
                    {{ form.prWorkCheck.prWorkPlan.unqualifiedQty }}
                </span>
            </template>
            <template #userName-form="{ type }">
                <span v-show="type == 'view'">
                    {{ form.createMan.userName }}
                </span>
            </template>
        </avue-crud>
        <pattern-dialog v-if="showDialog" :show-dialog="showDialog" :rs-id="rsId" @closeDialog="closeDialog"
            :trial-type="trialType"></pattern-dialog>

        <!-- 提交 -->
        <hearingDialog v-if="hearingOpen" :type="dialogType" :rs-id="rsId" :show-dialog="hearingOpen" @closeDialog="closeDialog"></hearingDialog>
    </basic-container>
</template>

<script>
import {getProductionDispositionList} from "@/api/qualityManagement/productionTesting/productionDisposition.js"
import patternDialog from './patternDialog.vue'
import hearingDialog from './hearingDialog.vue'
export default {
    components: {
        patternDialog,
        hearingDialog
    },
    data() {
        return {
            loading: false,
            data: [],
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            trialType: null,
            showDialog: false,
            rsId: null,
            dialogType:'',
            form: {},
            option: {
                tip: false,
                align: 'center',
                calcHeight:32,
                height: 'auto',
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                searchIcon: true,
                searchIndex: 3,
                tree: false,
                border: true,
                selection: false,
                viewBtn: false,
                editBtn: false,
                addBtn: false,
                delBtn: false,
                editBtnText: '修改',
                // viewBtnText: '详情',
                labelWidth: 120,
                menuWidth: 100,
                dialogWidth: 1200,
                dialogClickModal: false,
                searchEnter: true,
                excelBtn: false,
                filterBtn: true,
                searchShowBtn: false,
                excelBtn: true,
                index: true,
                showOverflowTooltip: true,
                searchLabelPosition: 'left',
                searchGutter: 24,
                searchSpan: 6,
                menuAlign: 'left',
                gridBtn: false,
                searchMenuPosition: 'right',
                addBtnIcon: ' ',
                viewBtnIcon: ' ',
                delBtnIcon: ' ',
                editBtnIcon: ' ',
                column: [
                    {
                        label: '上级编号',
                        prop: 'upCode',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: true,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入上级编号',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '单据编号',
                        prop: 'docCode',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: true,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入单据编号',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '车间订单号',
                        prop: 'woCode',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: true,
                        width: 200,
                        searchLabelWidth:100,
                        rules: [
                            {
                                required: true,
                                message: '请输入单据编号',
                                trigger: 'click',
                            },
                        ],
                    },

                    {
                        label: '产品号',
                        prop: 'prodCode',
                        // bind:"base.prodCode",
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: true,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入产品号',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '产品名称',
                        prop: 'prodName',
                        // bind:"base.prodName",
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: true,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入产品名称',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '产品型号',
                        prop: 'prodTypeName',
                        // bind:"base.prodTypeName",
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: true,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入产品型号',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '生产标识',
                        prop: 'prodIdent',
                        type: 'select',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: true,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入生产标识',
                                trigger: 'click',
                            },
                        ],
                        dicUrl:"/api/blade-desk/BA/ProdMark/listForSelect",
                        props:{label:"name",value:"id"}
                    },
                    {
                        label: '批次号',
                        prop: 'batchNo',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: true,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入批次号',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '流程卡号',
                        prop: 'cardNo',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: true,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入单据编号',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '生产数量',
                        prop: 'poQty',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: false,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入生产数量',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '不合格数量',
                        prop: 'unqualifiedQty',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: false,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入不合格数量',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '申请人',
                        prop: 'userName',
                        bind:'base.createUserRealName',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: false,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入申请人',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '建立时间',
                        prop: 'createTime',
                        type:"date",
                        format:"YYYY-MM-DD",
                        valueFormat:"YYYY-MM-DD",
                        searchRange: true,
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        search: true,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入建立时间',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '处置单类型',
                        prop: 'reviewOrderMode',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        type: 'select',
                        search: true,
                        width: 200,
                        searchLabelWidth:90,
                        rules: [
                            {
                                required: true,
                                message: '请输入处置单类型',
                                trigger: 'click',
                            },
                        ],
                        dicUrl:"/api/blade-system/dict/dictionary?code=ReviewSheet-Mode",
                        props:{
                            label: 'dictValue',
                            value: 'dictKey'
                        }
                        // dicData: [
                        //     {
                        //         value: 1,
                        //         label: '零件模式'
                        //     }, {
                        //         value: 2,
                        //         label: '装配模式'
                        //     }, {
                        //         value: 3,
                        //         label: '售后模式'
                        //     }
                        // ]
                    },
                    {
                        label: '当前状态',
                        prop: 'status',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        type: 'select',
                        search: true,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入当前状态',
                                trigger: 'click',
                            },
                        ],
                        props:{
                            label:'dictValue',
                            value:'dictKey',
                        },
                        dicUrl:'/api/blade-system/dict/dictionary?code=ReviewSheet-Status', //字典中取值
                        // dicData: [
                        //     {
                        //         value: 1,
                        //         label: '新建'
                        //     }, {
                        //         value: 3,
                        //         label: '打回'
                        //     }, {
                        //         value: 6,
                        //         label: '审理中'
                        //     }, {
                        //         value: 10,
                        //         label: '审理完成'
                        //     }
                        // ]
                    },
                    {
                        label: '打回人',
                        prop: 'backUserRealName',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入打回人',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '打回时间',
                        prop: 'backDate',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入打回时间',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '打回原因',
                        prop: 'backReason',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入打回原因',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '审理状态',
                        prop: 'reviewStatusName',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入审理状态',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '审理人',
                        prop: 'reviewUserRealName',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入审理人',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '审理时间',
                        prop: 'reviewDate',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入审理时间',
                                trigger: 'click',
                            },
                        ],
                    },
                    {
                        label: '审理意见',
                        prop: 'memo',
                        addDisplay: false,
                        editDisplay: false,
                        span: 24,
                        width: 200,
                        rules: [
                            {
                                required: true,
                                message: '请输入审理意见',
                                trigger: 'click',
                            },
                        ],
                    },
                ]

            },
            hearingOpen:false,
        }
    },
    mounted() {

    },
    methods: {
        // 提交
        hearingFn(val,id) {
            this.rsId = id
            this.dialogType = 'submit'
            this.hearingOpen = true
        },
        closeDialog(val) {
            this.showDialog = false
            this.hearingOpen = false
            if(val){ 
                this.onLoad()
            }
        },
        // 跳转质量系统
        openZlSystem() {
            let url = 'http://192.168.119.68:8088/mms/login/login_158.jsp?LOGIN158=jinna&sourceURI=/mms/console/index&TIMESTAMP=1758684792912&MD5STR=f6802064486cb328cbff1e312521f641'
            window.open(url)
        },
        addReview(type, id) {
            this.rsId = id
            this.dialogType = 'view'
            this.trialType = type
            this.hearingOpen = true
        },
        rowSave(row, done, loading) {

        },
        rowUpdate(row, index, done, loading) {

        },
        searchReset() {
            this.query = {};
            this.onLoad(this.page);
        },
        searchChange(params, done) {
            this.query = params;
            this.page.currentPage = 1;
            this.query.createTimeStart = params.createTime && params.createTime.length != 0 && params.createTime[0]
            this.query.createTimeEnd = params.createTime && params.createTime.length != 0 && params.createTime[1]
            if(this.query.createTime) delete this.query.createTime
            this.onLoad(this.page, params);
            done();
        },
        selectionChange(list) {
            this.selectionList = list;
        },
        selectionClear() {
            this.selectionList = [];
            this.$refs.crud.toggleSelection();
        },
        currentChange(currentPage) {
            this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
            this.page.pageSize = pageSize;
        },
        refreshChange() {
            this.onLoad(this.page, this.query);
        },
        onLoad() {
            // if(this.query.createTime){
            //     delete this.query.createTime
            // }
            getProductionDispositionList({
                current:this.page.currentPage,
                size:this.page.pageSize,
                ...this.query
            }).then(res =>{
                res.data.data.records.map(item =>{
                    item.status = item.status == -1 ? '' : item.status + ''
                })
                this.data = res.data.data.records
                this.page.total = res.data.data.total
            })
            // this.data = [
            //     {
            //         rsId: 22,
            //         supCode: 'WO-S23041025-R02', rsCode: 'DJ-S23041025-R02',
            //         prWorkCheck: {
            //             prWorkPlan: {
            //                 prWorkOrder: {
            //                     pjYieldOrder: {
            //                         partCode: 'CP-S23041025-R02',
            //                         partName: '产品名称',
            //                         productType: '产品型号',
            //                         prodIdent: '生产标识',
            //                         batchNo: '批次号'
            //                     }
            //                 },
            //                 qualifiedQty: 10,
            //                 unqualifiedQty: 5,
            //             }
            //         },
            //         createMan: {
            //             userName: '张三'
            //         },
            //         createTime: '2024-12-21 10:05:22',
            //         trialTypeTitle: '零件模式',
            //         trialType: 1,
            //         curStatusTitle: '新建',
            //         repulseMan: '李四',
            //         repulseTime: '2024-12-24 11:02:23',
            //         repulseMemo: '不合格',
            //         reviewStatusTitle: '审理中',
            //         reviewMan: '李四',
            //         reviewTime: '2024-12-30 15:23:32',
            //         memo: '通过'
            //     },
            //     {
            //         rsId: 23,
            //         supCode: 'WO-S23041025-R02', rsCode: 'DJ-S23041025-R02',
            //         prWorkCheck: {
            //             prWorkPlan: {
            //                 prWorkOrder: {
            //                     pjYieldOrder: {
            //                         partCode: 'CP-S23041025-R02',
            //                         partName: '产品名称',
            //                         productType: '产品型号',
            //                         prodIdent: '生产标识',
            //                         batchNo: '批次号'
            //                     }
            //                 },
            //                 qualifiedQty: 10,
            //                 unqualifiedQty: 5,
            //             }
            //         },
            //         createMan: {
            //             userName: '张三'
            //         },
            //         createTime: '2024-12-21 10:05:22',
            //         trialTypeTitle: '零件模式',
            //         trialType: 1,
            //         curStatusTitle: '新建',
            //         repulseMan: '李四',
            //         repulseTime: '2024-12-24 11:02:23',
            //         repulseMemo: '不合格',
            //         reviewStatusTitle: '审理中',
            //         reviewMan: '李四',
            //         reviewTime: '2024-12-30 15:23:32',
            //         memo: '通过'
            //     }
            // ]
            // this.page.total = this.data.length
        },
    }
}
</script>

<style></style>