structureB.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <br />
  3. <el-card style="margin: 0 1em;">
  4. <div class="title_card" v-text="title"></div>
  5. <br />
  6. <el-button-group style="margin-left: 1.5em">
  7. <el-button
  8. size="small"
  9. type="primary"
  10. v-for="(item, i) in industry_list"
  11. :key="'industry' + i"
  12. :plain="industry_act !== i"
  13. @click="() => industry_change(i)"
  14. >
  15. {{ item.text }}
  16. </el-button>
  17. </el-button-group>
  18. <br />
  19. <div ref="industry"></div>
  20. </el-card>
  21. </template>
  22. <script>
  23. // @ is an alias to /src
  24. // import config from "@/config/index";
  25. import * as echarts from "echarts";
  26. import { smallIndustryProportion } from "@/api/index.js";
  27. let industry_chart = undefined;
  28. export default {
  29. name: "AdvertisingEye_structure",
  30. data() {
  31. return {
  32. industry_act: 0,
  33. industry_list: [
  34. {
  35. text: "时长",
  36. proportionType: "timeSize",
  37. type: 2,
  38. },
  39. {
  40. text: "频次",
  41. proportionType: "pinci",
  42. type: 1,
  43. },
  44. {
  45. text: "客户数",
  46. proportionType: "customer",
  47. type: 4,
  48. },
  49. ],
  50. };
  51. },
  52. props: {
  53. title: String,
  54. industry: Number,
  55. industryRang: Number,
  56. },
  57. watch: {
  58. industryRang() {
  59. this.init();
  60. },
  61. industry() {
  62. this.init();
  63. },
  64. },
  65. mounted() {
  66. this.init();
  67. },
  68. computed: {},
  69. filter: {},
  70. methods: {
  71. init() {
  72. smallIndustryProportion({
  73. industryId: this.industry,
  74. dataType: this.industryRang + 1,
  75. type: this.industry_list[this.industry_act].type,
  76. }).then(res => {
  77. let li = [[], [], [], []],
  78. keys = Object.keys(res),
  79. kv = {
  80. softSdata: 3,
  81. softMdata: 1,
  82. hardSdata: 2,
  83. hardMdata: 0,
  84. },
  85. key = this.industry_list[this.industry_act].proportionType;
  86. for (let i = 0; i < keys.length; i++) {
  87. const v = keys[i];
  88. li[kv[v]] = (res[v] || []).map(item => {
  89. let value = item[key];
  90. if (!isNaN(value)) value = (value - 0).toFixed(2);
  91. return {
  92. name: item.midIndustryName || item.smallIndustryName,
  93. value,
  94. };
  95. });
  96. }
  97. this.industryChart(li);
  98. });
  99. },
  100. industry_change(i) {
  101. this.industry_act = i;
  102. this.init();
  103. },
  104. industryChart(li) {
  105. if (!this.$refs.industry) return;
  106. if (industry_chart && industry_chart.dispose) {
  107. industry_chart.dispose();
  108. industry_chart = undefined;
  109. }
  110. industry_chart = echarts.init(this.$refs.industry);
  111. industry_chart.resize({
  112. height: (this.$refs.industry.offsetWidth * 6) / 8,
  113. });
  114. var option = {
  115. legend: {
  116. left: "center",
  117. bottom: 10,
  118. },
  119. title: [
  120. {
  121. text: "硬广-中行业占比",
  122. left: "20%",
  123. top: "5%",
  124. },
  125. {
  126. text: "软广-中行业占比",
  127. left: "70%",
  128. top: "5%",
  129. },
  130. {
  131. text: "硬广-小行业占比",
  132. left: "20%",
  133. top: "50%",
  134. },
  135. {
  136. text: "软广-小行业占比",
  137. left: "70%",
  138. top: "50%",
  139. },
  140. ],
  141. tooltip: {
  142. trigger: "item",
  143. },
  144. series: li.map((v, i) => {
  145. let h = Math.floor(i / 2);
  146. return {
  147. type: "pie",
  148. radius: "30%",
  149. center: [25 + 50 * (i % 2) + "%", 28 + 45 * h + "%"],
  150. avoidLabelOverlap: false,
  151. label: {
  152. show: false,
  153. },
  154. labelLine: {
  155. show: false,
  156. },
  157. data: v,
  158. };
  159. }),
  160. };
  161. option && industry_chart.setOption(option);
  162. },
  163. },
  164. beforeUnmount: function() {
  165. industry_chart && industry_chart.dispose();
  166. industry_chart && (industry_chart = undefined);
  167. },
  168. components: {},
  169. };
  170. </script>
  171. <style></style>