mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 19:51:07 +03:30
266 lines
9.0 KiB
Vue
266 lines
9.0 KiB
Vue
<template>
|
|
<v-form ref="form">
|
|
<v-container grid-list-xs>
|
|
<material-card color="black" title="Submit Test Result">
|
|
<v-layout
|
|
align-center
|
|
justify-center
|
|
wrap
|
|
class="px-5 my-3"
|
|
v-if="!$route.params.testResult"
|
|
>
|
|
<v-flex xs12 sm4 md4>
|
|
<v-autocomplete
|
|
:search-input.sync="searchInput"
|
|
:items="testTypeNames"
|
|
v-model="filter.name"
|
|
label="Choose Test Type"
|
|
color="black"
|
|
class="pa-2"
|
|
></v-autocomplete>
|
|
</v-flex>
|
|
<v-flex xs12 sm3 md3>
|
|
<v-text-field
|
|
name="testcode"
|
|
v-model="filter.unique_code"
|
|
label="Or Enter Test Unique Code"
|
|
color="black"
|
|
class="pa-2"
|
|
></v-text-field>
|
|
</v-flex>
|
|
<v-flex xs12 md2 sm2 class="text-xs-center text-sm-center text-md-center">
|
|
<v-btn
|
|
class="WM-NoShadow WM-Outline-Btn WM-Border WM-Border-Black"
|
|
@click="selectTestType"
|
|
style="padding:10px 60px;"
|
|
>
|
|
<v-icon class="black--text mr-2 caption">fas fa-chevron-right</v-icon>
|
|
<span class="black--text">GO</span>
|
|
</v-btn>
|
|
</v-flex>
|
|
</v-layout>
|
|
<v-layout row wrap class="px-5 my-3" v-if="!$route.params.testResult">
|
|
<v-divider></v-divider>
|
|
</v-layout>
|
|
<v-layout align-center justify-center wrap class="px-5 my-3">
|
|
<v-flex xs12 sm4 md3>
|
|
<v-text-field
|
|
name="autoclave"
|
|
v-model="formData.autoclave_id"
|
|
label="ID AutoClave"
|
|
color="black"
|
|
class="pa-2"
|
|
></v-text-field>
|
|
</v-flex>
|
|
<v-flex xs12 sm4 md3>
|
|
<v-select
|
|
:items="result"
|
|
v-model="formData.result"
|
|
label="Resualt"
|
|
color="black"
|
|
class="pa-2"
|
|
></v-select>
|
|
</v-flex>
|
|
<v-flex xs12 sm4 md3>
|
|
<div v-if="!image">
|
|
<input type="file" @change="onFileChange">
|
|
</div>
|
|
<div v-else>
|
|
<img :src="image" style="width:100%;"/>
|
|
<button @click="removeImage">Remove image</button>
|
|
</div>
|
|
</v-flex>
|
|
<v-flex :class="['pa-2', item.size]" v-for="(item, key) in form" :key="key">
|
|
<v-text-field
|
|
v-if="item.type == 'Text'"
|
|
v-model="formData[item.name]"
|
|
:label="item.name"
|
|
color="black"
|
|
></v-text-field>
|
|
<v-select
|
|
multiple
|
|
v-if="item.type == 'Select'"
|
|
:items="item.options"
|
|
v-model="formData[item.name]"
|
|
:label="item.name"
|
|
color="black"
|
|
item-text="title"
|
|
item-value="id"
|
|
></v-select>
|
|
<v-container fluid v-if="item.type == 'Checkbox'">
|
|
<p>{{ item.name }}</p>
|
|
<v-checkbox
|
|
v-for="(optionValue, keyOption) in item.options"
|
|
:key="keyOption"
|
|
:label="optionValue.title"
|
|
v-model="formData[item.name]"
|
|
:value="optionValue.id"
|
|
></v-checkbox>
|
|
</v-container>
|
|
<template v-if="item.type == 'Form'">
|
|
<v-layout row wrap>
|
|
<h3>{{ item.name }}</h3>
|
|
</v-layout>
|
|
<v-layout row wrap>
|
|
<v-flex
|
|
:class="['pa-2', children.size]"
|
|
v-for="(children, keyChildren) in item.children"
|
|
:key="keyChildren"
|
|
>
|
|
<v-text-field
|
|
v-if="children.type == 'Text'"
|
|
v-model="formData[children.name]"
|
|
:label="children.name"
|
|
color="black"
|
|
></v-text-field>
|
|
<v-select
|
|
multiple
|
|
v-if="children.type == 'Select'"
|
|
:items="children.options"
|
|
v-model="formData[children.name]"
|
|
:label="children.name"
|
|
color="black"
|
|
item-text="title"
|
|
item-value="id"
|
|
></v-select>
|
|
<v-container fluid v-if="children.type == 'Checkbox'">
|
|
<p>{{ children.name }}</p>
|
|
<v-checkbox
|
|
v-for="(optionValue, keyOption) in children.options"
|
|
:key="keyOption"
|
|
:label="optionValue.title"
|
|
v-model="formData[children.name]"
|
|
:value="optionValue.id"
|
|
></v-checkbox>
|
|
</v-container>
|
|
</v-flex>
|
|
</v-layout>
|
|
</template>
|
|
</v-flex>
|
|
</v-layout>
|
|
<v-layout row wrap class="px-5 my-3">
|
|
<v-divider></v-divider>
|
|
</v-layout>
|
|
<v-layout align-center justify-center wrap class="px-5 mt-2">
|
|
<v-btn class="WM-CyanBlueGradient-BG" style="padding:10px 60px" @click="submitForm">
|
|
<v-icon class="white--text mr-2 caption">fas fa-check</v-icon>
|
|
<span class="white--text">SAVE</span>
|
|
</v-btn>
|
|
<router-link :to="{name: 'Dashboard'}">
|
|
<v-btn class="WM-NoShadow WM-Outline-Btn WM-Border WM-Border-Black ml-5">
|
|
<v-icon class="black--text mr-2 caption">fas fa-chevron-left</v-icon>
|
|
<span class="black--text">Back</span>
|
|
</v-btn>
|
|
</router-link>
|
|
</v-layout>
|
|
</material-card>
|
|
</v-container>
|
|
</v-form>
|
|
</template>
|
|
<script>
|
|
import { ApiService } from "@/services";
|
|
import { urls } from "@/config/urls";
|
|
export default {
|
|
data: () => ({
|
|
result: ["Accept", "Reject"],
|
|
testTypeNames: [],
|
|
searchInput: "",
|
|
form: [],
|
|
filter: {
|
|
test_result_id: "",
|
|
name: "",
|
|
unique_code: ""
|
|
},
|
|
formData : {
|
|
autoclave_id: "",
|
|
result: "",
|
|
img: null,
|
|
test_type_id: "",
|
|
},
|
|
image: null,
|
|
}),
|
|
created() {
|
|
if (this.$route.params.testResult) {
|
|
this.filter.test_result_id = this.$route.params.testResult;
|
|
this.selectTestType();
|
|
}
|
|
this.load();
|
|
|
|
},
|
|
methods: {
|
|
async load() {
|
|
const result = await ApiService.get(urls.listTestTypeName);
|
|
this.testTypeNames = result.data.data;
|
|
},
|
|
async selectTestType() {
|
|
const result = await ApiService.post(urls.getInputs, this.filter);
|
|
if (result && result.status == 200) {
|
|
this.form = result.data.data.inputs;
|
|
this.formData.test_type_id = result.data.data.testType.id;
|
|
for (const key in result.data.data.inputs) {
|
|
if (result.data.data.inputs.hasOwnProperty(key)) {
|
|
if(result.data.data.inputs[key].type == 'Form') {
|
|
for (const keyForm in result.data.data.inputs[key].children) {
|
|
if (result.data.data.inputs[key].children.hasOwnProperty(keyForm)) {
|
|
if (result.data.data.inputs[key].children[keyForm].type == 'Checkbox' || result.data.data.inputs[key].children[keyForm].type == 'Select' ) {
|
|
this.formData[result.data.data.inputs[key].children[keyForm].name] = [];
|
|
} else {
|
|
this.formData[result.data.data.inputs[key].children[keyForm].name] = '';
|
|
}
|
|
}
|
|
}
|
|
} else if(result.data.data.inputs[key].type == 'Checkbox' || result.data.data.inputs[key].type == 'Select') {
|
|
this.formData[result.data.data.inputs[key].name] = [];
|
|
} else {
|
|
this.formData[result.data.data.inputs[key].name] = '';
|
|
}
|
|
}
|
|
}
|
|
if (this.$route.params.testResult) {
|
|
const result = await ApiService.get(urls.editTestResult(this.$route.params.testResult));
|
|
if (result && result.status == 200) {
|
|
this.formData = result.data.data;
|
|
}
|
|
}
|
|
}
|
|
},
|
|
async submitForm() {
|
|
let result;
|
|
if (this.$route.params.testResult) {
|
|
result = await ApiService.put(urls.updateTestResult(this.$route.params.testResult), this.formData);
|
|
} else {
|
|
result = await ApiService.post(urls.storeTestResult, this.formData);
|
|
}
|
|
|
|
if (result && result.status == 200) {
|
|
this.$router.push({name: 'Dashboard'})
|
|
}
|
|
},
|
|
onFileChange(e) {
|
|
var files = e.target.files || e.dataTransfer.files;
|
|
if (!files.length)
|
|
return;
|
|
this.createImage(files[0]);
|
|
},
|
|
createImage(file) {
|
|
var image = new Image();
|
|
var reader = new FileReader();
|
|
var vm = this;
|
|
|
|
reader.onload = (e) => {
|
|
vm.image = e.target.result;
|
|
};
|
|
|
|
reader.readAsDataURL(file);
|
|
},
|
|
removeImage: function (e) {
|
|
this.image = null;
|
|
},
|
|
},
|
|
watch:{
|
|
image(img) {
|
|
this.formData.img = img;
|
|
}
|
|
}
|
|
};
|
|
</script> |