154 lines
4 KiB
Vue
154 lines
4 KiB
Vue
<template>
|
|
<div>
|
|
<table class="table table-bordered">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col" />
|
|
<th scope="col">
|
|
{{ __('Identifiant coupon') }} <span class="required-asterisk">*</span>
|
|
</th>
|
|
<th scope="col">
|
|
{{ __('Pourcentage') }} <span class="required-asterisk">*</span>
|
|
</th>
|
|
<th scope="col">
|
|
{{ __('Valeur faciale') }} <span class="required-asterisk">*</span>
|
|
</th>
|
|
<th scope="col">
|
|
{{ __('Valable sur') }} <span class="required-asterisk">*</span>
|
|
</th>
|
|
<th scope="col">
|
|
{{ __('Nom image') }} <span class="required-asterisk">*</span>
|
|
</th>
|
|
<th scope="col" />
|
|
</tr>
|
|
</thead>
|
|
<tbody id="emails">
|
|
<tr
|
|
v-for="(item, dataIndex) in datas"
|
|
:key="dataIndex"
|
|
>
|
|
<td>{{ dataIndex + 1 }}</td>
|
|
<td>
|
|
<input
|
|
:name="`${name}[${dataIndex}][web_coupon_identifiant]`"
|
|
class="form-control form-control-sm"
|
|
v-model="item.web_coupon_identifiant"
|
|
type="text"
|
|
required
|
|
>
|
|
</td>
|
|
<td>
|
|
<input
|
|
:name="`${name}[${dataIndex}][percentage]`"
|
|
class="form-control form-control-sm"
|
|
:class="{ border: totalPercentage > 100, 'border-danger': totalPercentage > 100}"
|
|
v-model="item.percentage"
|
|
type="number"
|
|
required
|
|
>
|
|
</td>
|
|
<td>
|
|
<input
|
|
:name="`${name}[${dataIndex}][face_value]`"
|
|
class="form-control form-control-sm"
|
|
v-model="item.face_value"
|
|
type="text"
|
|
required
|
|
>
|
|
</td>
|
|
<td>
|
|
<input
|
|
:name="`${name}[${dataIndex}][valid_on]`"
|
|
class="form-control form-control-sm"
|
|
v-model="item.valid_on"
|
|
type="text"
|
|
required
|
|
>
|
|
</td>
|
|
<td>
|
|
<input
|
|
:name="`${name}[${dataIndex}][img_name]`"
|
|
class="form-control form-control-sm"
|
|
v-model="item.img_name"
|
|
type="text"
|
|
required
|
|
>
|
|
</td>
|
|
<td>
|
|
<button
|
|
@click="removeItem(dataIndex)"
|
|
class="btn btn-danger btn-sm"
|
|
>
|
|
{{ __('Supprimer') }}
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="form-group text-right">
|
|
<small
|
|
v-show="totalPercentage > 100"
|
|
class="text-danger"
|
|
>
|
|
{{ __('Poucentage total \u{203A}\ 100%') }}</small>
|
|
<a
|
|
class="btn btn-primary btn-sm text-white"
|
|
@click="newItem"
|
|
role="button"
|
|
>
|
|
{{ __("Ajouter un coupon") }}
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { defineComponent } from "vue";
|
|
import trans from "../modules/trans";
|
|
|
|
export default defineComponent({
|
|
name: "WebCouponsComponent",
|
|
mixins: [trans],
|
|
mounted() {
|
|
const json = String(this.$attrs.json ?? "{}"),
|
|
data = JSON.parse(json);
|
|
this.datas = data.dbdatas;
|
|
this.name = data.name;
|
|
},
|
|
data(): {
|
|
datas: Array<{
|
|
web_coupon_identifiant: string,
|
|
percentage: number,
|
|
face_value: number,
|
|
valid_on: string,
|
|
img_name: string
|
|
}>;
|
|
name: string,
|
|
} {
|
|
return {
|
|
datas: [],
|
|
name: "",
|
|
};
|
|
},
|
|
watch: {
|
|
|
|
},
|
|
methods: {
|
|
newItem() {
|
|
this.datas.push({web_coupon_identifiant: "", percentage: 0, face_value: 0, valid_on: "", img_name: ""});
|
|
},
|
|
removeItem(index: number) {
|
|
if (confirm("Êtes-vous sûr(e) ?")) {
|
|
this.datas.splice(index, 1);
|
|
}
|
|
}
|
|
},
|
|
computed: {
|
|
totalPercentage() {
|
|
let total = 0;
|
|
this.datas.forEach((element: Record<string, number|string>) => total += parseInt(String(element.percentage)));
|
|
return total;
|
|
}
|
|
}
|
|
});
|
|
</script>
|