| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <template>
- <uni-list ref="list" class="list" :border="false" @click="test">
- <uni-list-item v-for="(item,index) in rankRs" :key="index" :border="false" class="list-item uni-row"
- :class="getListItemClass(item,index)">
- <template v-slot:body>
- <text class="item-rankNum"
- :class="getMedalClass(item.rankNum)">{{item.rankNum > 0 ? item.rankNum : '--'}}</text>
- <view class="item-detail uni-row">
- <text
- class="item-userName">{{ teamType >= 0 ? getTeamName(teamType, item.userName) : item.userName}}</text>
- <text class="item-totalTime" v-if="rankType == 'totalDistance'">{{fmtDistanct(item.inRankNum)}} km</text>
- <text class="item-totalTime" v-else-if="rankType == 'fastPace'">{{fmtPace(item.inRankNum)}}</text>
- <text class="item-totalTime" v-else-if="rankType == 'totalCp' || rankType == 'totalSysPoint'">{{item.inRankNum}} 个</text>
- <text class="item-totalTime" v-else>{{fmtTime(item.totalTime)}}</text>
- </view>
- </template>
- </uni-list-item>
- </uni-list>
- </template>
- <script>
- import tools from '/common/tools';
- import {
- teamName
- } from '/common/define';
- export default {
- name: "my-ranklist",
- props: {
- rankRs: {},
- teamType: {
- type: Number,
- default: -1
- },
- rankType: { // totalDistance:总距离 totalCp:打点数 totalSysPoint:百味豆 fastPace:配速
- type: String,
- default: ""
- },
- myOldRankNum: { // 我的旧排名
- type: Number,
- default: null
- },
- myNewRankNum: { // 我的新排名
- type: Number,
- default: null
- }
- },
- data() {
- return {
- curMoveIndex: null, // 当前正在移动的列表Index (等于 rankNum-1) 用于排名变动的动画效果
- refList: null,
- refListItems: null,
- // item: {}
- };
- },
- mounted() {
- this.refList = this.$refs.list;
- this.refListItems = this.refList.$el.children;
- // console.log("refListItems", this.refListItems);
- },
- methods: {
- getListItemClass(item, index) {
- // console.log("item", item);
- if (item == undefined) {
- return "";
- }
- let classStr = "";
- // if (item.rankNum >= 0 && this.curMoveIndex == item.rankNum-1) {
- if (this.curMoveIndex == index) {
- classStr += " list-item-move"
- // console.log("list-item-move curMoveIndex", this.curMoveIndex);
- }
- if (item.isSelf) {
- classStr += " list-item-isself"
- }
- return classStr;
- },
- getTeamName(teamType, teamIndex) {
- return teamName[teamType][teamIndex];
- },
- getMedalClass(rankNum) {
- if (rankNum == 0)
- return 'item-rankNum-other';
- if (rankNum <= 3)
- return 'item-rankNum-medal-' + rankNum;
- else if (rankNum <= 10)
- return 'item-rankNum-medal-other';
- else
- return 'item-rankNum-other';
- },
- fmtTime(time) {
- if (time > 0)
- return tools.convertSecondsToHMS(time, 1);
- else
- return '--';
- },
- // 格式化 距离
- fmtDistanct(val) {
- return Math.round(val * 100 / 1000) / 100;
- // if (val < 1000)
- // return Math.round(val * 10 / 1000) / 10;
- // else
- // return Math.round(val / 1000);
- },
- // 格式化 配速
- fmtPace(val) {
- return tools.convertSecondsToHMS(val, 2);
- },
- // 排名上升
- moveRankUp(i, animation = false) {
- // console.log("moveRankUp:", i, animation, this.rankRs[i]);
- const temp = this.rankRs[i];
- this.rankRs[i] = this.rankRs[i-1];
- this.rankRs[i-1] = temp;
- this.rankRs[i-1].rankNum--;
- if (animation) {
- this.curMoveIndex = i-1;
- this.refListItems[i-1].scrollIntoView(true);
- }
- // console.log("rankRs:", i, rankRs);
- },
- // 排名下降
- moveRankDown(i, animation = false) {
- // console.log("moveRankDown:", i, animation, this.rankRs[i]);
- const temp = this.rankRs[i];
- this.rankRs[i] = this.rankRs[i+1];
- this.rankRs[i+1] = temp;
- this.rankRs[i+1].rankNum++;
- if (animation) {
- this.curMoveIndex = i+1;
- this.refListItems[i+1].scrollIntoView(false);
- }
- // console.log("rankRs:", i, rankRs);
- },
- // 更新排名
- moveRank(myOldRankNum, myNewRankNum, animation = false) {
- if (!(myOldRankNum > 0)) {
- console.log("[moveRank] 我的旧排名为空,终止执行", myOldRankNum);
- return;
- }
- if (!(myNewRankNum > 0)) {
- console.log("[moveRank] 我的新排名为空,终止执行", myNewRankNum);
- return;
- }
-
- const difNum = myOldRankNum - myNewRankNum;
- if (difNum > 0) { // 排名上升
- // console.log("排名上升");
- let t = 1;
- for (var i = myOldRankNum - 1; i > myNewRankNum - 1; i--) {
- if (animation) {
- setTimeout(this.moveRankUp, 200 * t, i, animation);
- } else {
- this.moveRankUp(i, animation);
- }
- t++;
- }
- } else if (difNum < 0) { // 排名下降
- // console.log("排名下降");
- let t = 1;
- for (var i = myOldRankNum - 1; i < myNewRankNum - 1; i++) {
- if (animation) {
- setTimeout(this.moveRankDown, 200 * t, i, animation);
- } else {
- this.moveRankDown(i, animation);
- }
- t++;
- }
- }
- },
- test() {
- return;
-
- // const oldRankNum = 1;
- // const newRankNum = 20;
-
- const oldRankNum = 20;
- const newRankNum = 10;
-
- // 先将我的排名恢复到旧排名
- this.moveRank(newRankNum, oldRankNum);
-
- // 再将我的旧排名已动画的形式更新到新排名
- setTimeout(this.moveRank, 3000, oldRankNum, newRankNum, true);
- // this.moveRank(oldRankNum, newRankNum, true);
- }
- // onItemClick(item) {
- // this.data.item = item
- // this.$emit('my-combo-list-click', this.data);
- // }
- }
- }
- </script>
- <style lang="scss" scoped>
- .list {
- width: 90%;
- height: 53vh;
- flex-grow: 1;
- overflow: scroll;
- margin-top: 16rpx;
- margin-bottom: 16rpx;
- }
- .list-item {
- width: 100%;
- height: 70rpx;
- justify-content: flex-start;
- // transition: all 1s ease;
- // -webkit-transition: all 1s ease;
- }
- .list-item-move {
- background-color: #bd640a !important;
- }
- .list-item-isself {
- background-color: #ececea !important;
- border-radius: 10rpx;
- }
- .item-rankNum {
- width: 80rpx;
- height: 50rpx;
- text-align: center;
- margin-top: 6rpx;
- padding-right: 0.5rpx;
- margin-right: 20rpx;
- font-size: 26rpx;
- font-weight: bold;
- line-height: 50rpx;
- background-repeat: no-repeat;
- background-position-x: center;
- background-position-y: top;
- background-size: contain;
- }
- .item-detail {
- width: 82%;
- height: 60rpx;
- padding-left: 10rpx;
- padding-right: 10rpx;
- border-bottom: #ececea 5rpx solid;
- justify-content: space-between;
- }
- .item-rankNum-medal-1 {
- color: #bd640a;
- background-image: url("/static/default/medal_gold.png");
- }
- .item-rankNum-medal-2 {
- color: #68758c;
- background-image: url("/static/default/medal_silver.png");
- }
- .item-rankNum-medal-3 {
- color: #9b3b11;
- background-image: url("/static/default/medal_copper.png");
- }
- .item-rankNum-medal-other {
- color: #9a140a;
- background-image: url("/static/default/medal_other.png");
- }
- .item-rankNum-other {
- color: #9a140a;
- }
- .item-userName {
- font-size: 30rpx;
- }
- .item-totalTime {
- font-size: 26rpx;
- font-weight: 550;
- }
- </style>
|