123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- <template>
- <br />
- <el-card style="margin: 0 1em;">
- <div class="title_card" v-text="title"></div>
- <br />
- <el-button-group style="margin-left: 1.5em">
- <el-button
- size="small"
- type="primary"
- v-for="(item, i) in share_list"
- :key="'share' + i"
- :plain="share_act !== i"
- @click="() => share_change(i)"
- >
- {{ item.text }}
- </el-button>
- </el-button-group>
- <br />
- <div ref="share1"></div>
- <br />
- <div ref="share"></div>
- </el-card>
- </template>
- <script>
- // @ is an alias to /src
- // import config from "@/config/index";
- import * as echarts from "echarts";
- import { industryList } from "@/api/index.js";
- let share1_chart = undefined,
- share_chart = undefined;
- export default {
- name: "AdvertisingEye_tranche",
- data() {
- return {
- share_act: 0,
- share_list: [
- {
- text: "时长",
- proportionType: "timeSize",
- unit: "分",
- type: 2,
- },
- {
- text: "频次",
- proportionType: "pinci",
- unit: "次",
- type: 1,
- },
- {
- text: "费用",
- proportionType: "fee",
- unit: "万",
- type: 3,
- },
- {
- text: "客户数",
- proportionType: "custom",
- unit: "个",
- type: 4,
- },
- ],
- };
- },
- props: {
- title: String,
- industry: Number,
- industryRang: Number,
- },
- watch: {
- industryRang() {
- this.init();
- },
- industry() {
- this.init();
- },
- },
- mounted() {
- share1_chart = undefined;
- share_chart = undefined;
- this.init();
- },
- computed: {},
- filter: {},
- methods: {
- init() {
- Promise.all([
- industryList({
- tableType: 5,
- dataType: this.share_list[this.share_act].type,
- indexTime: this.industryRang + 1,
- }),
- industryList({
- tableType: 15,
- dataType: this.share_list[this.share_act].type,
- indexTime: this.industryRang + 1,
- }),
- industryList({
- tableType: 6,
- dataType: this.share_list[this.share_act].type,
- indexTime: this.industryRang + 1,
- }),
- industryList({
- tableType: 16,
- dataType: this.share_list[this.share_act].type,
- indexTime: this.industryRang + 1,
- }),
- ]).then(all => {
- let barAll = [...(all[1] || []), ...(all[3] || [])],
- barGroup = [];
- let k = {};
- for (let i = 0; i < barAll.length; i++) {
- const v = barAll[i];
- if (isNaN(k[v.name])) {
- k[v.name] = barGroup.length;
- barGroup.push([]);
- }
- barGroup[k[v.name]].push(v);
- }
- this.share1Chart(barGroup);
- let share = [[], []],
- s = 0;
- all[0].map((v, i) => {
- if (i >= 9)
- s += v[this.share_list[this.share_act].proportionType] - 0;
- i < 9 && share[0].push(v);
- });
- share[0].push({
- name: "其它",
- [this.share_list[this.share_act].proportionType]: s,
- });
- s = 0;
- all[2].map((v, i) => {
- if (i >= 9)
- s += v[this.share_list[this.share_act].proportionType] - 0;
- i < 9 && share[1].push(v);
- });
- share[1].push({
- name: "其它",
- [this.share_list[this.share_act].proportionType]: s,
- });
- this.shareChart([share[0], share[1]]);
- });
- },
- share_change(i) {
- this.share_act = i;
- this.init();
- },
- shareChart(list) {
- if (!this.$refs.share) return;
- if (share_chart && share_chart.dispose) {
- share_chart.dispose();
- share_chart = undefined;
- }
- share_chart = echarts.init(this.$refs.share);
- share_chart.resize({
- height: (this.$refs.share.offsetWidth * 6) / 16,
- });
- var option = {
- title: [
- {
- text: "重点媒体份额",
- top: 10,
- left: 50,
- },
- ],
- tooltip: {
- trigger: "item",
- formatter: item => {
- return (
- item.name +
- " " +
- (Number(item.value).toFixed(2) - 0) +
- (this.share_list[this.share_act].unit || "")
- );
- },
- },
- legend: {
- left: "center",
- bottom: 10,
- },
- series: list.map((v, i) => {
- return {
- name: i === 0 ? "硬广" : "软广",
- type: "pie",
- radius: ["30%", "60%"],
- center: [25 + i * 50 + "%", "50%"],
- avoidLabelOverlap: false,
- label: {
- show: true,
- formatter: item => {
- return (
- item.name +
- " \n" +
- (Number(item.value || 0).toFixed(2) - 0) +
- this.share_list[this.share_act].unit
- );
- },
- },
- labelLine: {
- show: true,
- },
- data: v.map(item => {
- return {
- name: item.name,
- value:
- item[this.share_list[this.share_act].proportionType] || 0,
- };
- }),
- };
- }),
- };
- option && share_chart.setOption(option);
- },
- share1Chart(list) {
- if (!this.$refs.share1) return;
- if (share1_chart && share1_chart.dispose) {
- share1_chart.dispose();
- share1_chart = undefined;
- }
- share1_chart = echarts.init(this.$refs.share1);
- share1_chart.resize({
- height: (this.$refs.share1.offsetWidth * 6) / 25,
- });
- let t = -1;
- let k = this.share_list[this.share_act].proportionType || "";
- list[0][0] = list[0][0] || { [k]: 0 };
- list[0][1] = list[0][1] || { [k]: 0 };
- list[1][0] = list[1][0] || { [k]: 0 };
- list[1][1] = list[1][1] || { [k]: 0 };
- if (list[0][0][k] + list[1][0][k] === 0) t = 0;
- if (list[0][1][k] + list[1][1][k] === 0) t = 1;
- let li = list.map(v => {
- const item = v[0] || {};
- return {
- name: item.name,
- type: "bar",
- stack: "total",
- label: {
- show: true,
- formatter:(item) =>{
- return item.value + '%'
- }
- },
- emphasis: {
- focus: "series",
- },
- data: v.map(o => ((o[k] || 0) * 100).toFixed(2) - 0),
- };
- });
- if (t > -1 && k === "fee") {
- li.push({
- type: "bar",
- stack: "total",
- color: "rgba(255,255,255,1)",
- tooltip: {
- show: false,
- },
- label: {
- show: true,
- formatter: item => {
- if (t !== -1 && item.dataIndex === t) {
- return t === 0 ? "硬广无刊例价" : "软广无刊例价";
- }
- },
- },
- data: t === 1 ? [0, 100] : [100, 0],
- });
- }
- var option = {
- tooltip: {
- trigger: "item",
- axisPointer: {
- type: "shadow",
- },
- formatter: item => {
- return (
- item.name +
- "<br />" +
- item.seriesName +
- "<br />" +
- "占比:" +
- item.value +
- "%"
- );
- },
- },
- legend: {},
- grid: {
- left: "3%",
- right: "4%",
- bottom: "3%",
- containLabel: true,
- },
- color: ["#1b9ade", "#fd5555"],
- xAxis: {
- type: "value",
- },
- yAxis: {
- type: "category",
- data: ["硬广", "软广"],
- },
- series: li,
- };
- option && share1_chart.setOption(option);
- },
- },
- beforeUnmount: function() {
- share1_chart && share1_chart.dispose();
- share_chart && share_chart.dispose();
- share1_chart && (share1_chart = undefined);
- share_chart && (share_chart = undefined);
- },
- components: {},
- };
- </script>
- <style></style>
|