<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_SHIPPING_TRAILER_STATUS)" :key="type.value" :label="type.label" :value="type.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="拖车公司">
        <supplierSelect v-model="trailerObj.tlCompanyId" :companyType="'4'" placeholder="请选择拖车公司" :allSupplier="this.$attrs.allSupplier" />
      </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 } from "@/api/ecw/boxSea";
import supplierSelect from "./common/supplierSelect.vue";
import {
  formatStringNumber,
  formatDateStr,
  formatNumberString,
  serviceMsg,
} from "../utils";
/**
 * 拖车
 */
export default {
  inheritAttrs: false,
  name: "trailer",
  components: { supplierSelect },
  data() {
    return {
      // 拖车对象
      trailerObj: {},
      // 校验
      rules: {
        tlTime: [{ required: true, message: "必填", trigger: "change" }],
      },
    };
  },
  created() {
    const { currNode, shipmentObj } = this.$attrs;
    const voName = currNode.voName;
    let oldData = { ...shipmentObj[voName] };
    oldData = formatNumberString(oldData, ["tlContainerStatus"]);
    oldData = formatStringNumber(oldData, ["tlCompanyId"]);
    oldData = formatDateStr(oldData, ["tlTime"]);
    this.trailerObj = oldData;
  },
  methods: {
    /** 提交 */
    onSubmit(operateType) {
      this.$refs["trailerForm"].validate((valid) => {
        if (valid) {
          trailer({
            ...this.trailerObj,
            shipmentId: this.$attrs.shipmentObj.id,
            operateType,
          }).then((res) => {
            serviceMsg(res, this).then(() => {
              this.cancel("submit");
            });
          });
        }
      });
    },
    /** 取消 */
    cancel(type) {
      this.$emit("closeDialog", type);
    },
  },
};
</script>
