<template>
  <div>
    <el-form ref="blCopyForm" :model="blCopyObj" label-width="120px">
      <el-form-item :label="$t('提单Copy')">
        <FileUpload :limit="1" :isShowTip=false v-model="blCopyObj.copyUrl" :fileType="fileType" />
      </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 { ladingCopyCreate } from "@/api/ecw/boxSea";
import FileUpload from "@/components/FileUpload";
import { fileTypes, serviceMsg } from "../utils";

/**
 * 提单copy
 */
export default {
  name: "blCopy",
  inheritAttrs: false,
  components: { FileUpload },
  data() {
    return {
      // 提单copy对象
      blCopyObj: {},
      // 文件格式
      fileType: fileTypes,
    };
  },
  created() {
    const voName = this.$attrs.currNode.voName;
    let oldData = { ...this.$attrs.shipmentObj[voName] };
    this.blCopyObj = oldData;
  },
  methods: {
    /** 提交 */
    onSubmit(operateType) {
      this.$refs["blCopyForm"].validate((valid) => {
        if (valid) {
          ladingCopyCreate({
            ...this.blCopyObj,
            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>
