index.vue 9.19 KB
<template>
  <div class="layout">
    <view-container>
      <template #title>
        <DetailTitle :searchType="'solar'" :dataList="merchantList" :dataListObj="merchantListObj" :tabObject="tabObject"></DetailTitle>
      </template>
      <template #content>
        <div class="solar-detail-content">
          <view-date :defaultYear="defaultYear" :dataList="yearList" :businessTime="businessTime"></view-date>
          <StatisticsBox class="statistic-box" :list="solarDetailList"></StatisticsBox>
          <div class="solar-detail-content-bottom">
            <div class="solar-detail-left">
              <!-- 采购趋势 -->
              <MerchantsPurchaseTrends ref="merchantsTrends" :dataList="dataList" :isEmpty="isEmpty"></MerchantsPurchaseTrends>
              <!-- 商品占比 -->
              <MerchantsPropotion :shopmallData="shopmallData" :selfPickData="selfPickData"></MerchantsPropotion>
            </div>
            <div class="solar-detail-right">
              <div class="service-box">
                <box-title title="服务中心-采购及入库情况"></box-title>
                <PurchaseStorageTable :tableData="merchantServiceDataList" class="main-table" id="serviceTable"></PurchaseStorageTable>
              </div>
              <div class="merchant-box">
                <box-title title="门店-采购及入库情况"></box-title>
                <PurchaseStorageTable firstName="门店名称名称" :tableData="merchantMerDataList" class="main-table" id="merchantTable"></PurchaseStorageTable>
              </div>
            </div>
          </div>
        </div>
      </template>
    </view-container>
  </div>
</template>

<script>
import { changeMixin } from '@/mixins'
import MerchantsPurchaseTrends from './MerchantsPurchaseTrends.vue'
import MerchantsPropotion from './MerchantsPropotion.vue'
import PurchaseStorageTable from './PurchaseStorageTable.vue'
export default {
  name: 'SolarDetail',
  mixins: [changeMixin],
  components: {
    MerchantsPropotion,
    MerchantsPurchaseTrends,
    PurchaseStorageTable
  },
  data() {
    return {
      yearList: [
        {
          label: '全部',
          value: ''
        }
      ],
      defaultYear: '',
      isEmpty: false,
      dataList: [],
      tooltipFormatterObj: [
        {
          label: '商城',
          attrName: 'data1'
        },
        {
          label: '自采',
          attrName: 'data2'
        },
        {
          label: '占比',
          attrName: 'data3',
          addSymbol: '%'
        }
      ],
      merchantList: [],
      merchantListObj: {
        labelName: 'merchantname',
        valueName: 'merchantid'
      },
      tabObject: {},
      solarDetailList: [
        {
          name: '总采购额',
          valueName: 'amounttotal',
          value: '0',
          unit: '¥',
          unitType: 'left',
          bottomLabel: '本月采购额',
          bottemName: 'amounttotalThismonth',
          bottomValue: '0',
          bottomType: 'money'
        },
        {
          name: '商城采购额',
          valueName: 'amountshop',
          value: '0',
          unit: '¥',
          unitType: 'left',
          bottomLabel: '本月采购额',
          bottemName: 'amountshopThismonth',
          bottomValue: '0',
          bottomType: 'money'
        },
        {
          name: '自采采购额',
          valueName: 'amountself',
          value: '0',
          unit: '¥',
          unitType: 'left',
          bottomLabel: '本月采购额',
          bottemName: 'amountselfThismonth',
          bottomValue: '0',
          bottomType: 'money'
        }
      ],
      // 商城采购数据
      shopmallData: [],
      // 自采采购数据
      selfPickData: [],
      businessTime: '',
      merchantMerDataList: [],
      merchantServiceDataList: []
    }
  },
  created() {
    this.$bus.$on('selectVal', data => {
      this.$router.replace({
        path: '/solarDetail',
        query: {
          merchantid: data.merchantid,
          merchantname: data.merchantname,
          purchaseType: this.purchaseType,
          year: this.$store.state.app.solarYear
        }
      })
      this.init()
    })
  },
  methods: {
    async init() {
      this.tabObject = this.$route.query
      const { merchantid, purchaseType, year } = this.$route.query
      this.defaultYear = year
      const _merchantList = await this.getAllRanking(purchaseType)
      this.merchantList = _merchantList
      this.purchaseType = purchaseType
      this.getMerchantGoodsRatio(merchantid)
      this.getMerchantPurchase(merchantid)
      this.getMerchantPurchaseTrend(merchantid)
      this.getYears(merchantid)
      this.getMerchantMer(merchantid)
      this.getMerchantServiceCenter(merchantid)
    },
    // 获取门店的商品采购占比(商城、自采)
    getMerchantGoodsRatio(merchantid) {
      this.api.solar.getMerchantGoodsRatio({ year: this.$store.state.app.solarYear, MerchantId: merchantid }).then(res => {
        if (!res.code === '0') {
          this.openMessage('获取门店商品采购占比失败')
          return
        }
        this.shopmallData = res.data.dataList[0].shopgoodsRatioList.slice(0, 6) || []
        this.selfPickData = res.data.dataList[0].selfgoodsRatioList.slice(0, 6) || []
      })
    },
    // 获取每个门店的 总采购额(总计、本月) 、商城采购额(总计、本月) 、自采采购额(总计、本月)
    getMerchantPurchase(merchantid) {
      this.api.solar.getMerchantPurchase({ year: this.$store.state.app.solarYear, MerchantId: merchantid }).then(res => {
        if (!res.code === '0') {
          this.openMessage('获取门店采购额趋势失败')
          return
        }
        const _dataList = res.data.dataList[0]
        if (_dataList) {
          this.businessTime = _dataList.businessstarttime
          this.solarDetailList.forEach(item => {
            item.value = _dataList[item.valueName]
            item.bottomValue = _dataList[item.bottemName]
          })
        }
      })
    },
    // 获取每个门店的商城采购额(占比)、自采采购额(占比) 趋势
    getMerchantPurchaseTrend(merchantid) {
      this.api.solar.getMerchantPurchaseTrend({ year: this.$store.state.app.solarYear, MerchantId: merchantid }).then(res => {
        if (!res.code === '0') {
          this.openMessage('获取门店商品采购占比失败')
          return
        }
        if (!res.data || !res.data.dataList.length) {
          this.isEmpty = true
          return
        }
        const _dataList = res.data.dataList
        _dataList.forEach((item, index) => {
          this.dataList[index] = {
            month: item.statDate,
            data1: item.shopamount,
            data2: item.selfamount,
            data3: item.shopratio
          }
        })
        this.$refs.merchantsTrends.$refs.purchaseTrend.drawBarLine()
      })
    },
    // 获取所有门店数据
    getAllRanking(purchaseType) {
      return new Promise(resolve => {
        let _merchantList
        this.api.solar.getAllRanking({ year: this.$store.state.app.solarYear }).then(res => {
          if (!res.code === '0') {
            this.openMessage('获取商品采购额排名失败')
            return
          }
          const _data = res.data.dataList[0]
          _merchantList = _data[purchaseType]
          resolve(_merchantList)
        })
      })
    },
    // 获取年份数据参数门店id
    async getYears(MerchantId) {
      this.yearList = [
        {
          label: '全部',
          value: ''
        }
      ]
      const _data = await this.api.solar.getYears({ MerchantId })
      const _yearList = _data.data.dataList[0].year.reverse()
      _yearList.forEach(item => {
        this.yearList.push({
          label: item,
          value: item + ''
        })
      })
      this.defaultYear = this.yearList[0].value
    },
    // 获取每个门店的门店采购额和入库情况
    getMerchantMer(merchantid) {
      this.api.solar.getMerchantMer({ year: this.$store.state.app.solarYear, MerchantId: merchantid }).then(res => {
        if (!res.code === '0') {
          this.openMessage('获取每个门店的门店采购额和入库情况失败')
          return
        }
        const _dataList = res.data.dataList
        this.merchantMerDataList = _dataList
      })
    },
    // 获取每个门店的服务中心的采购额和入库情况
    getMerchantServiceCenter(merchantid) {
      this.api.solar.getMerchantServiceCenter({ year: this.$store.state.app.solarYear, merchantid: merchantid }).then(res => {
        if (!res.code === '0') {
          this.openMessage('获取每个门店的服务中心的采购额和入库情况失败')
          return
        }
        const _dataList = res.data.dataList
        this.merchantServiceDataList = _dataList
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.solar-detail-content {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 1.78vh 24px;
  gap: 0 16px;
  &-bottom {
    margin-top: 1.78vh;
    display: flex;
    justify-content: space-between;
  }
  .statistic-box {
    margin-top: 1.78vh;
  }
}

.service-box,
.merchant-box {
  width: 31.53vw;
  height: 32.56vh;
  box-shadow: inset 0 0 20px 0 #3d57ff69;
}
.merchant-box {
    margin-top: 1.78vh;
}
.main-table {
    padding: 1.11vh 1.39vw 2.44vh;
}
</style>