distributionB.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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 soft_planting_list"
  11. :key="'soft_planting' + i"
  12. :plain="soft_planting_act !== i"
  13. @click="() => soft_planting_change(i)"
  14. >
  15. {{ item.text }}
  16. </el-button>
  17. </el-button-group>
  18. <br />
  19. <el-row>
  20. <el-col :span="12">
  21. <div class="customer_list">
  22. <div class="customer_list_head">
  23. 软广-节目类型占比
  24. </div>
  25. <div ref="softAd"></div>
  26. </div>
  27. </el-col>
  28. <el-col :span="12">
  29. <com-table
  30. :title="'栏目排名top10-' + (titleName || '')"
  31. :tableList="tableList"
  32. :child="true"
  33. >
  34. <template #cols>
  35. <el-table-column
  36. align="center"
  37. type="index"
  38. label="序号"
  39. width="50"
  40. />
  41. <el-table-column
  42. show-overflow-tooltip
  43. align="center"
  44. property="programName"
  45. label="栏目名称"
  46. >
  47. <template #default="scope">
  48. {{ scope.row.programName || "--" }}
  49. </template>
  50. </el-table-column>
  51. <el-table-column align="center" property="pinci">
  52. <template #header>
  53. <span
  54. :style="
  55. soft_planting_list[soft_planting_act].type === 1
  56. ? 'color: red'
  57. : ''
  58. "
  59. >
  60. 频次(次)
  61. </span>
  62. </template>
  63. <template #default="scope">
  64. {{ numFor(scope.row.pinci) }}
  65. </template>
  66. </el-table-column>
  67. <el-table-column align="center" property="timeSize">
  68. <template #header>
  69. <span
  70. :style="
  71. soft_planting_list[soft_planting_act].type === 2
  72. ? 'color: red'
  73. : ''
  74. "
  75. >
  76. 时长(秒)
  77. </span>
  78. </template>
  79. <template #default="scope">
  80. {{ numFor(scope.row.timeSize / 1000) }}
  81. </template>
  82. </el-table-column>
  83. <el-table-column align="center" property="customer" label="">
  84. <template #header>
  85. <span
  86. :style="
  87. soft_planting_list[soft_planting_act].type === 4
  88. ? 'color: red'
  89. : ''
  90. "
  91. >
  92. 客户数
  93. </span>
  94. </template>
  95. <template #default="scope">
  96. {{ numFor(scope.row.customer) }}
  97. </template>
  98. </el-table-column>
  99. </template>
  100. </com-table>
  101. </el-col>
  102. </el-row>
  103. </el-card>
  104. </template>
  105. <script>
  106. // @ is an alias to /src
  107. // import config from "@/config/index";
  108. import * as echarts from "echarts";
  109. import comTable from "./table.vue";
  110. import {
  111. ProgramTypeDistribution,
  112. ProgramTypeDistributionChart,
  113. } from "@/api/index.js";
  114. export default {
  115. name: "AdvertisingEye_distribution",
  116. data() {
  117. return {
  118. titleName: "",
  119. tableList: [],
  120. soft_planting_act: 0,
  121. soft_planting_list: [
  122. {
  123. text: "时长",
  124. proportionType: "timeSize",
  125. type: 2,
  126. },
  127. {
  128. text: "频次",
  129. proportionType: "pinci",
  130. type: 1,
  131. },
  132. {
  133. text: "客户数",
  134. proportionType: "custom",
  135. type: 4,
  136. },
  137. ],
  138. softAd_chart: undefined,
  139. };
  140. },
  141. props: {
  142. title: String,
  143. industry: Number,
  144. industryRang: Number,
  145. },
  146. watch: {
  147. industryRang() {
  148. this.init();
  149. },
  150. industry() {
  151. this.init();
  152. },
  153. },
  154. mounted() {
  155. this.init();
  156. },
  157. computed: {},
  158. filter: {},
  159. methods: {
  160. init() {
  161. Promise.all([
  162. ProgramTypeDistribution({
  163. industryId: this.industry,
  164. dataType: this.industryRang + 1,
  165. type: this.soft_planting_list[this.soft_planting_act].type,
  166. }),
  167. ProgramTypeDistributionChart({
  168. industryId: this.industry,
  169. dataType: this.industryRang + 1,
  170. type: this.soft_planting_list[this.soft_planting_act].type,
  171. }),
  172. ]).then(all => {
  173. const li = (all[0] || { data: [] }).data || [];
  174. this.tableList = all[1].data || [];
  175. li.length && (this.titleName = li[0].name || li[0].programType || "");
  176. this.softAdChart(li);
  177. });
  178. },
  179. soft_planting_change(i) {
  180. this.soft_planting_act = i;
  181. this.init();
  182. },
  183. softAdChart(list) {
  184. if (!this.$refs.softAd) return;
  185. if (this.softAd_chart && this.softAd_chart.dispose) {
  186. this.softAd_chart.dispose();
  187. this.softAd_chart = undefined;
  188. }
  189. this.softAd_chart = echarts.init(this.$refs.softAd);
  190. this.softAd_chart.resize({
  191. height: 524,
  192. });
  193. let k = [],
  194. item = [],
  195. max =
  196. list[0][
  197. this.soft_planting_list[this.soft_planting_act].proportionType
  198. ] || 0;
  199. list.map(v => {
  200. k.push({ name: v.programType, max });
  201. let val =
  202. (
  203. v[this.soft_planting_list[this.soft_planting_act].proportionType] -
  204. 0
  205. ).toFixed(2) - 0;
  206. item.push(val);
  207. });
  208. const buildSeries = function(data) {
  209. const helper = data.map((item, index) => {
  210. const arr = new Array(data.length);
  211. arr.splice(index, 1, item);
  212. return arr;
  213. });
  214. return [data, ...helper].map((item, index) => {
  215. return {
  216. type: "radar",
  217. symbol: index === 0 ? "circle" : "none",
  218. symbolSize: 6,
  219. itemStyle: {
  220. color: "rgb(157,200,241)",
  221. },
  222. lineStyle: {
  223. color: index === 0 ? "rgb(157,200,241)" : "transparent",
  224. width: 1,
  225. opacity: 0.5,
  226. },
  227. areaStyle: {
  228. color: index === 0 ? "rgba(157,200,241,.5)" : "transparent",
  229. },
  230. tooltip: {
  231. show: index === 0 ? false : true,
  232. formatter: function() {
  233. return k[index - 1].name + ":" + item[index - 1];
  234. },
  235. },
  236. z: index === 0 ? 1 : 2,
  237. data: [item],
  238. };
  239. });
  240. };
  241. let option = {
  242. tooltip: { trigger: "item" },
  243. radar: {
  244. radius: 130,
  245. shape: "circle",
  246. splitNumber: 5,
  247. splitArea: {
  248. show: true,
  249. },
  250. axisName: {
  251. color: "#0000ee",
  252. },
  253. indicator: k,
  254. },
  255. series: buildSeries(item),
  256. };
  257. option && this.softAd_chart.setOption(option);
  258. },
  259. numFor(num) {
  260. if (isNaN(num)) return 0;
  261. if (num >= 100000000) return (num / 100000000).toFixed(2) - 0 + "亿";
  262. if (num >= 10000) return (num / 10000).toFixed(2) - 0 + "万";
  263. return Number(num).toFixed(2) - 0;
  264. },
  265. },
  266. beforeUnmount: function() {
  267. this.softAd_chart && this.softAd_chart.dispose();
  268. this.softAd_chart && (this.softAd_chart = undefined);
  269. },
  270. components: {
  271. comTable,
  272. },
  273. };
  274. </script>
  275. <style scoped>
  276. .customer_list {
  277. width: 500px;
  278. margin: 30px auto;
  279. border: 1px solid #d2e7fc;
  280. border-top: 3px solid #40a1f3;
  281. }
  282. .customer_list_head {
  283. line-height: 42px;
  284. height: 42px;
  285. color: #378ee8;
  286. border-bottom: none;
  287. font-family: "Microsoft YaHei";
  288. text-align: center;
  289. font-size: 18px;
  290. background-color: #d9efff;
  291. }
  292. .headStyle .cell {
  293. font-weight: 600;
  294. color: #000;
  295. }
  296. </style>