us-tax-form-upload-comp.js 1.64 KB
/**
 * 组件描述:上传美国税务表格
 */
import api from "@/api/api";
import {
	formdata
} from '@/api/fetch-api.js'
import {
	Loading
} from 'vant';

export default {
	props: {
		// 是否显示组件
		// 1、顯示事故類型;2、顯示時間
		// 是否显示组件
		visible: {
			type: Boolean,
			default: false
		}
	},
	data() {
		return {
			fileName: "",
			file: null,
			iobsKey: "",
			loading: false,
			selected: false
		};
	},
	components: {},
	computed: {
		locale() {
			return this.$i18n.locale || "tc";
		}
	},
	methods: {
		initData() {
			this.file = null;
			this.iobsKey = "";
			this.loading = false;
			this.selected = false;
		},

		onOverLayHandler() {
			console.log("onOverLayHandler");
			this.$emit("close");
		},
		toDownLoadTaxForm() {
			window.open("https://www.irs.gov/");
		},
		onUploadHandler() {

			let file = this.file;
			if (!file) return;
			if (this.loading) return;
			this.loading = true;
			let myFormData = new FormData();
			myFormData.append("file", file);
			formdata({
					url: api.uploadFileIobs,
					myFormData: myFormData,
					sid: true
				})
				.then(res => {
					if (res && res.content) {
						this.loading = false;
						this.iobsKey = res.content;
						this.$emit("uploadsuccess");
						this.$emit("submit", this.iobsKey);
					} else {
						this.loading = false;
						this.$emit("uploaderr");
					}
				})
				.catch(err => {
					this.loading = false;
					this.$emit("uploaderr");
				});
		},
		selectImgs() {
			let _this = this;
			let file = this.$refs.file.files[0];
			this.file = file;
			this.selected = true;
		},
	},
	mounted() {},
	created() {
		this.initData();
	},
	watch: {}
};