上传为 pdf 格式的发票

131 阅读1分钟

需求:上传为 pdf 格式的发票,可以多选,拿到所选的发票信息上传给后端,后端返回发票信息,展示出......

image.png

 <el-upload action="#" :accept="'application/pdf'" ref="uploadRef" :before-upload="beforeUpload"
                        multiple :http-request="getFile" :on-change="onChangeFiles">
                        <el-button type="primary" round size="small" icon="el-icon-upload2">上传发票PDF
                        </el-button>
 </el-upload>
uploader(file) {
            // const data = new FormData();
            // data.append('file', file);
            // return axiosHttp.post('/upms/file/upload?fileType=file&dir=file/finance/', data);
            const data = new FormData();
            data.append('file', file);
            return uploadAndRecognizeInvoice(data)
        },
        onChangeFiles(file, fileList) {
            this.uploadedFiles = fileList.map(item => item.raw);
            Promise.all(Array.from(this.uploadedFiles).map(file => this.uploader(file))).then(res => {
                 this.invoiceData = res.map(item => item.data);

            })
        },
        getFile({ file }) {

        },
        beforeUpload() {
            this.uploadedFiles = [];
        },
        beforeUpload(file) {
            const isPdf = file.type === 'application/pdf';
            if (!isPdf) {
                this.$message.error('只能上传 PDF 格式的文件');
            }
            return isPdf;
        },