allTrend.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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 hard_list"
  11. :key="'launch' + i"
  12. :plain="hard_act !== i"
  13. @click="() => hard_change(i)"
  14. >
  15. {{ item.text }}
  16. </el-button>
  17. </el-button-group>
  18. <br />
  19. <div ref="launch" id="launch"></div>
  20. <br />
  21. <div style="border-top: 1px dashed #eee"></div>
  22. <br />
  23. <el-button-group style="margin-left: 1.5em">
  24. <el-button
  25. size="small"
  26. type="primary"
  27. v-for="(item, i) in soft_list"
  28. :key="'trend' + i"
  29. :plain="soft_act !== i"
  30. @click="() => soft_change(i)"
  31. >
  32. {{ item.text }}
  33. </el-button>
  34. </el-button-group>
  35. <br />
  36. <div ref="trend"></div>
  37. </el-card>
  38. </template>
  39. <script>
  40. // @ is an alias to /src
  41. import { industryList } from "@/api/index.js";
  42. // import config from "@/config/index";
  43. import * as echarts from "echarts";
  44. let hard_chart = undefined;
  45. let soft_chart = undefined;
  46. export default {
  47. name: "AdvertisingEye_trend",
  48. data() {
  49. return {
  50. hard_act: 0,
  51. soft_act: 0,
  52. hard_list: [
  53. {
  54. text: "时长",
  55. proportionType: "timeSize",
  56. unit: "分",
  57. type: 2,
  58. },
  59. {
  60. text: "频次",
  61. proportionType: "pinci",
  62. unit: "次",
  63. type: 1,
  64. },
  65. {
  66. text: "费用",
  67. proportionType: "fee",
  68. unit: "万",
  69. type: 3,
  70. },
  71. ],
  72. soft_list: [
  73. {
  74. text: "时长",
  75. proportionType: "timeSize",
  76. unit: "分",
  77. type: 2,
  78. },
  79. {
  80. text: "频次",
  81. proportionType: "pinci",
  82. unit: "次",
  83. type: 1,
  84. },
  85. ],
  86. };
  87. },
  88. props: {
  89. title: String,
  90. industry: Number,
  91. industryRang: Number,
  92. industryAct: Number,
  93. },
  94. watch: {
  95. industryRang() {
  96. this.init();
  97. },
  98. industry() {
  99. this.init();
  100. },
  101. },
  102. mounted() {
  103. this.init();
  104. },
  105. computed: {},
  106. filter: {},
  107. methods: {
  108. init() {
  109. industryList({
  110. tableType: 1,
  111. dataType: this.hard_list[this.hard_act].type,
  112. indexTime: this.industryRang + 1,
  113. }).then(r => {
  114. let org = r || [],
  115. before = (org[0] || {}).linkType || "",
  116. returnObj = { before: [], now: [] };
  117. if (!org.length) return;
  118. for (let i = 0; i < org.length; i++) {
  119. const v = org[i];
  120. if (v.linkType === before) returnObj.before.push(v);
  121. else returnObj.now.push(v);
  122. }
  123. this.industryChart(returnObj);
  124. });
  125. industryList({
  126. tableType: 2,
  127. dataType: this.soft_list[this.soft_act].type,
  128. indexTime: this.industryRang + 1,
  129. }).then(r => {
  130. let org = r || [],
  131. before = (org[0] || {}).linkType || "",
  132. returnObj = { before: [], now: [] };
  133. if (!org.length) return;
  134. for (let i = 0; i < org.length; i++) {
  135. const v = org[i];
  136. if (v.linkType === before) returnObj.before.push(v);
  137. else returnObj.now.push(v);
  138. }
  139. this.trendChart(returnObj);
  140. });
  141. },
  142. hard_change(i) {
  143. this.hard_act = i;
  144. industryList({
  145. tableType: 1,
  146. dataType: this.hard_list[this.hard_act].type,
  147. indexTime: this.industryRang + 1,
  148. }).then(r => {
  149. let org = r || [],
  150. before = org[0].linkType,
  151. returnObj = { before: [], now: [] };
  152. for (let i = 0; i < org.length; i++) {
  153. const v = org[i];
  154. if (v.linkType === before) returnObj.before.push(v);
  155. else returnObj.now.push(v);
  156. }
  157. this.industryChart(returnObj);
  158. });
  159. },
  160. soft_change(i) {
  161. this.soft_act = i;
  162. industryList({
  163. tableType: 2,
  164. dataType: this.soft_list[this.soft_act].type,
  165. indexTime: this.industryRang + 1,
  166. }).then(r => {
  167. let org = r || [],
  168. before = org[0].linkType,
  169. returnObj = { before: [], now: [] };
  170. for (let i = 0; i < org.length; i++) {
  171. const v = org[i];
  172. if (v.linkType === before) returnObj.before.push(v);
  173. else returnObj.now.push(v);
  174. }
  175. this.trendChart(returnObj);
  176. });
  177. },
  178. launchtrendData(list = { before: [], now: [] }, keyName) {
  179. const org = list;
  180. let old = org.before || [];
  181. let now = org.now || [];
  182. let len = Math.max(old.length, now.length),
  183. key = this.hard_list[this[keyName + "_act"]].proportionType;
  184. let keys = [],
  185. realKey = [[], []],
  186. value = [[], []],
  187. lendata = [];
  188. for (let i = 0; i < len; i++) {
  189. let o = old[i] || {},
  190. n = now[i] || {};
  191. if (old.length > now.length) keys.push(o.name);
  192. else keys.push(n.name);
  193. o.dt && realKey[0].push(o.dt);
  194. n.dt && realKey[1].push(n.dt);
  195. o[key] >= 0 && value[0].push(o[key]);
  196. n[key] >= 0 && value[1].push(n[key]);
  197. }
  198. if (old && old.length) {
  199. let sDate = old[0].name,
  200. eDate = old[old.length - 1].name;
  201. if (sDate === eDate) lendata.push(sDate);
  202. else lendata.push(`${sDate}到${eDate}`);
  203. }
  204. if (now && now.length) {
  205. let sDate = now[0].name,
  206. eDate = now[now.length - 1].name;
  207. if (sDate === eDate) lendata.push(sDate);
  208. else lendata.push(`${sDate}到${eDate}`);
  209. }
  210. return {
  211. keys,
  212. realKey,
  213. lendata,
  214. value,
  215. };
  216. },
  217. formatNum(num) {
  218. if (isNaN(num)) return 0;
  219. if (num >= 100000000) return (num / 10000).toFixed(2) - 0 + "亿";
  220. if (num >= 10000) return (num / 10000).toFixed(2) - 0 + "万";
  221. return num;
  222. },
  223. industryChart(list) {
  224. if (!this.$refs.launch) return;
  225. if (hard_chart && hard_chart.dispose) {
  226. hard_chart.dispose();
  227. hard_chart = undefined;
  228. }
  229. hard_chart = echarts.init(this.$refs.launch);
  230. let chartData = this.launchtrendData(list, "hard");
  231. hard_chart.resize({
  232. height: (this.$refs.launch.offsetWidth * 6) / 16,
  233. });
  234. let c = ["#1b9ade", "#fd5555"];
  235. var option = {
  236. title: {
  237. text: "硬广趋势",
  238. top: 20,
  239. left: 50,
  240. },
  241. legend: {
  242. show: true,
  243. data: chartData.lendata,
  244. top: "10%",
  245. },
  246. xAxis: {
  247. type: "category",
  248. data: chartData.keys,
  249. boundaryGap: false,
  250. },
  251. yAxis: {
  252. type: "value",
  253. scale: true,
  254. name: "单位:" + this.hard_list[this.hard_act].unit,
  255. axisLabel: {
  256. formatter: arr => {
  257. return this.formatNum(arr);
  258. },
  259. },
  260. },
  261. color: c,
  262. tooltip: {
  263. trigger: "axis",
  264. textStyle: {
  265. color: "#000000",
  266. },
  267. backgroundColor: "rgba(255,255,255,.8)",
  268. borderColor: "#1b9ade",
  269. borderWidth: 1,
  270. formatter: m => {
  271. let out = "";
  272. for (let i = 0; i < m.length; i++) {
  273. const v = m[i];
  274. let time = (v.seriesName.split("到")[0] || "").split("-"),
  275. day =
  276. v.dataIndex > 8 ? v.dataIndex + 1 : "0" + (v.dataIndex + 1),
  277. val = (v.value - 0).toFixed(2) - 0;
  278. out +=
  279. "<div style='display:inline-block;width: 10px;height: 10px;border-radius: 50%;background: " +
  280. c[i] +
  281. "' ></div> " +
  282. time[0] +
  283. "-" +
  284. time[1];
  285. this.industryRang + 1 <= 2 ? (out += "-" + day) : "";
  286. out +=
  287. ": " + val + this.hard_list[this.hard_act].unit + "<br />";
  288. }
  289. return out;
  290. },
  291. },
  292. grid: [{ left: 150, top: "20%", buttom: 0, right: 100 }],
  293. series: chartData.value.map((data, i) => {
  294. return {
  295. showSymbol: false,
  296. name: chartData.lendata[i],
  297. data,
  298. type: "line",
  299. smooth: true,
  300. };
  301. }),
  302. };
  303. option && hard_chart.setOption(option);
  304. },
  305. trendChart(list) {
  306. if (!this.$refs.trend) return;
  307. if (soft_chart && soft_chart.dispose) {
  308. soft_chart.dispose();
  309. soft_chart = undefined;
  310. }
  311. soft_chart = echarts.init(this.$refs.trend);
  312. let chartData = this.launchtrendData(list, "soft");
  313. soft_chart.resize({
  314. height: (this.$refs.trend.offsetWidth * 6) / 16,
  315. });
  316. let c = ["#1b9ade", "#fd5555"];
  317. var option = {
  318. title: {
  319. text: "软广趋势",
  320. top: 20,
  321. left: 50,
  322. },
  323. legend: {
  324. show: true,
  325. data: chartData.lendata,
  326. top: "10%",
  327. },
  328. xAxis: {
  329. type: "category",
  330. data: chartData.keys,
  331. },
  332. color: c,
  333. tooltip: {
  334. trigger: "axis",
  335. textStyle: {
  336. color: "#000000",
  337. },
  338. backgroundColor: "rgba(255,255,255,.8)",
  339. borderColor: "#1b9ade",
  340. borderWidth: 1,
  341. formatter: m => {
  342. let out = "";
  343. for (let i = 0; i < m.length; i++) {
  344. const v = m[i];
  345. let time = (v.seriesName.split("到")[0] || "").split("-"),
  346. day =
  347. v.dataIndex > 8 ? v.dataIndex + 1 : "0" + (v.dataIndex + 1),
  348. val = (v.value - 0).toFixed(2) - 0;
  349. out +=
  350. "<div style='display:inline-block;width: 10px;height: 10px;border-radius: 50%;background: " +
  351. c[i] +
  352. "' ></div> " +
  353. time[0] +
  354. "-" +
  355. time[1];
  356. this.industryRang + 1 <= 2 ? (out += "-" + day) : "";
  357. out +=
  358. ": " + val + this.soft_list[this.soft_act].unit + "<br />";
  359. }
  360. return out;
  361. },
  362. },
  363. yAxis: {
  364. type: "value",
  365. name: "单位:" + this.soft_list[this.soft_act].unit,
  366. scale: true,
  367. axisLabel: {
  368. formatter: arr => {
  369. return this.formatNum(arr);
  370. },
  371. },
  372. },
  373. grid: [{ left: 150, top: "20%", buttom: 0, right: 100 }],
  374. series: chartData.value.map((v, i) => {
  375. return {
  376. showSymbol: false,
  377. name: chartData.lendata[i],
  378. data: v,
  379. type: "line",
  380. smooth: true,
  381. };
  382. }),
  383. };
  384. option && soft_chart.setOption(option);
  385. },
  386. },
  387. beforeUnmount: function() {
  388. hard_chart && hard_chart.dispose();
  389. soft_chart && soft_chart.dispose();
  390. hard_chart && (hard_chart = undefined);
  391. soft_chart && (soft_chart = undefined);
  392. },
  393. components: {},
  394. };
  395. </script>
  396. <style>
  397. .AdvertisingEye .title_card {
  398. font-weight: 600;
  399. background-color: #1989fa;
  400. height: 40px;
  401. line-height: 40px;
  402. color: #fff;
  403. font-size: 18px;
  404. padding-left: 12px;
  405. }
  406. </style>