<template>
    <el-container>
        <el-header>
            <div class="left-panel">
            </div>
            <div class="right-panel">
                <el-date-picker v-model="query.test_date" type="date" value-format="YYYY-MM-DD" />
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" row-key="id" stripe :params="params" :query="query">
                <el-table-column type="index" width="50" />
                <el-table-column label="产品名称" prop="material_name" show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="批次号" prop="batch">
                </el-table-column>
                <el-table-column label="总袋（桶）数" prop="count_bag">
                </el-table-column>
                <el-table-column label="抽样数量" prop="count_sampling">
                </el-table-column>
                <el-table-column label="称重记录/Kg" prop="weight_kgs">
                </el-table-column>
                <el-table-column label="抽样计算总重量/Kg" prop="production_date">
                    <template #default="scope">
                        {{ countWeight(scope.row) }}
                    </template>
                </el-table-column>
                <el-table-column label="合同采购量/Kg" prop="buy_date">
                </el-table-column>
                <el-table-column label="检验结论">
                    <template #default="scope">
                        <el-tag v-if="scope.row.is_testok" type="success">
                            合格
                        </el-tag>
                        <el-tag v-else type="danger">
                            不合格
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="检验员" prop="test_user_name">
                </el-table-column>
                <el-table-column label="检验日期" prop="test_date">
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
</template>
<script>
export default {
    name: "rparty",
    data() {
        return {
            apiObj: this.$API.inm.mioitem.list,
            query: {
                test_date: '',
            },
            params: { type: 20, mio__type: 'pur_in' },
            selection: [],
            state_: {
                10: '',
                20: '',
            },
        };
    },
    methods: {
        //查看
        table_show(row) {
            this.dialog.save = true;
            this.$nextTick(() => {
                this.$refs.saveDialog.open("show", 10).setData(row);
            });
        },
        handleQuery() {
            this.$refs.table.queryData(this.query)
        },
        countWeight(row) {
            let weight = 0, single = 0, allW = 0;
            let kgs = row.weight_kgs;
            if (kgs.length > 0) {
                kgs.forEach(item => {
                    weight += item;
                });
                single = weight / kgs.length;
                allW = single * row.count_bag;
            }
            return allW;
        },
        resetQuery() {
            this.query = {};
        },
    },
};
</script>