<template>
  <div>
    <el-form ref="twoWayArrivalForm" :rules="rules" :model="twoWayArrivalObj" label-width="120px">
      <el-form-item label="预计到达时间" prop="estTime">
        <el-date-picker type="datetime" placeholder="请选择日期" v-model="twoWayArrivalObj.estTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
      </el-form-item>
      <el-form-item label="实际到达时间" prop="actTime">
        <el-date-picker type="datetime" placeholder="请选择日期" v-model="twoWayArrivalObj.actTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
      </el-form-item>
      <el-form-item label="实际二程时间" prop="actSecondTime">
        <el-date-picker type="datetime" placeholder="请选择日期" v-model="twoWayArrivalObj.actSecondTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
      </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-button type="primary" @click="exceptionReg">异常登记</el-button>
    </el-row>

    <!-- 对话框 -->
    <el-dialog custom-class="shipping-dialog" title="异常登记" :visible.sync="dialogVisible" width="700px" :modal-append-to-body=false append-to-body destroy-on-close>
      <regError @closeDialog="dialogVisible = false" v-bind="$attrs" />
    </el-dialog>
  </div>
</template>

<script>
import regError from "../../regError";
import { arrivalCreate } from "@/api/ecw/boxSeaAir";
import { formatDateStr, serviceMsg } from "../utils";

/**
 * 起飞
 */
export default {
  name: "twoWayArrival",
  inheritAttrs: false,
  components: {
    regError,
  },
  data() {
    return {
      // 清关对象
      twoWayArrivalObj: {},
      // 校验
      rules: {
        actTime: [{ required: true, message: "必填", trigger: "blur" }]
      },
      // 弹窗配置
      dialogVisible: false,
      // 提示消息
      showMsg: false,
    };
  },
  created() {
    const voName = this.$attrs.currNode.voName;
    let oldData = { ...this.$attrs.shipmentObj[voName] };
    oldData = formatDateStr(oldData, ["actTime"], "YYYY-MM-DD HH:mm:ss");
    oldData = formatDateStr(oldData, ["actSecondTime"], "YYYY-MM-DD HH:mm:ss");
    oldData = formatDateStr(oldData, ["estTime"], "YYYY-MM-DD HH:mm:ss");
    this.twoWayArrivalObj = oldData;
  },
  watch: {
  },
  methods: {
    // 异常登记
    exceptionReg() {
      this.dialogVisible = true;
    },
    /** 提交 */
    onSubmit(operateType) {
      this.$refs["twoWayArrivalForm"].validate((valid) => {
        if (valid) {
          arrivalCreate({
            ...this.twoWayArrivalObj,
            shipmentId: this.$attrs.shipmentObj.id,
            operateType,
          }).then((res) => {
            serviceMsg(res, this).then(() => {
              this.cancel("submit");
            });
          });
        }
      });
    },
    /** 取消 */
    cancel(type) {
      this.$emit("closeDialog", type);
    },
  },
};
</script>

<style lang="scss" scoped>
.message-area {
  margin: 0;
  color: red;
}
</style>
