PurchaseRank.vue 5.47 KB
<!-- 采购额排名 -->
<template>
  <div class="purchase-rank-box">
    <box-title title="采购额排名"></box-title>
    <div class="content-box">
      <!-- 采购选项下拉 -->
      <div class="purchase-plugin">
        <div class="purchase" @click.stop="switchPurchase">
          {{ purchase.labelName }}
          <img class="arrow-down" src="@/assets/images/arrow-down.png" alt="" />
        </div>
        <SelectBox :isShow="isShow" @clickOutside="clickOutside" isObject :dataList="purchaseList" :boxWidth="'28.61vw'" @selectVal="selectPurchase" :labelName="'labelName'"></SelectBox>
        <!-- <div v-show="isShow" class="select-purchase">
          <div class="purchase-item" :class="purchase == item ? 'active' : ''" v-for="(item, index) in purchaseList" :key="index" @click.s="selectPurchase(item)">{{ item }}</div>
        </div> -->
      </div>
      <!-- 门店排行 -->
      <div v-if="merchantsList.length" class="merchant-box">
        <ranking :rankingsList="merchantsList" :rankingDataObj="merchantsDataObj" :isMultiple="false" @goDetailPage="goDetailPage"></ranking>
      </div>
      <div v-else class="empty">
        <Empty></Empty>
      </div>
    </div>
  </div>
</template>

<script>
import { changeMixin } from '@/mixins'
import { mapActions } from 'vuex'
export default {
  name: 'PurchaseRank',
  mixins: [changeMixin],
  data() {
    return {
      // 采购额排名下拉框显示
      isShow: false,
      // 采购额排名下拉框数据
      purchaseList: [
        {
          labelName: '总采购额排行-商城采购',
          value: 'shopranking'
        },
        {
          labelName: '近三月采购额排行-商城采购',
          value: 'shoprankingnear3'
        },
        {
          labelName: '总采购额排行-自采',
          value: 'selfranking'
        },
        {
          labelName: '近三月采购额排行-自采',
          value: 'selfrankingnear3'
        }
      ],
      rankingList: {},
      // 采购额排名当前选中值
      purchase: {},
      // 采购额排名门店数据
      merchantsList: [],
      merchantsDataObj: [
        {
          name: 'merchantname',
          width: '20.3vw',
          action: true
        },
        {
          name: 'num',
          type: 'number'
        }
      ]
    }
  },

  mounted() {
    this.purchase = this.purchaseList[0]
  },

  methods: {
    ...mapActions(['setMerchantRankingList']),
    init() {
      this.getAllRanking()
    },
    // 获取各类商品采购额排名
    getAllRanking() {
      this.api.solar.getAllRanking({ year: this.$store.state.app.solarYear }).then(res => {
        if (!res.code === '0') {
          this.openMessage('获取商品采购额排名失败')
          return
        }
        this.rankingList = res.data.dataList[0]
        this.merchantsList = this.rankingList[this.purchase.value || this.purchaseList[0].value].slice(0, 5)
        this.setMerchantRankingList(this.merchantsList)
      })
    },
    // 排名下拉显示/隐藏
    switchPurchase() {
      this.isShow = !this.isShow
    },
    // 排名下拉选中
    selectPurchase(item) {
      this.purchase = item
      const purchaseIndex = this.purchaseList.findIndex(itm => itm.value === item.value)
      // 只获取排名前五的数据
      this.merchantsList = this.rankingList[this.purchaseList[purchaseIndex].value].slice(0, 5)
      this.setMerchantRankingList(this.merchantsList)
      this.switchPurchase()
    },
    // 跳转太阳膜详情页
    goDetailPage(item) {
      // this.$router.push({ path: `solarDetail?merchantid=${item.merchantid}&merchantname=${item.merchantname}&purchaseType=${this.purchase.value}` })
      const routeData = this.$router.resolve({
        name: 'solarDetail',
        query: {
          merchantid: item.merchantid,
          merchantname: item.merchantname,
          purchaseType: this.purchase.value,
          year: this.$store.state.app.solarYear
        }
      })
      window.open(routeData.href, '_blank')
    },
    // 点击外部控制排名下拉隐藏
    clickOutside() {
      this.isShow = false
    }
  }
}
</script>

<style lang="scss" scoped>
.purchase-rank-box {
  width: 100%;
  background: #061422;
  box-shadow: inset 0 0 20px 0 #3d57ff69;
  height: 27.33vh;
  margin-bottom: 1.78vh;
  .content-box {
    padding: 1.11vh 1.39vw 0 1.39vw;
  }

  .purchase-plugin {
    position: relative;
  }
  .select-purchase {
    position: absolute;
    top: 2.86vh;
    width: 28.61vw;
    background-color: #051526;
    padding: 16px 20px;
    box-sizing: border-box;
    border: 2px solid;
    border-image: linear-gradient(90deg, #074989, #30dcff, #074989) 1;
    .purchase-item {
      margin-bottom: 8px;
      color: #c9c9c9;
      max-width: 25.83vw;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      cursor: pointer;
      &:hover {
        color: #ffffff;
      }
      &:last-child {
        margin-bottom: 0;
      }
      &.active {
        color: #ffffff;
      }
    }
  }
  .purchase {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 28.61vw;
    // height: 5.7vh;
    padding: 0 0.56vw;
    box-sizing: border-box;
    background-image: linear-gradient(270deg, #6578ff 0%, #079ff1 100%);
    font-weight: 400;
    font-size: 14px;
    margin-right: 0.56vw;
    color: #ffffff;
    .arrow-down {
      width: 0.69vw;
      height: 0.67vh;
    }
  }
  .merchant-box {
    margin-top: 2.06vh;
  }
  .empty {
    height: 19vh;
    display: flex;
    align-items: center;
  }
}
</style>