<template>
    <div class="app-container">
        <el-form :model="form" label-position="left" label-width="120px">
          <el-form-item label="订单号" v-if="order">
            {{order.orderNo}}
          </el-form-item>
          <el-form-item label="放货方式">
            <dict-selector :type="DICT_TYPE.ECW_HARVEST_METHOD" v-model="form.pickType" form-type="radio" formatter="number"></dict-selector>
          </el-form-item>
          <el-form-item label="提货时间" v-if="form.pickType == 1">
            <el-date-picker v-model="form.pickTime" placeholder="" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>

          <template v-if="form.pickType == 2">
            <el-form-item label="收货人">
                {{order.consigneeVO.name}}
            </el-form-item>
            <el-form-item label="收货电话">
                {{order.consigneeVO.countryCode}} {{order.consigneeVO.phone}}
            </el-form-item>
            <el-form-item label="收货地址">
                <!--缺少国城名字-->
                {{order.consigneeVO.address}}
            </el-form-item>
            <el-form-item label="快递单号">
                <el-input v-model="form.trackingNumber" placeholder=""></el-input>
            </el-form-item>
            <el-form-item label="送货时间">
                <el-date-picker v-model="form.deliverTime" placeholder="" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
            </el-form-item>
            <el-form-item label="签收时间">
                <el-date-picker v-model="form.pickTime" placeholder="" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
            </el-form-item>
          </template>

          <el-form-item label="附件">
            <image-upload v-model="form.attachment" />
          </el-form-item>
          
          <el-form-item label="备注">
            <el-input v-model="form.remark" type="textarea" placeholder=""></el-input>
          </el-form-item>
          <el-form-item label="">
            <el-button type="primary" @click="submit">确认放货</el-button>
            <el-button type="default" @click="$router.back()">取消</el-button>
          </el-form-item>          
        </el-form>
    </div>
</template>
<script>
import {getOrder, createOrderPickup} from '@/api/ecw/order'
import ImageUpload from '@/components/ImageUpload'
export default {
    components: {ImageUpload},
    data(){
        return {
            order: null,
            form: {}
        }
    },
    created(){
        this.loadOrderData()
    },
    methods:{
        loadOrderData(){
            getOrder(this.$route.query.orderId).then(res => {
                this.order = res.data
                this.$set(this.form, 'pickType', this.order.consigneeVO.harvestMethod)
            })
        },
        submit(){
            createOrderPickup(Object.assign({orderId: this.order.orderNo}, this.form)).then(res => {
                return this.$alert(res.message || '操作成功')
            }).then(res => {
                this.$router.back()
            })
        }
    }
}
</script>