tranche.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 share_list"
  11. :key="'share' + i"
  12. :plain="share_act !== i"
  13. @click="() => share_change(i)"
  14. >
  15. {{ item.text }}
  16. </el-button>
  17. </el-button-group>
  18. <br />
  19. <div ref="share1"></div>
  20. <br />
  21. <div ref="share"></div>
  22. </el-card>
  23. </template>
  24. <script>
  25. // @ is an alias to /src
  26. // import config from "@/config/index";
  27. import * as echarts from "echarts";
  28. import { industryList } from "@/api/index.js";
  29. let share1_chart = undefined,
  30. share_chart = undefined;
  31. export default {
  32. name: "AdvertisingEye_tranche",
  33. data() {
  34. return {
  35. share_act: 0,
  36. share_list: [
  37. {
  38. text: "时长",
  39. proportionType: "timeSize",
  40. unit: "分",
  41. type: 2,
  42. },
  43. {
  44. text: "频次",
  45. proportionType: "pinci",
  46. unit: "次",
  47. type: 1,
  48. },
  49. {
  50. text: "费用",
  51. proportionType: "fee",
  52. unit: "万",
  53. type: 3,
  54. },
  55. {
  56. text: "客户数",
  57. proportionType: "custom",
  58. unit: "个",
  59. type: 4,
  60. },
  61. ],
  62. };
  63. },
  64. props: {
  65. title: String,
  66. industry: Number,
  67. industryRang: Number,
  68. },
  69. watch: {
  70. industryRang() {
  71. this.init();
  72. },
  73. industry() {
  74. this.init();
  75. },
  76. },
  77. mounted() {
  78. share1_chart = undefined;
  79. share_chart = undefined;
  80. this.init();
  81. },
  82. computed: {},
  83. filter: {},
  84. methods: {
  85. init() {
  86. Promise.all([
  87. industryList({
  88. tableType: 5,
  89. dataType: this.share_list[this.share_act].type,
  90. indexTime: this.industryRang + 1,
  91. }),
  92. industryList({
  93. tableType: 15,
  94. dataType: this.share_list[this.share_act].type,
  95. indexTime: this.industryRang + 1,
  96. }),
  97. industryList({
  98. tableType: 6,
  99. dataType: this.share_list[this.share_act].type,
  100. indexTime: this.industryRang + 1,
  101. }),
  102. industryList({
  103. tableType: 16,
  104. dataType: this.share_list[this.share_act].type,
  105. indexTime: this.industryRang + 1,
  106. }),
  107. ]).then(all => {
  108. let barAll = [...(all[1] || []), ...(all[3] || [])],
  109. barGroup = [];
  110. let k = {};
  111. for (let i = 0; i < barAll.length; i++) {
  112. const v = barAll[i];
  113. if (isNaN(k[v.name])) {
  114. k[v.name] = barGroup.length;
  115. barGroup.push([]);
  116. }
  117. barGroup[k[v.name]].push(v);
  118. }
  119. this.share1Chart(barGroup);
  120. let share = [[], []],
  121. s = 0;
  122. all[0].map((v, i) => {
  123. if (i >= 9)
  124. s += v[this.share_list[this.share_act].proportionType] - 0;
  125. i < 9 && share[0].push(v);
  126. });
  127. share[0].push({
  128. name: "其它",
  129. [this.share_list[this.share_act].proportionType]: s,
  130. });
  131. s = 0;
  132. all[2].map((v, i) => {
  133. if (i >= 9)
  134. s += v[this.share_list[this.share_act].proportionType] - 0;
  135. i < 9 && share[1].push(v);
  136. });
  137. share[1].push({
  138. name: "其它",
  139. [this.share_list[this.share_act].proportionType]: s,
  140. });
  141. this.shareChart([share[0], share[1]]);
  142. });
  143. },
  144. share_change(i) {
  145. this.share_act = i;
  146. this.init();
  147. },
  148. shareChart(list) {
  149. if (!this.$refs.share) return;
  150. if (share_chart && share_chart.dispose) {
  151. share_chart.dispose();
  152. share_chart = undefined;
  153. }
  154. share_chart = echarts.init(this.$refs.share);
  155. share_chart.resize({
  156. height: (this.$refs.share.offsetWidth * 6) / 16,
  157. });
  158. var option = {
  159. title: [
  160. {
  161. text: "重点媒体份额",
  162. top: 10,
  163. left: 50,
  164. },
  165. ],
  166. tooltip: {
  167. trigger: "item",
  168. formatter: item => {
  169. return (
  170. item.name +
  171. " " +
  172. (Number(item.value).toFixed(2) - 0) +
  173. (this.share_list[this.share_act].unit || "")
  174. );
  175. },
  176. },
  177. legend: {
  178. left: "center",
  179. bottom: 10,
  180. },
  181. series: list.map((v, i) => {
  182. return {
  183. name: i === 0 ? "硬广" : "软广",
  184. type: "pie",
  185. radius: ["30%", "60%"],
  186. center: [25 + i * 50 + "%", "50%"],
  187. avoidLabelOverlap: false,
  188. label: {
  189. show: true,
  190. formatter: item => {
  191. return (
  192. item.name +
  193. " \n" +
  194. (Number(item.value || 0).toFixed(2) - 0) +
  195. this.share_list[this.share_act].unit
  196. );
  197. },
  198. },
  199. labelLine: {
  200. show: true,
  201. },
  202. data: v.map(item => {
  203. return {
  204. name: item.name,
  205. value:
  206. item[this.share_list[this.share_act].proportionType] || 0,
  207. };
  208. }),
  209. };
  210. }),
  211. };
  212. option && share_chart.setOption(option);
  213. },
  214. share1Chart(list) {
  215. if (!this.$refs.share1) return;
  216. if (share1_chart && share1_chart.dispose) {
  217. share1_chart.dispose();
  218. share1_chart = undefined;
  219. }
  220. share1_chart = echarts.init(this.$refs.share1);
  221. share1_chart.resize({
  222. height: (this.$refs.share1.offsetWidth * 6) / 25,
  223. });
  224. let t = -1;
  225. let k = this.share_list[this.share_act].proportionType || "";
  226. list[0][0] = list[0][0] || { [k]: 0 };
  227. list[0][1] = list[0][1] || { [k]: 0 };
  228. list[1][0] = list[1][0] || { [k]: 0 };
  229. list[1][1] = list[1][1] || { [k]: 0 };
  230. if (list[0][0][k] + list[1][0][k] === 0) t = 0;
  231. if (list[0][1][k] + list[1][1][k] === 0) t = 1;
  232. let li = list.map(v => {
  233. const item = v[0] || {};
  234. return {
  235. name: item.name,
  236. type: "bar",
  237. stack: "total",
  238. label: {
  239. show: true,
  240. formatter:(item) =>{
  241. return item.value + '%'
  242. }
  243. },
  244. emphasis: {
  245. focus: "series",
  246. },
  247. data: v.map(o => ((o[k] || 0) * 100).toFixed(2) - 0),
  248. };
  249. });
  250. if (t > -1 && k === "fee") {
  251. li.push({
  252. type: "bar",
  253. stack: "total",
  254. color: "rgba(255,255,255,1)",
  255. tooltip: {
  256. show: false,
  257. },
  258. label: {
  259. show: true,
  260. formatter: item => {
  261. if (t !== -1 && item.dataIndex === t) {
  262. return t === 0 ? "硬广无刊例价" : "软广无刊例价";
  263. }
  264. },
  265. },
  266. data: t === 1 ? [0, 100] : [100, 0],
  267. });
  268. }
  269. var option = {
  270. tooltip: {
  271. trigger: "item",
  272. axisPointer: {
  273. type: "shadow",
  274. },
  275. formatter: item => {
  276. return (
  277. item.name +
  278. "<br />" +
  279. item.seriesName +
  280. "<br />" +
  281. "占比:" +
  282. item.value +
  283. "%"
  284. );
  285. },
  286. },
  287. legend: {},
  288. grid: {
  289. left: "3%",
  290. right: "4%",
  291. bottom: "3%",
  292. containLabel: true,
  293. },
  294. color: ["#1b9ade", "#fd5555"],
  295. xAxis: {
  296. type: "value",
  297. },
  298. yAxis: {
  299. type: "category",
  300. data: ["硬广", "软广"],
  301. },
  302. series: li,
  303. };
  304. option && share1_chart.setOption(option);
  305. },
  306. },
  307. beforeUnmount: function() {
  308. share1_chart && share1_chart.dispose();
  309. share_chart && share_chart.dispose();
  310. share1_chart && (share1_chart = undefined);
  311. share_chart && (share_chart = undefined);
  312. },
  313. components: {},
  314. };
  315. </script>
  316. <style></style>