<template>
  <div>
    <el-form ref="airCheckoutForm" :model="airCheckoutObj" :rules="rules" label-width="80px">
      <el-form-item :label="$t('出仓日期')">
          <el-date-picker type="datetime" :placeholder="$t('请选择日期')" v-model="airCheckoutObj.checkoutTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
      </el-form-item>

      <el-form-item :label="$t('出仓影像')">
        <ImageUpload :limit="1" :isShowTip=false v-model="airCheckoutObj.checkoutFiles" />
      </el-form-item>

      <el-form-item :label="$t('备注')">
        <el-input type="textarea" :rows ="6" v-model="airCheckoutObj.remark" :placeholder="$t('备注')"></el-input>
      </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-row>
  </div>
</template>

<script>
import { airCheckoutCreate } from "@/api/ecw/boxSea";
import userSelect from "./common/userSelect.vue";
import ImageUpload from "@/components/ImageUpload";
import { constantDict, formatDateStr, formatNumberString, serviceMsg } from "../utils";

/**
 * 驳船
 */
export default {
  name: "checkout",
  inheritAttrs: false,
  components: { userSelect, ImageUpload },
  data() {
    return {
      // 空运出货对象
      airCheckoutObj: {},
      // 校验
      rules: {
        //deliverType: [{ required: true, message: this.$t("必填"), trigger: "change" }],
      },
    };
  },
  created() {
    const voName = this.$attrs.currNode.voName;
    let oldData = { ...this.$attrs.shipmentObj[voName] };
    oldData = formatDateStr(oldData, ["checkoutTime"]);
    this.airCheckoutObj = oldData;
  },
  methods: {
    /** 提交 */
    onSubmit(operateType) {
      this.$refs["airCheckoutForm"].validate((valid) => {
        if (valid) {
          airCheckoutCreate({
            ...this.airCheckoutObj,
            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>
</style>
