distribution.vue 7.7 KB

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