audit_games.vue 5.17 KB
Newer Older
sunxiwei's avatar
sunxiwei committed
1 2 3 4
<template>
  <v-app>
    <!-- {{ filteredMatches }} -->
    <v-container>
5 6
      <v-data-table class="overflow-auto " :headers="headers" :items="filteredMatches" item-key="id"
        :search="search.value" :items-per-page="10">
sunxiwei's avatar
sunxiwei committed
7 8 9 10 11 12 13 14 15
        <template v-slot:top>
          <v-toolbar flat>
            <v-toolbar-title>比赛</v-toolbar-title>
            <v-divider class="mx-4" inset vertical></v-divider>
            <v-spacer></v-spacer>
            <v-text-field v-model="search" append-icon="mdi-magnify" label="搜索" single-line hide-details></v-text-field>
          </v-toolbar>
        </template>
        <template v-slot:item.date="{ item }">
16
          <p style="width:60px">{{ item.date }}</p>
sunxiwei's avatar
sunxiwei committed
17 18
        </template>
        <template v-slot:item.team="{ item }">
19
          <p style="width:120px">{{ item.homeTeam }} VS {{ item.awayTeam }}</p>
20

sunxiwei's avatar
sunxiwei committed
21 22
        </template>
        <template v-slot:item.score="{ item }">
23
          <p style="width:30px">{{ item.homeScore }} - {{ item.awayScore }}</p>
24

sunxiwei's avatar
sunxiwei committed
25 26
        </template>
        <template v-slot:item.actions="{ item }">
27 28 29 30 31 32
          <div style="width:45px"> <v-icon v-if="!item.shenhe" small color="green" @click="opendialog(item, 'approve')"
              style="padding-right: 20px;">mdi-check</v-icon>
            <v-icon v-if="!item.shenhe" small color="red" @click="opendialog(item, 'reject')"
              style="padding-left: 20px;">mdi-close</v-icon>
            <div v-if="item.shenhe" variant="text">已审核</div>
          </div>
33

sunxiwei's avatar
sunxiwei committed
34 35
        </template>
      </v-data-table>
36 37 38 39 40 41 42 43
      <v-dialog v-model="dialog" width="auto">
        <v-card width="300px">
          <v-card-title>
            {{ cardtitle }}
          </v-card-title>
          <v-card-text>
            {{ cardtext }}
          </v-card-text>
44 45 46 47 48
          <v-card-actions>
            <v-spacer></v-spacer>
            <v-btn color="indigo" text="取消" @click="dialog = false"></v-btn>
            <v-btn color="indigo" text="确定" @click="confirmAction"></v-btn>
          </v-card-actions>
49 50
        </v-card>
      </v-dialog>
sunxiwei's avatar
sunxiwei committed
51 52
    </v-container>
  </v-app>
53 54 55



sunxiwei's avatar
sunxiwei committed
56 57 58 59 60 61 62 63 64
</template>

<script setup>
import { ref } from 'vue';
import { reactive } from 'vue';
import { computed } from 'vue';
import axios from 'axios';

const matches = ref(new Array());
65 66 67 68 69 70 71 72 73 74 75 76 77
const actiontype = ref(null);
const selectedMatch = ref(null);
const cardtitle = ref(null);
const cardtext = ref(null);
const shenhetitle = ref(null);
const shenhetext = ref(null);
const dialog = ref(false);
const verify = ref(true);

function info(title, text) {
  cardtitle.value = title;
  cardtext.value = text;
  dialog.value = true;
sunxiwei's avatar
sunxiwei committed
78 79
}

80
function refresh() {
sunxiwei's avatar
sunxiwei committed
81
  axios.get('/api/lauchedGames',)
82 83 84 85 86 87 88 89 90 91 92
    .then(function (response) {
      const data = response.data;
      for (var i = 0; i < data.Games.length; i++) {
        var match = {
          id: data.Games[i].id,
          date: data.Games[i].game_date,
          homeTeam: data.Games[i].player1_real_name,
          awayTeam: data.Games[i].player2_real_name,
          homeScore: data.Games[i].score1,
          awayScore: data.Games[i].score2,
          shenhe: false,
sunxiwei's avatar
sunxiwei committed
93
        }
94 95
        matches.value[i] = match;
      }
sunxiwei's avatar
sunxiwei committed
96 97
    })
    .catch(function (error) {
98 99
      console.log(error);
    })
sunxiwei's avatar
sunxiwei committed
100
}
101
refresh();
sunxiwei's avatar
sunxiwei committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121

const search = ref('');
const headers = reactive([
  { title: '日期', key: 'date', sortable: false },
  { title: '比赛', key: 'team', sortable: false },
  { title: '比分', key: 'score', sortable: false },
  { title: '审核', key: 'actions', sortable: false }
]);
// const matches = ref(new Array());

const filteredMatches = computed(() => {
  // return matches.value
  return matches.value.filter(match =>
    match.homeTeam.includes(search.value) ||
    match.awayTeam.includes(search.value) ||
    match.homeScore === parseInt(search.value) ||
    match.awayScore === parseInt(search.value)
  );
})

122 123 124 125 126 127 128 129 130 131 132
function opendialog(game, type) {
  if (type === 'approve') {
    shenhetitle.value = `审核比赛 ${game.homeTeam} VS ${game.awayTeam}`;
    shenhetext.value = `确定要通过这场比赛吗?`;
  } else if (type === 'reject') {
    shenhetitle.value = `审核比赛 ${game.homeTeam} VS ${game.awayTeam}`;
    shenhetext.value = `确定要不通过这场比赛吗?`;
  }
  info(shenhetitle.value, shenhetext.value);
  selectedMatch.value = game;
  actiontype.value = type;
sunxiwei's avatar
sunxiwei committed
133 134
}

135 136 137 138 139 140 141
function confirmAction() {
  if (actiontype.value === 'approve') {
    verify.value = true;
    selectedMatch.value.shenhe = true;
    axios.post('/api/confirmGame', {
      game_id: selectedMatch.value.id,
      confirm: verify.value,
sunxiwei's avatar
sunxiwei committed
142
    })
143 144 145 146 147 148 149 150 151 152
      .then(function (response) {
        const data = response.data;
        if (data.status === "SUCCESS") {
          console.log('success');
        }
      })
      .catch(function (error) {
        console.log(error);
      })
  }
153
  else if (actiontype.value === 'reject') {
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    verify.value = false;
    selectedMatch.value.shenhe = true;
    axios.post('/api/confirmGame', {
      game_id: selectedMatch.value.id,
      confirm: verify.value,
    })
      .then(function (response) {
        const data = response.data;
        if (data.status === "SUCCESS") {
          console.log('success');
        }
      })
      .catch(function (error) {
        console.log(error);
      })
  }
  dialog.value = false;
sunxiwei's avatar
sunxiwei committed
171 172
}
</script>