<template>
    <el-dialog title="分批" v-model="setCrewShow" :before-close="cancel" width="45%" @open="open">
        <el-form ref="form" :model="batchForm" :rules="batchRules" label-width="90">
            <el-form-item label="分批数量" prop="makeQty">
                <el-input-number style="width:100%;" controls-position="right" v-model="batchForm.makeQty"></el-input-number>
            </el-form-item>
            <el-form-item label="车间订单号" prop="woCode">
                <el-input disabled  v-model="batchForm.woCode"></el-input>
            </el-form-item>
            <el-form-item label="流程卡号" prop="cardNo">
                <el-input disabled  v-model="batchForm.cardNo"></el-input>
            </el-form-item>
            <el-form-item label="批次号" prop="batchNo">
                <el-input disabled  v-model="batchForm.batchNo"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="memo">
                <el-input type="textarea"  v-model="batchForm.memo"></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="cancel">取消</el-button>
                <el-button type="primary" @click="submit()"> 确认</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script>
import {getBatchData,setBatch} from "@/api/outsourcingManagement/oemOrder"
export default {
    props:{
        showBatch:{
            type:Boolean,
            default:false
        },
        checkRow:{
            type:Object,
            default:() => {}
        }
    },
    data(){
        return{
            setCrewShow:false,
            batchForm:{
                makeQty:1,
            },
            batchRules:{
                makeQty:[{required: true, message: '请输入分批数量', trigger: 'blur'}],
                woCode:[{required: true, message: '请输入车间订单号', trigger: 'blur'}],
                cardNo:[{required: true, message: '请输入流程卡号', trigger: 'blur'}],
                batchNo:[{required: true, message: '请输入批次号', trigger: 'blur'}],
            }
        }
    },
    created(){
        this.setCrewShow = this.showBatch;
        this.getData()
    },
    methods:{
        getData(){
            console.log('111111111111111')
            getBatchData({
                worId:this.checkRow.id
            }).then(res =>{
                console.log('res----------',res)
                this.batchForm = {
                    ...this.batchForm,
                    woCode:res.data.data.woCode,
                    cardNo:res.data.data.cardNo,
                    batchNo:res.data.data.batchNo
                }
            })
        },
        cancel(val){
            this.setCrewShow = false
            this.$emit('cancel', val);
        },
        submit(){
            this.$refs.form.validate((valid) => { 
                if(valid){
                    console.log('11111111111111111111111111111111111')
                    setBatch({
                        id:this.checkRow.woId,
                        ...this.batchForm
                    }).then(res =>{
                        if(res.data.code == 200){
                            this.$message.success('分批成功')
                            this.cancel(true)
                        }
                    }).catch(err =>{
                        this.cancel(false)
                    })
                }
            })
        }
    }
}
</script>

<style>

</style>