<template>
    <el-dialog :title="$t('批量提货')" visible :before-close="closeDialog" :close-on-click-modal="false">
        <el-form ref="form" :model="form" :rules="rules">                
            <el-tabs v-model="current" type="card">
                <el-tab-pane :label="$t('全部提货')" name="createOrderPickupBatch">
                    <el-form-item :label="$t('订单号') + '/' + this.$t('提单号')" prop="orderId">
                        <el-input v-model="form.orderId" :placeholder="$t('例：NA2200001L')"></el-input>
                        <div>{{$t('注：单号之间使用逗号或空格隔开')}}</div>
                    </el-form-item>
                    <el-form-item :label="$t('提货时间')" prop="pickTime">
                        <el-date-picker v-model="form.pickTime" placeholder="" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                    </el-form-item>
                </el-tab-pane>
                <el-tab-pane :label="$t('分批提货')" name="createOrderPickupSplitBatch">
                    // TODO
                </el-tab-pane>
            </el-tabs>
            <el-form-item label="">
                <el-button type="primary" @click="submit">{{$t('提交')}}</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>
<script>
import {createOrderPickupBatch, createOrderPickupSplitBatch} from '@/api/ecw/order'
export default {
    props:{
        
    },
    data(){
        return {
            current: 'createOrderPickupBatch',
            show: false,
            form:{
                orderId: '',
                pickTime: '',
                pickType: 1
            },
            rules:{
                orderId: [{required: true, message: this.$t('请填写单号')}],
                pickTime: [{required: true, message: this.$t('请选择时间')}]
            }
        }
    },
    computed:{
        
    },
    created(){
        
    },
    methods:{
        submit(){
            this.$refs.form.validate().then(() => {
                if(this.form.orderId == '' || this.form.pickTime==''){
                    return this.$message.error(this.$t('请填写订单号和提货时间'))
                }
                let orderIdArr = this.form.orderId.replace(/,/g, ' ').split(' ').filter(item => item !='')
                let data = []
                for(let orderId of orderIdArr){
                    data.push({
                        pickType: 1,
                        orderId,
                        pickTime: this.form.pickTime
                    })
                }

                ({createOrderPickupBatch, createOrderPickupSplitBatch}[this.current])(data).then(res => {
                    this.$message.success(this.$t("操作成功"));
                    this.$emit('success')
                })
            })
        },
        closeDialog(){
            this.show = false
            this.$emit('close');
        }
    }
}
</script>