Dung Diego

up

...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
44 ocr_window : null 44 ocr_window : null
45 }, 45 },
46 mounted() { 46 mounted() {
47 -
48 }, 47 },
49 methods:{ 48 methods:{
50 upload_pdf(e){ 49 upload_pdf(e){
...@@ -60,12 +59,75 @@ ...@@ -60,12 +59,75 @@
60 } 59 }
61 }).then(res => { 60 }).then(res => {
62 this.ocr=res.data.ocr 61 this.ocr=res.data.ocr
63 - if(res.data.status) alert('Upload thành công'); 62 + if(res.data.status){
63 + alert('Upload thành công');
64 +
65 + }
64 else alert('Upload false'); 66 else alert('Upload false');
65 }).finally(() => { 67 }).finally(() => {
66 this.$refs.pdf.value = ''; 68 this.$refs.pdf.value = '';
67 }); 69 });
68 - } 70 + },
71 + openPdfWindow(options = {}){
72 + if(!(!!this.ocr && this.ocr.json_data)) return
73 + const params = new URLSearchParams({disable: 1,...options});
74 +
75 + const url = `/orders/preview-pdf?${params.toString()}`;
76 +
77 + let form = document.createElement('form')
78 +
79 + form.method = 'POST'
80 + form.action = url
81 + form.target = 'slave_window'
82 +
83 + const csrf = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
84 + if (csrf) {
85 + const csrfInput = document.createElement("input");
86 + csrfInput.type = "hidden";
87 + csrfInput.name = "_token";
88 + csrfInput.value = csrf;
89 + form.appendChild(csrfInput);
90 + }
91 +
92 + function appendFormData(form, obj, parentKey = "") {
93 + Object.entries(obj).forEach(([key, value]) => {
94 + const fullKey = parentKey ? `${parentKey}[${key}]` : key;
95 + if(key === 'json_data') return
96 + if (typeof value === "object" && value !== null) {
97 + appendFormData(form, value, fullKey);
98 + } else {
99 + const input = document.createElement( "input");
100 + input.type = "hidden";
101 + input.name = fullKey;
102 + input.value = value;
103 + form.appendChild(input);
104 + }
105 + });
106 + }
107 +
108 + appendFormData(form, this.ocr);
109 +
110 + document.body.appendChild(form)
111 +
112 + this.ocr_window = window.open(url,'slave_window','width=1200,height=800')
113 + form.submit()
114 + form.remove()
115 +
116 + window.addEventListener('message', e => {
117 + if(e.data.type === 'mapping-field'){
118 + this.handle_map_field(e.data.template_field,e.data.text)
119 + }
120 + if(e.data.type === 'mapping-customer'){
121 + this.handle_map_customer(e.data.customer)
122 + }
123 + });
124 +
125 + window.addEventListener('beforeunload', () => {
126 + if(this.ocr_window && !this.ocr_window.closed){
127 + this.ocr_window.close();
128 + }
129 + });
130 + },
69 } 131 }
70 }) 132 })
71 </script> 133 </script>
......