Я не могу загрузить изображение из одного из моих всплывающих диалоговых окон, но я могу загрузить из другого, используя ту же самую функцию. Это работает во втором диалоге (editDialog), но не в первом (потреблениеDialog). Вывод переменных, связанных с файлом загрузки изображений / для правильного (editDialog) в консоли:
idf: files_uploader
app.js:238600 file1: [object File]
app.js:238609 num of picture1
app.js:238614 file: [object File]
Вывод переменных, связанных с файлом загрузки изображений для сбойного файла (editDialog) в консоли:
app.js:238597 idf: files_uploader
app.js:238600 file1: undefined
app.js:238609 num of picture1
Любая помощь по этому вопросу с благодарностью! Мой код ниже:
<!-- Intake Dialog -->
<v-dialog
v-model="intakeDialog"
width="700"
>
<v-card>
<v-card-title
class="headline grey lighten-2 p-3"
primary-title
>
<span>{{current_sample.number}}</span>
<v-spacer></v-spacer>
<span>{{current_sample.sample_accession}}</span>
</v-card-title>
<v-container>
<v-layout wrap class="form-blocks">
<v-flex>
<p><v-flex sm3 v-for="media in current_sample.media" :key="media.id">
<v-btn @click="delete_image(media.id)">[X]</v-btn> <img :src="'https://orderinformation.s3.amazonaws.com/' + media.path" class="rotateImg" />
</v-flex> </p>
</v-flex>
<v-flex sm10>
<label class="m-l-1 m-r-1"><p style="font-weight: bold">Image Uploader </p></label>
<input type="file"
name = "file"
class="form-control-file border"
id="files_uploader"
multiple
ref="image"
accept="image/*"
placeholder="Order #"
v-on:change="fileValidation(1), previewFile()"/>
<img style="height:80px; margin:15px; visibility: hidden;"
src=""
height="80"
alt="Sample preview..."
class="PreviewImage"/>
</v-flex>
<v-flex sm2>
<label class="m-l-1 m-r-1"><p style="font-weight: bold; color:red">Make Image Default?</p></label>
<b-form-checkbox
id="default_check"
v-model="current_sample.status"
name="default_check"
value="default"
unchecked-value="not_default"
>
</b-form-checkbox>
</v-flex>
</v-layout>
</v-container>
<v-divider></v-divider>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="red"
text
@click="intakeDialog = false, current_sample={}"
>
Cancel
</v-btn>
<v-btn
color="green darken-1"
@click="upload_image()"
>
Submit
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<!-- Edit Dialog -->
<v-dialog
v-model="editDialog"
width="700"
class="editDialog"
>
<v-card>
<v-card-title
class="headline grey lighten-2 p-3"
primary-title
>
<span>{{current_sample.number}} / {{current_sample.batch_no}} / {{current_sample.sample_accession}}</span>
<v-spacer></v-spacer>
<span></span>
</v-card-title>
<v-container>
<v-layout wrap class="form-blocks">
<label class="m-l-1 m-r-1"><p style="font-weight: bold; font-size:24px !important; line-height: 32px !important">Sample Verification</p></label>
<table width="100%">
<tr valign="top" colspan="3">
<td width="33%">
<v-layout wrap class="form-blocks">
<label class="m-l-1 m-r-1">Sample Verified </label>
<b-form-checkbox
id="accepted_check"
v-model="current_sample.accepted_for_testing"
name="accepted_check"
value="Yes"
unchecked-value="No"
>
</b-form-checkbox>
</v-layout>
</td>
<td width="33%">
<v-layout wrap class="form-blocks"><label class="m-l-1 m-r-1">Accession ID fixed? </label>
<b-form-checkbox
id="accession_id_check"
v-model="current_sample.accession_id_fixed"
name="accession_id_check"
value="1"
unchecked-value="0"
>
</b-form-checkbox>
</v-layout>
</td>
<td width="33%">
<v-layout wrap class="form-blocks"><label class="m-l-1 m-r-1">Batch# Validated </label>
<b-form-checkbox
id="bash_no_check"
v-model="current_sample.batch_no"
name="bash_no_check"
value="1"
unchecked-value="0"
>
</b-form-checkbox>
</v-layout>
</td>
</tr>
<tr colspan="3">
<td>
<v-layout wrap class="form-blocks"><label class="m-l-1 m-r-1">Sample Rejected </label>
<b-form-checkbox
id="rejected_no_check"
v-model="current_sample.sample_rejected"
name="rejected_no_check"
value="Yes"
unchecked-value="No"
>
<div class="container" v-if="current_sample.sample_rejected">
<v-text-field
label="Rejection Comments"
v-model="current_sample.rejection_comment"
name="rejection_comment"
class="break">
</v-text-field>
</div>
</b-form-checkbox>
</v-layout>
</td>
</tr>
</table>
<v-flex sm10>
<div id="selector" class="flex-row">
<div class="container" id="app-container">
<table>
<tr>
<td>
<v-select
v-model="current_sample.sample_received_date_time_1"
:items="datesList"
label="Select dates"
item-text="date"
id="select_dates"
value="2019-10-01" >
</v-select>
</td>
<td>
<v-select
v-model="current_sample.sample_received_date_time_2"
:items="hourList"
label="Select hour"
item-text="hour"
id="select_hour"
value="2019-10-01"
>
</v-select>
</td>
<td>
<v-select
v-model="current_sample.sample_received_date_time_3"
:items="minuteList"
label="Select minute"
item-text="minute"
id="select_minute"
value="2019-10-01"
>
</v-select>
</td>
</tr>
</table>
</div>
</div>
<input type="file"
name = "file"
class="form-control-file border"
id="files_uploader"
multiple
ref="image"
accept="image/*"
placeholder="Order #"
v-on:change="fileValidation(1), previewFile()"/>
<v-flex>
<p>
<v-flex sm3 v-for="media in current_sample.media" :key="media.id">
<v-btn @click="delete_image(media.id)">[X] </v-btn> <img :src="'https://orderinformation.s3.amazonaws.com/' + media.path" class="rotateImg PreviewImage" />
</v-flex>
</p>
</v-flex>
</v-flex>
</v-layout>
</v-container>
<v-divider></v-divider>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="red"
text
@click="editDialog = false, current_sample={}"
>
Cancel
</v-btn>
<v-btn
color="green darken-1"
@click="updateOrderInfo(current_sample), upload_image()"
>
Submit
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<script>
methods: {
upload_image(value = 0, accession = '696668')
{
let idf = (value = 0) ? 'file_uploader' : 'files_uploader';
console.log("idf: " + idf);
this.uploading = true;
let file = document.getElementById(idf).files[0];
console.log("file1: " + file);
let accession_number = `${this.current_sample.sample_accession}`;
var order_number = `${this.current_sample.number}`;
var order_details_id = `${this.current_sample.id}`;
var checkdefault = `${this.current_sample.status}`;
/*for(i=0; i<current_sample.media.length; i++)
{
}*/
console.log("num of picture" + Object.keys(this.current_sample.media).length);
if (Object.keys(this.current_sample.media).length <= 1) {
if (file) {
// create reader
console.log("file: " + file);
let reader = new FileReader();
reader.readAsText(file);
reader.onload = function (e) {
// browser completed reading file - display it
// alert(e.target.result);
let formData = new FormData();
formData.append("order_number", order_number);
formData.append("order_details_id", order_details_id);
formData.append("file", file);
formData.append("acession_number", accession_number);
formData.append("checkdefault", checkdefault);
axios
.post("/api/order_master/uploadPicture", formData, {
headers: {
"Content-Type": "multipart/form-data"
}
})
.then(response => {
this.upload = null;
this.imagename = null;
this.uploading = false;
file = null;
this.closeModal();
this.snackbar.text = `Sample ${this.current_sample.sample_accession} picture(s) weight has been upload!`;
this.snackbar.color = "success";
this.snackbar.show = true;
}).catch((error) => {
console.error(error);
this.snackbar.text = "A problem occurred, try again!";
this.snackbar.color = "danger";
this.snackbar.show = true;
});
}
}
}
}
,
//1671
fileValidation: function (value = 0) {
// let idf = ( value = 0 )?'file_uploader': 'files_uploader';
let fileInput = document.getElementById('files_uploader');
let filePath = fileInput.value;
let allowedExtensions = /(\.jpg|\.jpeg|\.png|\.svg|\.gif)$/i;
if (!allowedExtensions.exec(filePath)) {
alert('Please upload file having extensions .jpeg/.jpg/.png/.gif only.');
fileInput.value = '';
return false;
} else {
//Image preview
if (fileInput.files && fileInput.files[0]) {
let reader = new FileReader();
reader.onload = function (e) {
let id = (value = 0) ? 'imagePreview' : 'imagesPreview';
document.getElementById(id).innerHTML = '<img src="' + e.target.result + '"/>';
};
reader.readAsDataURL(fileInput.files[0]);
}
}
}
}
</script>