ldc-gen-game-web/resources/ts/components/InstantWinComponent.vue

150 lines
4.1 KiB
Vue

<template>
<div>
<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()"
>
<FontAwesomeIcon icon="cog" /> {{ __('Générer') }}
</button>
<button
v-else
class="btn btn-sm btn-success float-right"
@click="copyToClipboard()"
>
<span v-show="!copying">
<FontAwesomeIcon icon="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.available_at }}
</td>
<td class="text-center align-middle">
{{ (item.prize as LaravelModel).label }}
</td>
<td class="text-center align-middle">
{{ item.participation_id === null ? __('Non') : __('Oui') }}
</td>
</tr>
</tbody>
</table>
</div>
</template>
<script lang="ts">
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import axios from "axios";
import { defineComponent } from "vue";
import route from "../modules/route";
import toast from "../modules/toast";
import trans from "../modules/trans";
export default defineComponent({
name: "InstantWinComponent",
mixins: [toast, trans, route],
mounted() {
const json = String(this.$attrs.json ?? "{}"),
data = JSON.parse(json);
this.datas = data.instantwin;
console.log(this.datas);
this.cangenerate = data.cangenerate ? true : false;
// Create text for clipboard.
this.clipboard = this.__("Voici la liste des instants gagnants :\u{00A0}");
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: boolean;
startdate: string;
enddate: string;
instantwin: string;
} {
return {
datas: [],
response: "",
clipboard: "",
copying: false,
cangenerate: false,
startdate: "",
enddate: "",
instantwin: "",
};
},
methods: {
generate() {
const route = this.route("bo.instant-wins.generate");
if (!route) {
throw new Error("Missing route bo.instant-wins.generate");
}
axios.get(route)
.then(response => (this.datas = response.data))
.catch((error) => {
console.log(error);
this.response = "Erreur lors de la génération.";
});
this.cangenerate = false;
},
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);
});
}
},
components: { FontAwesomeIcon }
});
</script>