arrival.vue 4.42 KB
Newer Older
lanbaoming's avatar
lanbaoming committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
<template>
  <div>
    <el-form ref="arrivalForm" :rules="rules" :model="arrivalObj" label-width="120px">
      <el-form-item :label="$t('预计到港时间')">{{getExpectedTime()}}</el-form-item>
      <el-form-item :label="$t('实际到港时间')" prop="apRealTime">
        <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="arrivalObj.apRealTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
      </el-form-item>
      <el-form-item :label="$t('确认到港')">
        <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="arrivalObj.apConfirmTime" value-format="yyyy-MM-dd HH:mm:ss">
        </el-date-picker>
        <p class="message-area" v-show="showMsg">{{$t('请确认是否有异常,如有异常请进行异常登记')}}</p>
      </el-form-item>
      <el-form-item :label="$t('卸港时间')">
        <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="arrivalObj.apUnloadPortTime" 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)">{{$t('保存')}}</el-button>
      <el-button type="success" @click="onSubmit(2)">{{$t('提交')}}</el-button>
      <el-button @click="cancel">{{$t('关闭')}}</el-button>
      <el-button type="primary" @click="exceptionReg" :disabled="!showMsg">{{$t('异常登记')}}</el-button>
    </el-row>

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

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

/**
 * 到港
 */
export default {
  name: "arrival",
  inheritAttrs: false,
  components: {
    regError,
  },
  data() {
    return {
      // 到港对象
      arrivalObj: {},
      // 校验
      rules: {
        apRealTime: [
          { required: true, message: this.$t("必填"), trigger: "change" },
        ],
      },
      // 弹窗配置
      dialogVisible: false,
      // 提示消息
      showMsg: false,
      inspectionTimeArrival: this.getDictDatas(
        this.DICT_TYPE.BOX_INSPECTION_TIME_ARRIVAL
      )[0].value,
    };
  },
  created() {
    const voName = this.$attrs.currNode.voName;
    let oldData = { ...this.$attrs.shipmentObj[voName] };
    oldData = formatDateStr(
      oldData,
      ["apRealTime", "apConfirmTime"],
      "YYYY-MM-DD HH:mm:ss"
    );
    oldData = formatDateStr(oldData, ["apUnloadPortTime"]);
    this.arrivalObj = oldData;
  },
  watch: {
    // 确认到港时间
    "arrivalObj.apConfirmTime"(val) {
      this.compareDate(this.getExpectedTime(), val);
    },
  },
  methods: {
    regCloseDialog(type) {
      this.dialogVisible = false;
      if (type === "error") {
        this.$emit("getBoxInfo");
      }
    },
    // 获取预计到港时间
    getExpectedTime() {
      const { shippingInfo } = this.$attrs.shipmentObj;
      if (shippingInfo) {
        return dayjs(shippingInfo.dtEstArrivalTime).format(
          "YYYY-MM-DD HH:mm:ss"
        );
      }
      return null;
    },
    // 时间比较
    compareDate(expectedTime, apConfirmTime) {
      this.showMsg = false;
      let date1 = null,
        date2 = null;
      if (expectedTime) date1 = dayjs(expectedTime);
      if (apConfirmTime) date2 = dayjs(apConfirmTime);
      if (date1 && date2) {
        const days = date2.diff(date1, "day");
        if (days > this.inspectionTimeArrival) {
          this.showMsg = true;
        }
      }
    },
    // 异常登记
    exceptionReg() {
      this.dialogVisible = true;
    },
    /** 提交 */
    onSubmit(operateType) {
      this.$refs["arrivalForm"].validate((valid) => {
        if (valid) {
          arrivalCreate({
            ...this.arrivalObj,
            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>