GameGoal.vue 21.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
<!-- 进球 -->
<template>
    <van-pull-refresh  v-model="loading" @refresh="onRefresh">
    <template #loosing> 
        <div class="refresh-txt">
            <svg-icon className="icon" iconName="loading" :class="{ 'is-spinning': loading }"></svg-icon>
            <span>释放即可刷新</span>
        </div> 
    </template>
    <template #loading>  
        <div class="refresh-txt">
            <svg-icon className="icon" iconName="loading" :class="{ 'is-spinning': loading }"></svg-icon>
            <span>加载中……</span>
        </div>
    </template> 
    <template #success>  
        <div class="refresh-txt">
            <svg-icon className="icon" iconName="loading" :class="{ 'is-spinning': loading }"></svg-icon>
            <span>刷新成功</span>
        </div>
    </template>
    <div class="goal">
        <section v-if="hostResult?.zhibiao1_result && awayResult?.zhibiao1_result">
            <div class="title">比赛进球数统计,取主客球队近{{ limit_count }}场数据分析统计</div>
            <table>
                <thead>
                    <tr>
                        <th>指标</th>
                        <th>{{ game_info?.host_name}}</th>
                        <th>{{ game_info?.away_name }}</th>
                        <th>平均</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item,index) in zhibiao1_array" :key="index">
                        <td>{{item}}</td>
                        <td>{{hostResult.zhibiao1_result[index]}}%</td>
                        <td>{{awayResult.zhibiao1_result[index]}}%</td>
                        <td>{{(parseInt(hostResult.zhibiao1_result[index]) + parseInt(awayResult.zhibiao1_result[index]))/2}}%</td>
                    </tr>
                </tbody>
            </table>
            <div class="txt" v-if="showResult.zhibiao1_txt">{{ showResult.zhibiao1_txt }}</div>
        </section>
        <section v-if="hostResult?.zhibiao2_result && awayResult?.zhibiao2_result">
            <div class="title">球队得球数统计,取主客球队近{{ limit_count }}场数据分析统计</div>
            <table>
                <thead>
                    <tr>
                        <th width="40%">指标</th>
                        <th width="30%">{{ game_info?.host_name}}</th>
                        <th width="30%">{{ game_info?.away_name }}</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item,index) in zhibiao2_array" :key="index">
                        <td>{{item}}</td>
                        <td>{{ hostResult.zhibiao2_result[index]}}%</td>
                        <td>{{ awayResult.zhibiao2_result[index]}}%</td>
                    </tr>
                </tbody>
            </table>
            <div class="txt" v-if="showResult.zhibiao2_txt">{{showResult.zhibiao2_txt}}</div>
        </section>
        <section v-if="hostResult?.zhibiao3_result && awayResult?.zhibiao3_result">
            <div class="title">球队上下半场得球数统计,取主客球队近{{ limit_count }}场数据</div>
            <table>
                <thead>
                    <tr>
                        <th width="40%">指标</th>
                        <th width="30%">{{ game_info?.host_name}}</th>
                        <th width="30%">{{ game_info?.away_name }}</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item,index) in zhibiao3_array" :key="index">
                        <td>{{item}}</td>
                        <td>{{ hostResult.zhibiao3_result[index]}}</td>
                        <td>{{ awayResult.zhibiao3_result[index]}}</td>
                    </tr>
                </tbody>
            </table>
            <div class="txt" v-if="showResult.zhibiao3_txt">{{showResult.zhibiao3_txt}}</div>
        </section>
        <section v-if="hostResult?.zhibiao4_result && awayResult?.zhibiao4_result">
            <div class="title">球队丢球数统计,取主客球队近{{ limit_count }}场数据分析统计</div>
            <table>
                <thead>
                    <tr>
                        <th width="40%">指标</th>
                        <th width="30%">{{ game_info?.host_name}}</th>
                        <th width="30%">{{ game_info?.away_name }}</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item,index) in zhibiao4_array" :key="index">
                        <td>{{item}}</td>
                        <td>{{ hostResult.zhibiao4_result[index]}}%</td>
                        <td>{{ awayResult.zhibiao4_result[index]}}%</td>
                    </tr>
                </tbody>
            </table>
            <div class="txt" v-if="showResult.zhibiao4_txt">{{showResult.zhibiao4_txt}}</div>
        </section>
    </div>
    </van-pull-refresh>
</template>
  
<script lang="ts">
import { ref, defineComponent, onMounted,toRef,watch } from 'vue';
import * as nm_match_api from "@/api/nm_match_api";
import { useRoute } from 'vue-router';
import { default as _ } from 'lodash';

export default defineComponent({
    name: "GameGoal",
    props: { 
        gameInfo: {
            type: Object,
            required: false,
            default: () => { return {}; }
        },
        gameDetail: {
            type: Object,
            required: false,
            default: () => ({})
        },
        activeName: { type: String, default: '' },
    },
    setup(props) {
        const route = useRoute();
        const game_info:any = toRef(props,'gameInfo');
        const game_detail:any = toRef(props,'gameDetail');
        const loading = ref(false);
        const limit_count:any = ref(10);
        const hostResult: any = ref({
            zhibiao1_result:[],
            zhibiao2_result:[],
            zhibiao3_result:[],
            zhibiao4_result:[],
        });
        const awayResult: any = ref({
            zhibiao1_result:[],
            zhibiao2_result:[],
            zhibiao3_result:[],
            zhibiao4_result:[]
        });
        const showResult: any = ref({
            zhibiao1_txt:'',
            zhibiao2_txt:'',
            zhibiao3_txt:'',
            zhibiao4_txt:'',
        })
        const zhibiao1_array:any = ref(['超过0.5球','超过1.5球','超过2.5球','超过3.5球','超过4.5球','超过0.5(上半场)','超过1.5(上半场)','超过2.5(上半场)']);
        const zhibiao2_array:any = ref(['超过0.5球','超过1.5球','超过2.5球','超过3.5球','未进球']);
        const zhibiao3_array:any = ref(['场均进球(上半场)','场均进球(下半场)','进球(上半场)','进球(下半场)']);
        const zhibiao4_array:any = ref(['超过0.5球','超过1.5球','超过2.5球','超过3.5球','未进球']);

        onMounted(init_data);

        watch(() => route.query.yiqiuid || route.params.yiqiuid, (newVal: any) => {
            if (newVal && game_detail.value && newVal != game_detail.value.id) {
                console.info('goal',newVal,game_detail.value.id)
                init_data();
            }
        });

        const onRefresh = () => {
            refresh_data();
            loading.value = false;
        };

        const handle_data = (list: any) => {
           return list.map((item: any) => {
                const socre = [item?.home_scores?.[0]  || 0, item?.away_scores?.[0] || 0];
                const half = `${item?.home_scores?.[1]  || 0}-${item?.away_scores?.[1] || 0}`;
                return {
                    Id: [item.id, item.season_id, item.home_team_id, item.away_team_id],
                    Half: half,
                    Score: socre,
                };
            })
        }

        async function refresh_data () {
            let game_id: any = route.query.yiqiuid || route.params.yiqiuid;
            if (game_id) {
                let nm_result = await nm_match_api.nm_match_detail({ yiqiu_id: game_id });
                game_detail.value = nm_result;
                let host_id = nm_result?.home_team_id;
                let away_id = nm_result?.away_team_id;
                const homeListData = nm_result?.history?.home;
                const awayListData = nm_result?.history?.away;
                if(homeListData){
                    if(homeListData.length < 10){
                        limit_count.value = homeListData.length;
                    }
                    const homeList = handle_data(homeListData);
                    let host_result = getTop10Goal(homeList,host_id,limit_count.value);
                    hostResult.value = host_result;
                }
                if(awayListData){
                    if(awayListData.length < 10){
                        limit_count.value = awayListData.length;
                    }
                    const awayList = handle_data(awayListData);
                    let away_result= getTop10Goal(awayList,away_id,limit_count.value);
                    awayResult.value = away_result;
                }
                getShowResult();    
            }
        }

        async function init_data () {
            if (game_detail.value?.id) {
                let nm_result = game_detail.value;
                let host_id = nm_result?.home_team_id;
                let away_id = nm_result?.away_team_id;
                const homeListData = nm_result?.history?.home;
                const awayListData = nm_result?.history?.away;
                if(homeListData){
                    if(homeListData.length < 10){
                        limit_count.value = homeListData.length;
                    }
                    const homeList = handle_data(homeListData);
                    let host_result = getTop10Goal(homeList,host_id,limit_count.value);
                    hostResult.value = host_result;
                }
                if(awayListData){
                    if(awayListData.length < 10){
                        limit_count.value = awayListData.length;
                    }
                    const awayList = handle_data(awayListData);
                    let away_result= getTop10Goal(awayList,away_id,limit_count.value);
                    awayResult.value = away_result;
                }
                getShowResult();    
            } else {
                refresh_data();
            }
        }

        const getTop10Goal = function (list: any, team_id: any,limit_count:any) {
            if(list.length > 10){
                list = _.take(list,limit_count);
            }
            list.forEach(function(item:any){
                if(item.Half && item.Half.indexOf('-')){
                    item.Half = _.map(item.Half.split('-'), _.parseInt);
                    item.Second_Half = [item.Score[0] - item.Half[0], item.Score[1] - item.Half[1]];
                }
            });
            //指标1:计算总进球超过0.5球,超过1.5球,超过2.5球,超过3.5球,超过4.5球
            let goal_sum_05 = _.filter(list,item => _.sum(item.Score) > 0).length;
            let goal_sum_15 = _.filter(list,item => _.sum(item.Score) > 1).length;
            let goal_sum_25 = _.filter(list,item => _.sum(item.Score) > 2).length;
            let goal_sum_35 = _.filter(list,item => _.sum(item.Score) > 3).length;
            let goal_sum_45 = _.filter(list,item => _.sum(item.Score) > 4).length;
            let goal_half_sum_05 = _.filter(list,item => _.sum(item.Half) > 0).length;
            let goal_half_sum_15 = _.filter(list,item => _.sum(item.Half) > 1).length;
            let goal_half_sum_25 = _.filter(list,item => _.sum(item.Half) > 2).length;
            let goal_sum_05_result = (goal_sum_05 / list.length * 100).toFixed(0);
            let goal_sum_15_result = (goal_sum_15 / list.length * 100).toFixed(0);
            let goal_sum_25_result = (goal_sum_25 / list.length * 100).toFixed(0);
            let goal_sum_35_result = (goal_sum_35 / list.length * 100).toFixed(0);
            let goal_sum_45_result = (goal_sum_45 / list.length * 100).toFixed(0);
            let goal_half_sum_05_result = (goal_half_sum_05 / list.length * 100).toFixed(0);
            let goal_half_sum_15_result = (goal_half_sum_15 / list.length * 100).toFixed(0);
            let goal_half_sum_02_result = (goal_half_sum_25 / list.length * 100).toFixed(0);

            //指标2:计算球队超过0.5球,超过1.5球,超过2.5球,超过3.5球, 未进球
            let goal_0 = _.filter(list,item => (item.Id[2] == team_id && item.Score[0] == 0) || (item.Id[3] == team_id && item.Score[1] == 0)).length
            let goal_05 = _.filter(list,item => (item.Id[2] == team_id && item.Score[0] > 0) || (item.Id[3] == team_id && item.Score[1] > 0)).length
            let goal_15 = _.filter(list,item => (item.Id[2] == team_id && item.Score[0] > 1) || (item.Id[3] == team_id && item.Score[1] > 1)).length
            let goal_25 = _.filter(list,item => (item.Id[2] == team_id && item.Score[0] > 2) || (item.Id[3] == team_id && item.Score[1] > 2)).length
            let goal_35 = _.filter(list,item => (item.Id[2] == team_id && item.Score[0] > 3) || (item.Id[3] == team_id && item.Score[1] > 3)).length
            let goal_0_result = (goal_0 / list.length * 100).toFixed(0);
            let goal_05_result = (goal_05 / list.length * 100).toFixed(0);
            let goal_15_result = (goal_15 / list.length * 100).toFixed(0);
            let goal_25_result = (goal_25 / list.length * 100).toFixed(0);
            let goal_35_result = (goal_35 / list.length * 100).toFixed(0);

            //指标3
            let goal_shang_mean = _.meanBy(list,(item:any) => {
                if(item.Id[2] == team_id){
                    return item.Half[0]
                }else if(item.Id[3] == team_id){
                    return item.Half[1]
                } else {
                    return 0
                }
            });
            let goal_xia_mean = _.meanBy(list,(item:any) => { 
            if(item.Id[2] == team_id && item?.Second_Half){
                return item?.Second_Half[0]
            }else if(item.Id[3] == team_id && item?.Second_Half){
                return item?.Second_Half[1]
            } else {
                return 0
            }
            });
            let goal_shang_count =_.filter(list,item => (item.Id[2] == team_id && item.Half[0] > 0) || (item.Id[3] == team_id && item.Half[1] > 0)).length
            let gaol_shang_rate = (goal_shang_count/list.length * 100).toFixed(0) + '%';
            let goal_xia_count = _.filter(list,item => (item.Id[2] == team_id && item?.Second_Half && item?.Second_Half[0] > 0) || (item.Id[3] == team_id && item?.Second_Half && item?.Second_Half[1] > 0)).length
            let gaol_xia_rate = (goal_xia_count/list.length * 100).toFixed(0) + '%';

             //指标4
            let goal_loss_0 = _.filter(list,item => (item.Id[2] == team_id && item.Score[1] == 0) || (item.Id[3] == team_id && item.Score[0] == 0)).length
            let goal_loss_05 = _.filter(list,item => (item.Id[2] == team_id && item.Score[1] > 0) || (item.Id[3] == team_id && item.Score[0] > 0)).length
            let goal_loss_15 = _.filter(list,item => (item.Id[2] == team_id && item.Score[1] > 1) || (item.Id[3] == team_id && item.Score[0] > 1)).length
            let goal_loss_25 = _.filter(list,item => (item.Id[2] == team_id && item.Score[1] > 2) || (item.Id[3] == team_id && item.Score[0] > 2)).length
            let goal_loss_35 = _.filter(list,item => (item.Id[2] == team_id && item.Score[1] > 3) || (item.Id[3] == team_id && item.Score[0] > 3)).length
            let goal_loss_0_rate = (goal_loss_0 / list.length * 100).toFixed(0);
            let goal_loss_05_rate = (goal_loss_05 / list.length * 100).toFixed(0);
            let goal_loss_15_rate = (goal_loss_15 / list.length * 100).toFixed(0);
            let goal_loss_25_rate = (goal_loss_25 / list.length * 100).toFixed(0);
            let goal_loss_35_rate = (goal_loss_35 / list.length * 100).toFixed(0);
             
            return{
                zhibiao1_result:[goal_sum_05_result,goal_sum_15_result,goal_sum_25_result,goal_sum_35_result,goal_sum_45_result,goal_half_sum_05_result,goal_half_sum_15_result,goal_half_sum_02_result],
                zhibiao2_result:[goal_05_result,goal_15_result,goal_25_result,goal_35_result,goal_0_result],
                zhibiao3_result:[goal_shang_mean.toFixed(2),goal_xia_mean.toFixed(2),gaol_shang_rate,gaol_xia_rate],
                zhibiao4_result:[goal_loss_05_rate,goal_loss_15_rate,goal_loss_25_rate,goal_loss_35_rate,goal_loss_0_rate]
            }
        }

        const getShowResult = function(){
            if(hostResult.value?.zhibiao1_result && awayResult.value?.zhibiao1_result){
                
                //指标1
                // *超过0.5球 平均值    >=80%
                // 两队进球能力不错,本场比赛大概率会有进球。
                // *超过0.5球 平均值   小于80%且大于55%
                // 两队进球能力一般,本场比赛有概率进球。
                // *超过0.5球 平均值   <=55%
                // 两队进球能力较弱,本场比赛有可能不进球。
                let mean = (parseInt(hostResult.value.zhibiao1_result[0]) + parseInt(awayResult.value.zhibiao1_result[0]))/2;
                if(mean >= 80){
                    showResult.value.zhibiao1_txt = '两队进球能力不错,本场比赛大概率会有进球。';
                }else if(mean >= 55 && mean < 80){
                    showResult.value.zhibiao1_txt = '两队进球能力不错,本场比赛大概率会有进球。';
                }else{
                    showResult.value.zhibiao1_txt = '两队进球能力较弱,本场比赛有可能不进球。';
                }

                //指标2
                // 1*未进球项 2队双方 概率都大于35%
                // 本场比赛 很有可能0:0 无进球收场。

                // 2*未进球项  只有一方 概率大于35%
                // 本场比赛XX对 很有可能无法取得进球。

                // 3*未进球项 双方 概率都小于等于35%
                // 本场比赛有进球,看谁先进球,拭目以待!
                let host_goal_0_rate = parseInt(hostResult.value.zhibiao2_result[4]);
                let away_goal_0_rate = parseInt(awayResult.value.zhibiao2_result[4]);
                if(host_goal_0_rate > 35 && away_goal_0_rate>35){
                    showResult.value.zhibiao2_txt = '本场比赛 很有可能0:0 无进球收场。';
                }else if ((host_goal_0_rate > 35 && away_goal_0_rate <= 35) || (away_goal_0_rate > 35 && host_goal_0_rate <= 35)) {
                    showResult.value.zhibiao2_txt = `本场比赛${host_goal_0_rate > 35 ? `主队${game_info.value.host_name}` : `客队${game_info.value.away_name}`} 很有可能无法取得进球。`;
                }else if (host_goal_0_rate <= 35 && away_goal_0_rate <= 35) {
                    showResult.value.zhibiao2_txt = '本场比赛有进球,看谁先进球,拭目以待!';
                }

                //指标3
                // 1*两队场均进球(上半场) 之和 大于1  
                // 本场比赛 上半场进球概率较高!
                // 2*两队场均进球(上半场) 之和 >0.5且 <=1
                // 本场比赛 上半场有较大几率进球!
                // 3*两队场均进球(上半场) 之和 <=0.5
                // 本场比赛 上半场有较大概率平局收场!
                let mean_sum = hostResult.value.zhibiao3_result[0] + awayResult.value.zhibiao3_result[0];
                if(mean_sum > 1){
                    showResult.value.zhibiao3_txt = '本场比赛 上半场进球概率较高!';
                }else if (mean_sum > 0.5 && mean_sum <= 1) {
                    showResult.value.zhibiao3_txt = '本场比赛 上半场有较大几率进球!';
                } else if (mean_sum <= 0.5) {
                    showResult.value.zhibiao3_txt = '本场比赛 上半场有较大概率平局收场!';
                }

                //指标4
                // 判断 满足指定条件 显示 0封对手 
                // 超过1.5球项  2队概率之差大于30% 
                // 不丢球项       2队概率之差>=0%

                // 否则不显示
                let loss_goal_15_rate = hostResult.value.zhibiao4_result[1] - awayResult.value.zhibiao4_result[1];
                let loss_goal_0_rate = hostResult.value.zhibiao4_result[4] - awayResult.value.zhibiao4_result[4];
                if(loss_goal_15_rate > 30 && loss_goal_0_rate >= 0){
                    showResult.value.zhibiao4_txt = `本场比赛 ${game_info.value.host_name}有可能0封对手`
                }else if(loss_goal_15_rate <= 30 && loss_goal_0_rate <0){
                    showResult.value.zhibiao4_txt = `本场比赛 ${game_info.value.away_name}有可能0封对手`
                }
            }
        }
        
        return {
            game_info,
            loading,
            limit_count,
            zhibiao1_array,
            zhibiao2_array,
            zhibiao3_array,
            zhibiao4_array,
            hostResult,
            awayResult,
            showResult,
            onRefresh,
        };
    }
  });
</script>

<style lang="scss" scoped>
@use '@/common/style/common' as *;
.goal{
    margin:10px;
    position: relative;
    section{
        background: #fff;
        margin-bottom: 10px;
        padding:10px;
        @include border-radius(5px);
        .title{
            @include sc(15px,#333);
            height: 40px;
        }
        .txt{
            color:#FF2121;
            line-height: 30px;
            padding-top: 10px;
            text-align: center;
        }
        table{
            @include sc(14px,#777);
            tr{
                line-height: 30px;
            }
            th{
                background-color: #f4f4f4;
            }
            th,td{
                border:solid 1px #f5f5f5;
            }
            tbody td:first-child{
                color:#333;
                font-weight: 500;
            }
        }
    }
    
}

</style>