<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="船公司类型">
        <el-select v-model="bookingObj.shipCompanyType" placeholder="请选择船公司类型">
          <el-option v-for="supplier in shipCompany" :key="supplier.id" :label="supplier.companyZh" :value="supplier.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="驳船港">
        <el-select v-model="bookingObj.bargePort" placeholder="请选择驳船港">
          <el-option v-for="dock in docks" :key="dock.id" :label="dock.titleZh" :value="dock.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="大船港">
        <el-select v-model="bookingObj.bigPort" placeholder="请选择大船港">
          <el-option v-for="dock in docks" :key="dock.id" :label="dock.titleZh" :value="dock.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="目的港">
        <el-select v-model="bookingObj.destPort" placeholder="请选择目的港">
          <el-option v-for="dock in docks" :key="dock.id" :label="dock.titleZh" :value="dock.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订舱公司">
        <el-select v-model="bookingObj.spaceCompany" placeholder="请选择订舱公司">
          <el-option v-for="supplier in suppliers" :key="supplier.id" :label="supplier.companyZh" :value="supplier.id"></el-option>
        </el-select>
      </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">
            <el-select v-model="bookingObj.feedTimePerson1" placeholder="请选择通知人">
            </el-select>
          </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">
            <el-select v-model="bookingObj.feedTimePerson" placeholder="请选择通知人">
            </el-select>
          </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">
            <el-select v-model="bookingObj.feedTimePerson" placeholder="请选择通知人">
            </el-select>
          </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">
            <el-select v-model="bookingObj.feedTimePerson" placeholder="请选择通知人">
            </el-select>
          </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 { getDockPage } from "@/api/ecw/dock";
import { booking, serviceMsg } from "@/api/ecw/boxSea";
/**
 * 订舱
 */
export default {
  name: "booking",
  props: {
    shipmentObj: Object,
    allSupplier: Array,
  },
  data() {
    return {
      // 订舱对象
      bookingObj: {},
      // 校验
      rules: {
        bargeTime: [{ required: true, message: "必填", trigger: "change" }],
        sailTime: [{ required: true, message: "必填", trigger: "change" }],
      },
      // 码头
      docks: [],
      // 供应商
      suppliers: this.allSupplier.filter((item) =>
        item.companyTypes.includes("1")
      ),
      // 船公司
      shipCompany: this.allSupplier.filter((item) =>
        item.companyTypes.includes("9")
      ),
    };
  },
  created() {
    getDockPage({ pageNo: "1", pageSize: "10000" }).then((res) => {
      const { data } = res;
      this.docks = data.list;
    });
  },
  methods: {
    /** 提交 */
    onSubmit() {
      this.$refs["bookingForm"].validate((valid) => {
        if (valid) {
          booking({
            shipmentId: shipmentObj.id,
            ...this.bookingObj,
            operateType: 2,
          }).then((res) => {
            serviceMsg(res, this).then(() => {
              this.cancel();
            });
          });
        }
      });
    },
    /** 取消 */
    cancel() {
      this.$emit("closeDialog");
    },
  },
};
</script>
