/
form_file.vue
112 lines (104 loc) · 2.92 KB
/
form_file.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<template>
<div>
<section>
<h1>{{ response.details.inquiry_name }}</h1>
<div>
<template v-for="line in textLines2texts(response.details.inquiry_info)">
{{ line }}<br>
</template>
</div>
<div v-if="submitted">
<template v-for="line in textLines2texts(response.details.thanks_text)">
{{ line }}<br>
</template>
</div>
<form v-else>
<div v-if="error" class="error">
<p v-for="(err, idx) in error" :key="idx" style="color: red">
{{ err.message }}
</p>
</div>
<div>
<dl>
<dt>Name</dt>
<dd><input v-model="submitData.name" name='name' type="text"></dd>
</dl>
<dl>
<dt>Email</dt>
<dd><input v-model="submitData.from_mail" name='from_mail' type="text"></dd>
</dl>
<dl>
<dt>Message</dt>
<dd><textarea v-model="submitData.body" name='body'></textarea></dd>
</dl>
<dl>
<dt>Item</dt>
<dd>
<select v-model="submitData.ext_01" name='ext_01'>
<option v-for="option in response.details.cols.ext_01.options" :key="option.key" :label=option.value :value=option.key>
{{ option.value }}
</option>
</select>
</dd>
</dl>
<dl>
<dt>Date</dt>
<dd><input v-model="submitData.ext_02" name='ext_02' type="date"></dd>
</dl>
<dl>
<dt>File</dt>
<dd><input type="file" name='ext_03' @change="uploadFile($event, 'ext_03')"></dd>
</dl>
</div>
<button @click.prevent="handleOnSubmit">Submit</button>
</form>
</section>
</div>
</template>
<script>
const FORM_ID = 3; // Form ID
export default {
data() {
return {
submitted: false,
submitData: {},
error: null,
file_id: null,
}
},
async asyncData({ $axios }) {
return {
response: await $axios.$get(`/rcms-api/8/form/${FORM_ID}`),
};
},
methods: {
textLines2texts(textLines = '') {
return textLines.split('\r\n');
},
//Set_file_id
async uploadFile(e, key) {
const fm = new FormData();
fm.append('file', e.target.files[0]);
const { file_id } = await this.$axios.$post(`/rcms-api/8/file`, fm, {
headers: {
'Content-Type': 'multipart/form-data', // required to post file as a binary
},
});
this.submitData = {
...this.submitData,
[key]: { "file_id": file_id }
}
},
async handleOnSubmit() {
//Post processing to Kuroco endpoints
try {
await this.$axios.$post('/rcms-api/8/form', { ...this.submitData });
this.submitted = true;
this.error = null;
} catch (e) {
this.error = e.response.data.errors;
}
}
}
};
</script>