<template>
  <div>
    <el-form ref="bookingForm" :rules="rules" :model="bookingObj" label-width="140px">
      <el-form-item label="SO NO.">
        <el-input v-model="bookingObj.sono" placeholder="请输入SO NO."></el-input>
      </el-form-item>
      <el-form-item label="船公司类型">
        <supplierSelect v-model="bookingObj.shipCompanyType" :companyType="'9'" placeholder="请选择船公司类型" v-bind="$attrs" />
      </el-form-item>
      <el-form-item label="驳船港">
        <dockSelect v-model="bookingObj.bargePort" placeholder="请选择驳船港" v-bind="$attrs" />
      </el-form-item>
      <el-form-item label="大船港">
        <dockSelect v-model="bookingObj.bigPort" placeholder="请选择大船港" v-bind="$attrs" />
      </el-form-item>
      <el-form-item label="目的港">
        <dockSelect v-model="bookingObj.destPort" placeholder="请选择目的港" v-bind="$attrs" />
      </el-form-item>
      <el-form-item label="订舱公司">
        <supplierSelect v-model="bookingObj.spaceCompany" :companyType="'1'" placeholder="请选择订舱公司" v-bind="$attrs" />
      </el-form-item>
      <el-form-item label="预计驳船时间" prop="bargeTime">
        <el-date-picker type="date" placeholder="请选择日期" value-format="yyyy-MM-dd" v-model="bookingObj.bargeTime"></el-date-picker>
      </el-form-item>

      <el-row>
        <el-col :span="12">
          <el-form-item label="预计开船时间" prop="sailTime">
            <el-date-picker type="date" placeholder="请选择日期" value-format="yyyy-MM-dd" v-model="bookingObj.sailTime"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="通知人" label-width="80px">
            <userSelect v-model="bookingObj.feedTimePerson1" placeholder="请选择通知人" v-bind="$attrs" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="预计提单补料时间">
            <el-date-picker type="date" placeholder="请选择日期" value-format="yyyy-MM-dd" v-model="bookingObj.feedTime"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="通知人" label-width="80px">
            <userSelect v-model="bookingObj.feedTimePerson2" placeholder="请选择通知人" v-bind="$attrs" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="预计报关时间">
            <el-date-picker type="date" placeholder="请选择日期" value-format="yyyy-MM-dd" v-model="bookingObj.declarationTime"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="通知人" label-width="80px">
            <userSelect v-model="bookingObj.feedTimePerson3" placeholder="请选择通知人" v-bind="$attrs" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="预计截关时间">
            <el-date-picker type="date" placeholder="请选择日期" value-format="yyyy-MM-dd" v-model="bookingObj.cutOffTime"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="通知人" label-width="80px">
            <userSelect v-model="bookingObj.feedTimePerson4" placeholder="请选择通知人" v-bind="$attrs" />
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
    <el-row class="operate-button">
      <el-button type="primary" @click="onSubmit">提交</el-button>
      <el-button @click="cancel">关闭</el-button>
    </el-row>
  </div>

</template>

<script>
import { booking, serviceMsg } from "@/api/ecw/boxSea";
import supplierSelect from "./common/supplierSelect.vue";
import dockSelect from "./common/dockSelect.vue";
import userSelect from "./common/userSelect.vue";
/**
 * 订舱
 */
export default {
  name: "booking",
  components: {
    supplierSelect,
    dockSelect,
    userSelect,
  },
  props: {
    shipmentObj: Object,
  },
  data() {
    return {
      // 订舱对象
      bookingObj: {},
      // 校验
      rules: {
        bargeTime: [{ required: true, message: "必填", trigger: "change" }],
        sailTime: [{ required: true, message: "必填", trigger: "change" }],
      },
    };
  },
  created() {},
  methods: {
    /** 提交 */
    onSubmit() {
      this.$refs["bookingForm"].validate((valid) => {
        if (valid) {
          booking({
            shipmentId: this.$attrs.shipmentObj.id,
            ...this.bookingObj,
            operateType: 2,
          }).then((res) => {
            serviceMsg(res, this).then(() => {
              this.cancel();
            });
          });
        }
      });
    },
    /** 取消 */
    cancel() {
      this.$emit("closeDialog");
    },
  },
};
</script>
