<template>
  <div>
    <el-form ref="trailerForm" :rules="rules" :model="trailerObj" label-width="120px">
      <el-form-item label="状态">
        <el-select v-model="trailerObj.tlContainerStatus" placeholder="请选择状态">
          <el-option v-for="type in this.getDictDatas(DICT_TYPE.BOX_SHIPMENT_TRAILER_STATUS)" :key="type.value" :label="type.label" :value="type.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="拖车公司">
        <el-select v-model="trailerObj.tlCompanyId" 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="tlTime">
        <el-date-picker type="date" placeholder="请选择日期" value-format="yyyy-MM-dd" v-model="trailerObj.tlTime"></el-date-picker>
      </el-form-item>
      <el-form-item label="车牌">
        <el-input v-model="trailerObj.tlLicensePlate	" placeholder="请输入车牌"></el-input>
      </el-form-item>
      <el-form-item label="司机">
        <el-input v-model="trailerObj.tlDriver" placeholder="请输入司机"></el-input>
      </el-form-item>
      <el-form-item label="司机联系方式">
        <el-input v-model="trailerObj.tlDriverContact" placeholder="请输入司机联系方式"></el-input>
      </el-form-item>
      <el-form-item label="货柜号">
        <el-input v-model="trailerObj.tlContainerNo" placeholder="请输入货柜号"></el-input>
      </el-form-item>
      <el-form-item label="封条">
        <el-input v-model="trailerObj.tlStripSeal" placeholder="请输入封条"></el-input>
      </el-form-item>
    </el-form>
    <el-row class="operate-button">
      <el-button type="primary" @click="onSubmit(1)">保存</el-button>
      <el-button type="success" @click="onSubmit(2)">提交</el-button>
      <el-button @click="cancel">关闭</el-button>
    </el-row>
  </div>
</template>

<script>
import { trailer, serviceMsg } from "@/api/ecw/boxSea";
/**
 * 拖车
 */
export default {
  name: "trailer",
  props: {
    shipmentObj: Object,
    allSupplier: Array,
  },
  data() {
    return {
      // 拖车对象
      trailerObj: {},
      // 校验
      rules: {
        tlTime: [{ required: true, message: "必填", trigger: "change" }],
      },
      // 拖车公司
      suppliers: this.allSupplier.filter((item) =>
        item.companyTypes.includes("4")
      ),
    };
  },
  methods: {
    /** 提交 */
    onSubmit(operateType) {
      this.$refs["trailerForm"].validate((valid) => {
        if (valid) {
          trailer({
            ...this.trailerObj,
            shipmentId: shipmentObj.id,
            operateType,
          }).then((res) => {
            serviceMsg(res, this).then(() => {
              this.cancel();
            });
          });
        }
      });
    },
    /** 取消 */
    cancel() {
      this.$emit("closeDialog");
    },
  },
};
</script>
