Dung Diego

up

......@@ -44,7 +44,6 @@
ocr_window : null
},
mounted() {
},
methods:{
upload_pdf(e){
......@@ -60,12 +59,75 @@
}
}).then(res => {
this.ocr=res.data.ocr
if(res.data.status) alert('Upload thành công');
if(res.data.status){
alert('Upload thành công');
}
else alert('Upload false');
}).finally(() => {
this.$refs.pdf.value = '';
});
},
openPdfWindow(options = {}){
if(!(!!this.ocr && this.ocr.json_data)) return
const params = new URLSearchParams({disable: 1,...options});
const url = `/orders/preview-pdf?${params.toString()}`;
let form = document.createElement('form')
form.method = 'POST'
form.action = url
form.target = 'slave_window'
const csrf = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
if (csrf) {
const csrfInput = document.createElement("input");
csrfInput.type = "hidden";
csrfInput.name = "_token";
csrfInput.value = csrf;
form.appendChild(csrfInput);
}
function appendFormData(form, obj, parentKey = "") {
Object.entries(obj).forEach(([key, value]) => {
const fullKey = parentKey ? `${parentKey}[${key}]` : key;
if(key === 'json_data') return
if (typeof value === "object" && value !== null) {
appendFormData(form, value, fullKey);
} else {
const input = document.createElement( "input");
input.type = "hidden";
input.name = fullKey;
input.value = value;
form.appendChild(input);
}
});
}
appendFormData(form, this.ocr);
document.body.appendChild(form)
this.ocr_window = window.open(url,'slave_window','width=1200,height=800')
form.submit()
form.remove()
window.addEventListener('message', e => {
if(e.data.type === 'mapping-field'){
this.handle_map_field(e.data.template_field,e.data.text)
}
if(e.data.type === 'mapping-customer'){
this.handle_map_customer(e.data.customer)
}
});
window.addEventListener('beforeunload', () => {
if(this.ocr_window && !this.ocr_window.closed){
this.ocr_window.close();
}
});
},
}
})
</script>
......