|
|
@@ -9,7 +9,7 @@
|
|
|
</b-card-title>
|
|
|
</div>
|
|
|
<div class="d-flex align-items-center">
|
|
|
- <b-button variant="info" @click="draw">抽獎管理頁面</b-button>
|
|
|
+ <b-button variant="info" @click="draw">隨機抽100次</b-button>
|
|
|
</div>
|
|
|
</b-card-header>
|
|
|
|
|
|
@@ -85,10 +85,10 @@ export default {
|
|
|
chartjsData,
|
|
|
rangePicker: ['2019-05-01', '2019-05-10'],
|
|
|
randomData: {
|
|
|
- labels: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140],
|
|
|
+ labels: [],
|
|
|
datasets: [
|
|
|
{
|
|
|
- data: [80, 150, 180, 270, 210, 160, 160, 202, 265, 210, 270, 255, 290, 360, 375],
|
|
|
+ data: [],
|
|
|
label: '中獎次數',
|
|
|
borderColor: chartColors.lineChartDanger,
|
|
|
lineTension: 0.5,
|
|
|
@@ -108,17 +108,19 @@ export default {
|
|
|
}
|
|
|
],
|
|
|
},
|
|
|
+ data: {},
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
this.loaded = false
|
|
|
-
|
|
|
useJwt.postData('/api/check_in/index_by_activity', { activity_id: this.activityId }).then(res => {
|
|
|
+ console.log(res.data)
|
|
|
|
|
|
this.userList = res.data;
|
|
|
let array = Object.keys(res.data);
|
|
|
this.randomData.labels = array;
|
|
|
this.randomData.datasets[0].data = Array(array.length).fill(0)
|
|
|
+ this.data = array.reduce((acc, curr) => (acc[curr] = 0, acc), {});
|
|
|
this.loaded = true
|
|
|
});
|
|
|
|
|
|
@@ -128,27 +130,35 @@ export default {
|
|
|
});
|
|
|
|
|
|
},
|
|
|
- mounted() {
|
|
|
- console.log("mounted")
|
|
|
- },
|
|
|
computed: {
|
|
|
|
|
|
},
|
|
|
methods: {
|
|
|
draw() {
|
|
|
- useJwt.postData('/api/draw/draw', {
|
|
|
+ useJwt.postData('/api/randomTest/draw', {
|
|
|
activity_id: this.activityId,
|
|
|
prize_id: this.prizeList[2].id,
|
|
|
region: ['北區', '中區', '南區', '來賓'],
|
|
|
number: 100
|
|
|
}).then(res => {
|
|
|
this.drawList = res.data;
|
|
|
+ let result = this.countOccurrences(this.data, res.data);
|
|
|
+ this.randomData.datasets[0].data = result;
|
|
|
console.log(res.data);
|
|
|
+ console.log(result);
|
|
|
});
|
|
|
},
|
|
|
- },
|
|
|
- watch: {
|
|
|
-
|
|
|
+ countOccurrences(obj1, array1) {
|
|
|
+ const obj = obj1;
|
|
|
+ array1.forEach((item) => {
|
|
|
+ if (obj.hasOwnProperty(item)) {
|
|
|
+ obj[item]++;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ this.data = obj;
|
|
|
+ let array2 = Object.values(obj);
|
|
|
+ return array2;
|
|
|
+ }
|
|
|
},
|
|
|
mounted() {
|
|
|
|