index.vue 9.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
<script setup lang="ts" name="GameProposal">
import {
  ref,
  toRef,
  watch,
  onBeforeMount,
  nextTick,
  onActivated,
  onBeforeUnmount,
  onDeactivated,
  computed,
} from "vue";

import { useGamePropsal } from "@/hooks/game/use-game-propsal";
import { debounce } from "@/until/index";
import { useRouter } from "vue-router";

import bg_rebate_tag from "@/assets/images/bg_rebate_tag.png";
import bg_rebate_80_tag from "@/assets/images/bg_rebate_80_tag.png";

import ProposalList from "./component/proposal-list.vue";
import DataModel from "./component/data-model.vue";
import SeriesConnection from "./component/series-connection.vue";

interface GameProposalProps {
  yiqiu_id: string | number;
}

// $props
const props = withDefaults(defineProps<GameProposalProps>(), {
  yiqiu_id: "",
});
// $props

// $data
const componentRef = ref();
const ProposalListRef = ref();
const router = useRouter();

const {
  loading,
  experts,
  zq_coin,
  user_info,
  list_loading,
  all_data_flag,
  err_data_flag,
  game_predict_list,
  nnjq_data_list,
  hwyc_predict_list,
  ssyc_detail,
  nnjq_detail,
  hwyc_detail,
  refresh_data,
  checkUserInfo,
  is_look,
  init_data,
  load_schemes_data_debounce,
} = useGamePropsal();
const yiqiu_id: any = toRef(props, "yiqiu_id");
const activeNav = ref<string>("0");
const cache_nav = ref<string[]>([]);
const refresh_falg = ref<boolean>(false);
  const banner_list = ref<any[]>([
  {
    src: bg_rebate_tag,
    link: '/rebate',
    type: 'route'
  },
  {
    src: bg_rebate_80_tag,
    link: 'https://m.ydn.com/user/coupons',
    type: 'link'
  },
]);

// $data

// $computed
const list_tip_txt = computed(() => {
  if (err_data_flag.value) {
    return "加载错误,点击重试";
  }

  if (list_loading.value) {
    return "加载中...";
  }

  if (all_data_flag.value) {
    return "没有更多数据了";
  }
  return "";
});
// const currentComponent = computed(() => {
//   if (activeNav.value === '0') {
//     return ProposalList
//   } else if (activeNav.value === '1') {
//     return DataModel;
//   }
// })
// $computed

// $watch
watch(
  () => user_info.value?.user_id,
  (newVal, oldVal) => {
    if (newVal !== oldVal || (newVal && !experts?.hongdan?.length)) {
      resetComponent();
    }
  },
  { immediate: true }
);

watch(
  () => props.yiqiu_id,
  (newVal, oldVal) => {
    if (!newVal) {
      experts.value.hongdan = [];
      return;
    } 
    if (newVal !== oldVal || (newVal && !experts?.hongdan?.length)) {
      resetComponent();
    }
  },
  { immediate: true }
);

watch(activeNav, (newVal, oldVal) => {
  if (!cache_nav.value.includes(newVal)) {
    if (activeNav.value == "0" && (refresh_falg.value || list_loading.value)) return;
    refresh_falg.value = true;
    const timer = setTimeout(() => {
      refresh_falg.value = false;
      clearTimeout(timer);
    }, 800);
    cache_nav.value.push(newVal);
    refresh_data(props.yiqiu_id as string, newVal);
  }
});
// $watch

// $methods
const handleSwipeClick = (item: any) => {
  if (item.type == 'link') {
    (window as any).location.href = item.link
  } else if (item.type == 'route') {
    router.push({
      path: item.link,
      query: {},
    });
  }
}
const onRefresh = () => {
  refresh_data(yiqiu_id.value, activeNav.value);
};
// 监听滚动事件
const onScroll = (event: Event) => {
  const { target } = event as any;
  if (
    !target ||
    activeNav.value !== "0" ||
    list_loading.value ||
    all_data_flag.value ||
    refresh_falg.value
  )
    return;
  const { scrollTop, scrollHeight, clientHeight } = target;
  if (scrollTop + clientHeight >= scrollHeight - 10) {
    load_schemes_data_debounce(props.yiqiu_id as string);
  }
};

// 重新加载
const reload_list = () => {
  if (err_data_flag.value) {
    load_schemes_data_debounce(props.yiqiu_id as string);
  }
};

const reload_list_debounce = debounce(reload_list, 500);

const onScrollDebounce = debounce(onScroll, 500);

function resetComponent() {
  if (activeNav.value == "0" && (refresh_falg.value || list_loading.value)) return;
  refresh_falg.value = true;
  const timer = setTimeout(() => {
    refresh_falg.value = false;
    clearTimeout(timer);
  }, 800);
  activeNav.value = "0";
  cache_nav.value = ["0"];
  ProposalListRef?.value?.resetFilter?.();
  refresh_data(props.yiqiu_id as string, "0");
}

nextTick(() => {
  document
    .querySelector("#game-page")
    ?.addEventListener("scroll", onScrollDebounce, { passive: true });
});

// $methods

// $lifecycle
onActivated(() => {
  checkUserInfo();
});
onBeforeMount(() => {
  checkUserInfo();
  // localStorage.getItem('propsal_back') && (activeNav.value = '1');
});
onBeforeUnmount(() => {
  localStorage.removeItem("propsal_back");
});
onDeactivated(() => {
  localStorage.removeItem("propsal_back");
});
// $lifecycle

// $expose
defineExpose({ resetComponent });
// $expose
</script>

<template>
  <van-pull-refresh
    v-model="loading"
    class="game-proposal-content"
    ref="componentRef"
    @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>
    <article class="box-model">
      <van-swipe v-if="user_info?.is_bzf" class="advertisement-wrapper" :autoplay="3000">
        <van-swipe-item v-for="(item, index) in banner_list" :key="index" @click="handleSwipeClick(item)">
          <img class="placard-photo" v-lazy="item.src" />
        </van-swipe-item>
      </van-swipe>
    </article>
    <!-- 模块导航 -->
    <div class="nav-wrapper">
      <div class="trapezium-nav">
        <div
          :class="['nav-bar-item', activeNav === '0' && 'active']"
          @click="activeNav = '0'"
        >
          <span>专家推荐</span>
        </div>
        <div
          :class="['nav-bar-item', activeNav === '1' && 'active']"
          @click="activeNav = '1'"
        >
          <span>数据模型</span>
        </div>
        <div
          :class="['nav-bar-item', activeNav === '2' && 'active']"
          @click="activeNav = '2'"
        >
          <span>定期串关</span>
        </div>
      </div>
    </div>
    <div class="model-content">
      <proposal-list
        ref="ProposalListRef"
        v-if="activeNav === '0'"
        :loading="list_loading"
        :user_info="user_info"
        :data-list="experts?.hongdan"
        :list-tip-txt="list_tip_txt"
        @reload-list="reload_list_debounce"
      />
      <data-model
        v-if="activeNav === '1'"
        :yiqiu_id="yiqiu_id"
        :user_info="user_info"
        :game_predict_list="game_predict_list"
        :nnjq_data_list="nnjq_data_list"
        :hwyc_predict_list="hwyc_predict_list"
        :ssyc_detail="ssyc_detail"
        :nnjq_detail="nnjq_detail"
        :hwyc_detail="hwyc_detail"
        :is_look="is_look"
      />
      <series-connection
        v-if="activeNav === '2'"
        :yiqiu_id="yiqiu_id"
        :zq_coin="zq_coin"
        :experts-list="experts.chuanguan"
      />
    </div>
  </van-pull-refresh>
</template>

<style lang="scss">
@use "@/common/style/common" as *;
.game-proposal-content {
  font-family: PingFangSC, PingFang SC !important;

  .box-model {
    margin-top: 10px;
    /* padding: 10px; */
    background-color: #fff;
    // border-top: 10px solid #f8f6f6;

    .advertisement-wrapper {
      height: 76px;
      margin-bottom: 4px;
    }

    .placard-photo {
      width: 100%;
      height: 76px;
    }
  }

  .nav-wrapper {
    /* padding: 10px 0 0 6px; */
    padding-left: 6px;
    background-color: #f6f6f6;
  }

  .model-content {
    min-height: 50vh;
    background-color: #fff;
  }

  .trapezium-nav {
    position: relative;
    color: #7d7c82;
    background-color: #e6e8ec;
    width: 240px;

    height: 32px; /* 设置高度 */
    border-radius: 10px; /* 圆角效果 */

    display: flex;

    .nav-bar-item {
      position: relative;
      flex: 1;
      height: 100%;
      width: 80px;
      background-color: #e6e8ec;
      border-radius: 10px; /* 圆角效果 */

      display: flex;
      align-items: center;
      justify-content: center;

      span {
        margin-top: 5px;
        position: relative;
        z-index: 9;
        font-size: 14px;
      }

      &::before {
        content: "";
        position: absolute;
        bottom: 0px; /* 将伪元素定位到顶部 */
        left: -7px;
        right: -7px;
        height: 80%;
        z-index: -1;
        background-color: #e6e8ec; /* 顶边颜色 */
        clip-path: polygon(
          7% 0%,
          93% 0%,
          100% 100%,
          0% 100%
        ); /* 使用clip-path实现梯形 */
      }
    }

    .nav-bar-item.active {
      color: #000;
      background-color: #fff;
      &::before {
        z-index: 1;
        background-color: #fff !important; /* 顶边颜色 */
      }
    }

    &::before {
      content: "";
      position: absolute;
      bottom: 0px; /* 将伪元素定位到顶部 */
      left: -7.5px;
      right: -7.5px;
      height: 80%;
      background-color: #e6e8ec; /* 顶边颜色 */
      clip-path: polygon(
        3% 0%,
        97% 0%,
        100% 100%,
        0% 100%
      ); /* 使用clip-path实现梯形 */
    }
  }

  .list-loading-tip {
    color: #cccccc;
    font-size: 18px;
    height: 50px;
    line-height: 50px;
    text-align: center;
  }
}
</style>