<template>
    <ifrm ref="ifrm">
        <!-- 工序报废-->
        <uni-forms ref="form" err-show-type="toast">
            <uni-forms-item><input type="text" v-model="value" @confirm="valueConfirm" class="uni-input-border"
                    placeholder="流程卡号" /></uni-forms-item>
        </uni-forms>
        <t-table style="margin:20rpx 0">
            <t-tr>
                <t-td>流程卡号</t-td>
                <t-td>{{ obj.prWorkPlan.prWorkOrder.cardNo }}</t-td>
            </t-tr>
            <t-tr>
                <t-td>工序号</t-td>
                <t-td>{{ obj.prWorkPlan.procedureSet.ppsCode }}</t-td>
            </t-tr>
            <t-tr>
                <t-td>工序名称</t-td>
                <t-td>{{ obj.prWorkPlan.procedureSet.ppsName }}</t-td>
            </t-tr>
            <t-tr>
                <t-td>加工数量</t-td>
                <t-td>{{ obj.prWorkPlan.prWorkOrder.makeQty }}</t-td>
            </t-tr>
            <t-tr>
                <t-td>报废数量</t-td>
                <t-td><input type="number" :min="0" v-model="obj.scrapQty" /></t-td>
            </t-tr>
            <t-tr>
                <t-td>报废原因</t-td>
                <t-td><input type="text" v-model="obj.memo" /></t-td>
            </t-tr>
        </t-table>
        <view class="buttonBox"><button class="button" type="primary" @click="submitClick">确定</button></view>
    </ifrm>
</template>

<script>
    import ifrm from '@/pages/index/ifrm';
    import tTable from '@/components/t-table/t-table.vue';
    import tTh from '@/components/t-table/t-th.vue';
    import tTr from '@/components/t-table/t-tr.vue';
    import tTd from '@/components/t-table/t-td.vue';
    import scan from '../../mixin/scan.js';
    export default {
        mixins: [scan],
        components: {
            ifrm,
            tTable,
            tTh,
            tTr,
            tTd
        },
        data() {
            return {
                value: '',
                obj: {
                    prWorkPlan: {
                        prWorkOrder: {},
                        procedureSet: {}
                    }
                },
                scrapText: '',
                scrapNum: ''
            };
        },
        methods: {
            getBarCode(code) {
                this.getData(code);
            },
            valueConfirm(e) {
                this.getBarCode(e.target.value);
            },
            getData(code) {
                this.value = code;
                this.$ajax.request({
                    url: 'pdaLoad/loadProScrap/' + code,
                    method: 'GET',
                    success: data => {
                        console.log(data);
                        this.value = '';
                        this.obj = data;
                        uni.showToast({
                            title: '数据获取成功'
                        });
                    }
                });
            },
            submitClick() {
                if (this.scrapNum < 0 || this.obj.scrapQty > this.obj.prWorkPlan.prWorkOrder.makeQty) {
                    return uni.showToast({
                        title: '输入的报废数量有误，请重新输入',
                        icon: 'none'
                    });
                }
                this.$ajax.request({
                    url: 'pdaSave/saveProScrap',
                    method: 'POST',
                    data: this.obj,
                    success: data => {
                        uni.showToast({
                            title: '报废成功'
                        });
                        this.obj = {
                            prWorkPlan: {
                                prWorkOrder: {},
                                procedureSet: {}
                            }
                        };
                        this.value = '';
                    }
                });
            }
        },
        onNavigationBarButtonTap(btn) {
            this.$refs.ifrm.topMenuClick(btn);
        }
    };
</script>

<style scoped></style>