138 lines
3.6 KiB
Vue
138 lines
3.6 KiB
Vue
<template>
|
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center">
|
|
<h2>{{ __('Instants gagnants') }}</h2>
|
|
<button
|
|
v-if="cangenerate"
|
|
class="btn btn-sm btn-success float-right"
|
|
@click="generate()"
|
|
>
|
|
<i class="fas fa-cog" /> {{ __('Générer') }}
|
|
</button>
|
|
<button
|
|
v-else
|
|
class="btn btn-sm btn-success float-right"
|
|
@click="copyToClipboard()"
|
|
>
|
|
<span v-show="!copying"><i class="far fa-copy" /> {{ __('Exporter') }}</span>
|
|
<span v-show="copying"> <i class="fas fa-check" /> {{ __('Texte copié !') }}</span>
|
|
</button>
|
|
</div>
|
|
<hr>
|
|
<div v-if="cangenerate">
|
|
{{ __('Aucun instant gagnant pour le moment.') }}
|
|
</div>
|
|
<table
|
|
class="table table-sm table-striped text-center"
|
|
v-else
|
|
>
|
|
<thead class="thead-light">
|
|
<tr>
|
|
<th
|
|
class="w-25"
|
|
scope="col"
|
|
>
|
|
{{ __('Date d\'apparition') }}
|
|
</th>
|
|
<th
|
|
class="w-50"
|
|
scope="col"
|
|
>
|
|
{{ __('Lot') }}
|
|
</th>
|
|
<th
|
|
class="w-25"
|
|
scope="col"
|
|
>
|
|
{{ __('Gagné') }}
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr
|
|
class="list-item border-bottom"
|
|
v-for="item in datas"
|
|
:key="Number(item.id)"
|
|
>
|
|
<td class="text-center align-middle">
|
|
{{ item.appear_date }}
|
|
</td>
|
|
<td class="text-center align-middle">
|
|
{{ (item.prize as LaravelModel).label_one }}
|
|
</td>
|
|
<td class="text-center align-middle">
|
|
{{ item.won === false ? "Non" : "Oui" }}
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import axios from "axios";
|
|
import { defineComponent } from "vue";
|
|
import toast from "../modules/toast";
|
|
import trans from "../modules/trans";
|
|
|
|
export default defineComponent({
|
|
mixins: [toast, trans],
|
|
mounted() {
|
|
console.log("Instant Win Component mounted.");
|
|
const json = String(this.$attrs.json ?? "{}"),
|
|
data = JSON.parse(json);
|
|
this.datas = data.instantwin;
|
|
this.cangenerate = data.cangenerate;
|
|
// Create text for clipboard.
|
|
this.clipboard = "Voici la liste des instants gagnants :\n";
|
|
this.datas.forEach(
|
|
element => this.clipboard += "Le " + new Date(element.appear_date as Date).toLocaleDateString() + " à "
|
|
+ String(element.appear_date).substring(String(element.appear_date).length - 8, String(element.appear_date).length - 3)
|
|
+ " - " + (element.prize as LaravelModel).label_one + "\n"
|
|
);
|
|
},
|
|
data(): {
|
|
datas: LaravelModelList;
|
|
response: string;
|
|
clipboard: string;
|
|
copying: boolean;
|
|
cangenerate: Number;
|
|
startdate: String;
|
|
enddate: String;
|
|
instantwin: String;
|
|
} {
|
|
return {
|
|
datas: [],
|
|
response: "",
|
|
clipboard: "",
|
|
copying: false,
|
|
cangenerate: 0,
|
|
startdate: "",
|
|
enddate: "",
|
|
instantwin: "",
|
|
};
|
|
},
|
|
methods: {
|
|
generate() {
|
|
axios.get("/bo/ajax/instant-win-generate")
|
|
.then(
|
|
response => (this.datas = response.data)
|
|
)
|
|
.catch((error) => {
|
|
console.log(error);
|
|
this.response = "Erreur lors de la génération.";
|
|
});
|
|
this.cangenerate = 0;
|
|
},
|
|
copyToClipboard() {
|
|
navigator.clipboard.writeText(this.clipboard).then(() => {
|
|
this.copying = true;
|
|
setTimeout(() => {
|
|
this.copying = false;
|
|
}, 1000);
|
|
|
|
}, function(err) {
|
|
console.error("Async: Could not copy text: ", err);
|
|
});
|
|
}
|
|
}
|
|
});
|
|
</script>
|