<template>
	<el-container>
		<el-side>
            <el-container>
                <el-header style="height: 40px;">
                    <el-input
                        v-model="query.search"
                        placeholder="请输入物料编号"
                        clearable
                        style="width: 150px;"
                    >
                    </el-input>
                    <el-button type="primary" @click="search">查询</el-button>
                </el-header>
                <el-main style="padding: 0 1px;">
                    <scTable
                        ref="tablets"
                        :apiObj="apiObj"
                        row-key="id"
                        :query="query"
                        stripe
                        @row-click="rowClick"
                        hideDo
                        :paginationLayout="'total, sizes, jumper'"
                    >
                <el-table-column prop="number" label="物料编号"></el-table-column>
            </scTable>
                </el-main>
            </el-container>
		</el-side>
		<el-main id="elMain">
           <el-container>
                <el-header style="height: 150px;">
                    <el-descriptions :column="3">
                        <el-descriptions-item label="物料名称" width="30vw">
                            <span v-if="wprItem.material_name">{{wprItem.material_name}}</span>
                        </el-descriptions-item>
                        <el-descriptions-item label="物料编号" width="30vw">
                            <span v-if="wprItem.number">{{wprItem.number}}</span>
                        </el-descriptions-item>
                        <el-descriptions-item label="所属部门" width="30vw">
                            <span v-if="wprItem.belong_dept_name">{{wprItem.belong_dept_name}}</span>
                        </el-descriptions-item>
                        <el-descriptions-item label="所属工段" width="30vw">
                            <span v-if="wprItem.mgroup_name">{{wprItem.mgroup_name}}</span>
                        </el-descriptions-item>
                        <el-descriptions-item label="批次号" width="30vw">
                            <span v-if="wprItem.batch">{{wprItem.batch}}</span>
                        </el-descriptions-item>
                        <el-descriptions-item label="原始物料" width="30vw">
                            <span v-if="wprItem.material_ofrom_name">{{wprItem.material_ofrom_name}}</span>
                        </el-descriptions-item>
                        <el-descriptions-item label="原始批次" width="30vw">
                            <span v-if="wprItem.batch_ofrom">{{wprItem.batch_ofrom}}</span>
                        </el-descriptions-item>
                        
                    </el-descriptions>
                </el-header>
                <el-main style="padding: 0 1px;">
                    <el-tabs type="border-card" v-model="activeName" style="height: 100%;" lazy>
                        <el-tab-pane name="mlog" label="生产日志" style="height: 100%;">
                            <el-container v-if="activeName=='mlog'">
                                <el-main>
                                    <scTable
                                        ref="tableMlog"
                                        :apiObj="apiObj_mlog"
                                        row-key="id"
                                        :params="params_mlog"
                                    >
                                        <el-table-column label="#" type="index" width="50" fixed></el-table-column>
                                        <el-table-column label="工艺路线" prop="material_out_name" min-width="130" fixed>
                                        <template #default="scope">
                                            <span v-if="scope.row.material_out_name!==null">{{scope.row.material_out_name}}</span>
                                            <span v-else>返工</span>
                                        </template>
                                        </el-table-column>
                                        <el-table-column label="生产设备" prop="equipment_name" min-width="150"></el-table-column>
                                        <el-table-column label="加工数" prop="count_real"></el-table-column>
                                        <el-table-column label="合格数" prop="count_ok"></el-table-column>
                                        <el-table-column label="类型">
                                            <template #default="scope">
                                                <el-tag v-if="scope.row.is_fix" type="warning">返修</el-tag>
                                                <el-tag v-else type="primary">正常</el-tag>
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="部门/工段">
                                            <template #default="scope">
                                                {{scope.row.belong_dept_name}}/{{scope.row.mgroup_name}}
                                            </template>
                                        </el-table-column>
                                        <el-table-column
                                            label="处理人"
                                            prop="handle_user_name"
                                            width="80"
                                        ></el-table-column>
                                        <el-table-column label="保温剩余时间" v-if="mgroup_name=='黑化'||mgroup_name=='退火'">
                                            <template #default="scope">
                                                {{ getRemaTime(scope.row) }}
                                            </template>
                                        </el-table-column>
                                        <el-table-column
                                            label="操作日期"
                                            prop="handle_date"
                                        ></el-table-column>
                                        <el-table-column label="是否提交" prop="submit_time">
                                            <template #default="scope">
                                                <span v-if="scope.row.submit_time!==null" style="color: green;">是</span>
                                                <span v-else>否</span>
                                            </template>
                                        </el-table-column>
                                    </scTable>
                                </el-main>
                            </el-container>
                        </el-tab-pane>
                        <el-tab-pane name="handover" label="交接记录" style="height: 100%;">
                            <el-container v-if="activeName=='handover'">
                                <el-main>
                                    <scTable
                                        ref="tableHandover"
                                        :apiObj="apiObj_handover"
                                        row-key="id"
                                        :params="params_handover"
                                    >
                                        <el-table-column
                                            label="#"
                                            type="index"
                                            width="50"
                                        ></el-table-column>
                                        <el-table-column type="expand">
                                            <template #default="props">
                                                <div style="padding-left: 50px">
                                                    <template v-for="item in props.row.handoverb" :key="item.id">
                                                        <el-descriptions :column="3">
                                                            <el-descriptions-item label="批次">
                                                                {{item.batch}}
                                                            </el-descriptions-item>
                                                            <el-descriptions-item label="数量">
                                                                {{item.count}}
                                                            </el-descriptions-item>
                                                            <el-descriptions-item label="不合格标记" v-if="item.defect_name!==null">
                                                                {{item.defect_name}}
                                                            </el-descriptions-item>
                                                        </el-descriptions>
                                                    </template>
                                                </div>
                                            </template>
                                        </el-table-column>
                                        <el-table-column
                                            label="物料"
                                            prop="material_name"
                                            min-width="140"
                                        ></el-table-column>
                                        <el-table-column label="批次" prop="batch" min-width="80">
                                            <template #default="scope">
                                                <el-text v-if="scope.row.handoverb.length>0" type="primary">{{scope.row.handoverb.length}}批</el-text>
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="数量" prop="count" min-width="80"></el-table-column>
                                        <el-table-column label="交接类别" prop="type" width="80">
                                            <template #default="scope">
                                                <el-tag v-if="scope.row.type == 10" type="primary">正常</el-tag>
                                                <el-tag v-if="scope.row.type == 20" type="warning">返工</el-tag>
                                                <el-tag v-if="scope.row.type == 40" type="danger" >报废</el-tag>
                                                <el-tag v-if="scope.row.type == 50" type="success" >改版</el-tag>
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="交接类型" prop="mtype" min-width="80">
                                            <template #default="scope">
                                                <el-text v-if="scope.row.mtype == 10" type="primary">正常</el-text>
                                                <el-text v-if="scope.row.mtype == 20" type="success">分批</el-text>
                                                <el-text v-if="scope.row.mtype == 30" type="success">合批</el-text>
                                            </template>
                                        </el-table-column>
                                         <el-table-column label="交送工段" prop="send_mgroup_name" min-width="80">
                                        </el-table-column>
                                        <el-table-column
                                            label="交送人"
                                            prop="send_user_name"
                                            width="80"
                                        ></el-table-column>
                                         <el-table-column label="接收工段" prop="recive_mgroup_name" min-width="80">
                                        </el-table-column>
                                        <el-table-column
                                            label="接收人"
                                            prop="recive_user_name"
                                            width="80"
                                        ></el-table-column>
                                        <el-table-column
                                            label="交接日期"
                                            prop="send_date"
                                            width="120"
                                        ></el-table-column>
                                    </scTable>
                                </el-main>
                            </el-container>
                        </el-tab-pane>
                        <el-tab-pane name="mio" label="出入库记录" style="height: 100%;">
                            <el-container v-if="activeName=='mio'">
                                <el-main>
                                    <scTable
                                        ref="tableMio"
                                        :apiObj="apiObj_mio"
                                        row-key="id"
                                        :params="params_mio"
                                    >
                                        <el-table-column label="#" type="index" width="40"></el-table-column>
                                        <el-table-column label="记录编号" prop="number" min-width="80"></el-table-column>
                                        <el-table-column label="出入库类型" prop="type">
                                            <template #default="scope">{{ typeDict[scope.row.type] }}</template>
                                        </el-table-column>
                                        <el-table-column label="执行部门" prop="belong_dept_name">
                                        </el-table-column>
                                        <el-table-column label="工段" prop="mgroup_name">
                                        </el-table-column>
                                        <el-table-column label="状态" prop="type" width="80">
                                            <template #default="scope">
                                               {{ stateDict[scope.row.state] }}
                                            </template>
                                        </el-table-column>
                                        <el-table-column label="部门执行人" prop="do_user_name" ></el-table-column>
                                        <el-table-column label="仓库执行人" prop="mio_user_name"></el-table-column>
                                        <el-table-column label="日期" prop="inout_date"></el-table-column>
                                    </scTable>
                                </el-main>
                            </el-container>
                        </el-tab-pane>
                    </el-tabs>
                </el-main>
           </el-container>
		</el-main>
	</el-container>
</template>
<script>
import { wmState } from "@/utils/enum.js";
export default {
	name: "batch_statistics",
	data() {
		return {
            wmState,
            apiObj:this.$API.wpm.wpr.list,
            wprItem:{},
            query:{
                search:'',
            },
            params_mio:{
                item_mio__w_mioitem__number:'',
            },
            params_mlog:{
                cnumber:'',
            },
            params_handover:{
                b_handover__w_handoverb__number:'',
            },
            stateDict: {
				10: "创建中",
				20: "已提交",
			},
            typeDict: {
				do_out: "生产领料",
				sale_out: "销售发货",
				pur_in: "采购入库",
				do_in: "生产入库",
				other_in: "其他入库",
				other_out: "其他出库",
			},
            batch:'',
            activeName:'',
            limitedWatch:false,
            apiObj_mlog:null,
            apiObj_handover:null,
            apiObj_mio:null,
		};
	},
	mounted() {
	},
	methods: {
        rowClick(row){
            console.log('row',row)
            let that = this;
            that.nodes =[];
            that.edges = [];
             that.wprItem = {};
            that.wprItem.material_name = row.material_name;
            that.wprItem.number = row.number;
            that.activeName = 'mlog';
			that.$API.wpm.wpr.item.req(row.id).then((res) => {
                if(res.wm_!==null){
                    that.wprItem = res.wm_;
                    that.wprItem.number = row.number;
                }
                that.params_mio.item_mio__w_mioitem__number = row.number;
                that.params_mlog.cnumber = row.number;
                that.params_handover.b_handover__w_handoverb__number = row.number;
                that.apiObj_mlog = that.$API.wpm.mlog.list;
                that.apiObj_handover = that.$API.wpm.handover.list;
                that.apiObj_mio = that.$API.inm.mio.list;
                that.$refs.tableMlog.queryData(that.params_mlog);
                that.$refs.tableHandover.queryData(that.params_handover);
                that.$refs.tableMio.queryData(that.params_mio);
			})
        },
    
        search(){
            this.$refs.tablets.queryData(this.query)
        },
	},
};
</script>

<style scoped>

</style>
