cusClearance.vue 4.17 KB
Newer Older
huhaiqing's avatar
huhaiqing committed
1 2 3
<template>
  <div>
    <el-form ref="cusClearanceForm" :rules="rules" :model="cusClearanceObj" label-width="120px">
4 5 6
      <el-form-item :label="$t('清关代理')">{{getClAgent('label')}}</el-form-item>
      <el-form-item :label="$t('预计清关时间')" prop="clEstTime">
        <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="cusClearanceObj.clEstTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
huhaiqing's avatar
huhaiqing committed
7
      </el-form-item>
8 9 10
      <el-form-item :label="$t('清关时间')" prop="clClearTime">
        <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="cusClearanceObj.clClearTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
        <p class="message-area" v-show="showMsg">{{$t('清关时间与预计时间不符,如有异常请登记')}}</p>
huhaiqing's avatar
huhaiqing committed
11 12 13 14
      </el-form-item>
    </el-form>

    <el-row class="operate-button">
15 16 17 18
      <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>
huhaiqing's avatar
huhaiqing committed
19 20 21
    </el-row>

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

<script>
huhaiqing's avatar
huhaiqing committed
29
import regError from "../../regError";
huhaiqing's avatar
huhaiqing committed
30
import dayjs from "dayjs";
huhaiqing's avatar
huhaiqing committed
31 32
import { clearanceCreate } from "@/api/ecw/boxSea";
import { formatDateStr, serviceMsg } from "../utils";
huhaiqing's avatar
huhaiqing committed
33 34 35 36 37 38

/**
 * 清关
 */
export default {
  name: "cusClearance",
huhaiqing's avatar
huhaiqing committed
39
  inheritAttrs: false,
huhaiqing's avatar
huhaiqing committed
40 41 42 43 44 45
  components: {
    regError,
  },
  data() {
    return {
      // 清关对象
huhaiqing's avatar
huhaiqing committed
46
      cusClearanceObj: {},
huhaiqing's avatar
huhaiqing committed
47 48
      // 校验
      rules: {
huhaiqing's avatar
huhaiqing committed
49 50 51 52 53 54
        clEstTime: [
          { required: true, message: this.$t("必填"), trigger: "change" },
        ],
        clClearTime: [
          { required: true, message: this.$t("必填"), trigger: "change" },
        ],
huhaiqing's avatar
huhaiqing committed
55 56 57 58 59 60 61
      },
      // 弹窗配置
      dialogVisible: false,
      // 提示消息
      showMsg: false,
    };
  },
huhaiqing's avatar
huhaiqing committed
62 63 64
  created() {
    const voName = this.$attrs.currNode.voName;
    let oldData = { ...this.$attrs.shipmentObj[voName] };
huhaiqing's avatar
huhaiqing committed
65 66
    oldData = formatDateStr(oldData, ["clEstTime"]);
    oldData = formatDateStr(oldData, ["clClearTime"], "YYYY-MM-DD HH:mm:ss");
huhaiqing's avatar
huhaiqing committed
67 68
    this.cusClearanceObj = oldData;
  },
huhaiqing's avatar
huhaiqing committed
69 70
  watch: {
    // 预计清关时间
huhaiqing's avatar
huhaiqing committed
71 72
    "cusClearanceObj.clEstTime"(val) {
      this.compareDate(val, this.cusClearanceObj.clClearTime);
huhaiqing's avatar
huhaiqing committed
73 74
    },
    // 清关时间
huhaiqing's avatar
huhaiqing committed
75 76
    "cusClearanceObj.clClearTime"(val) {
      this.compareDate(this.cusClearanceObj.clEstTime, val);
huhaiqing's avatar
huhaiqing committed
77 78 79
    },
  },
  methods: {
huhaiqing's avatar
huhaiqing committed
80 81 82
    getClAgent(type) {
      const agentId = this.$attrs.shipmentObj.agentInfo.agentId;
      if (type === "label") {
huhaiqing's avatar
huhaiqing committed
83 84
        const selected = this.$attrs.allSupplier.find(
          (item) => item.id === agentId
huhaiqing's avatar
huhaiqing committed
85
        );
huhaiqing's avatar
huhaiqing committed
86
        return this.$l(selected, "company") ?? agentId;
huhaiqing's avatar
huhaiqing committed
87 88 89
      }
      return agentId;
    },
huhaiqing's avatar
huhaiqing committed
90
    // 时间比较
huhaiqing's avatar
huhaiqing committed
91
    compareDate(clEstTime, clClearTime) {
huhaiqing's avatar
huhaiqing committed
92 93 94
      this.showMsg = false;
      let date1 = null,
        date2 = null;
huhaiqing's avatar
huhaiqing committed
95 96
      if (clEstTime) date1 = dayjs(clEstTime);
      if (clClearTime) date2 = dayjs(clClearTime);
huhaiqing's avatar
huhaiqing committed
97
      if (date1 && date2 && !date2.isSame(date1)) {
huhaiqing's avatar
huhaiqing committed
98 99 100 101 102 103 104 105
        this.showMsg = true;
      }
    },
    // 异常登记
    exceptionReg() {
      this.dialogVisible = true;
    },
    /** 提交 */
huhaiqing's avatar
huhaiqing committed
106
    onSubmit(operateType) {
huhaiqing's avatar
huhaiqing committed
107 108
      this.$refs["cusClearanceForm"].validate((valid) => {
        if (valid) {
huhaiqing's avatar
huhaiqing committed
109 110 111
          clearanceCreate({
            ...this.cusClearanceObj,
            shipmentId: this.$attrs.shipmentObj.id,
huhaiqing's avatar
huhaiqing committed
112
            clAgentId: this.getClAgent(),
huhaiqing's avatar
huhaiqing committed
113 114 115
            operateType,
          }).then((res) => {
            serviceMsg(res, this).then(() => {
huhaiqing's avatar
huhaiqing committed
116
              this.cancel("submit");
huhaiqing's avatar
huhaiqing committed
117 118
            });
          });
huhaiqing's avatar
huhaiqing committed
119 120 121 122
        }
      });
    },
    /** 取消 */
huhaiqing's avatar
huhaiqing committed
123 124
    cancel(type) {
      this.$emit("closeDialog", type);
huhaiqing's avatar
huhaiqing committed
125 126 127 128 129 130 131 132 133 134 135
    },
  },
};
</script>

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