SingleDay.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <div class="SingleDay">
  3. <el-breadcrumb separator-class="el-icon-arrow-right">
  4. <el-breadcrumb-item>传统媒体</el-breadcrumb-item>
  5. <el-breadcrumb-item>频道全天节目</el-breadcrumb-item>
  6. </el-breadcrumb>
  7. <el-card class="box-card">
  8. <el-form
  9. ref="form"
  10. :model="form"
  11. size="small"
  12. :inline="true"
  13. label-width="120px"
  14. class="demo-form-inline"
  15. >
  16. <el-form-item label="日期">
  17. <el-date-picker
  18. v-model="form.date"
  19. type="daterange"
  20. :disabled-date="time => disabledDate(time)"
  21. value-format="YYYY-MM-DD"
  22. range-separator="-"
  23. start-placeholder="开始日期"
  24. end-placeholder="结束日期"
  25. >
  26. </el-date-picker>
  27. </el-form-item>
  28. <el-form-item :label="v.name" v-for="(v, i) in searchDate" :key="i">
  29. <el-select
  30. v-model="form.filter[v.key]"
  31. :placeholder="'请选择' + v.name"
  32. multiple
  33. collapse-tags
  34. @change="se => select(v, se)"
  35. >
  36. <el-option key="-1" v-if="v.id !== 'time'" label="全选" value="-1">
  37. </el-option>
  38. <el-option
  39. v-for="item in v.list || []"
  40. :key="item.id + ''"
  41. :label="item.name"
  42. :value="item.key + ''"
  43. >
  44. </el-option>
  45. </el-select>
  46. </el-form-item>
  47. <el-form-item style="float: right">
  48. <el-button type="primary" :loading="loading" @click="onSubmit"
  49. >查询</el-button
  50. >
  51. <el-button type="primary" :loading="loading1" @click="onExport"
  52. >导出</el-button
  53. >
  54. </el-form-item>
  55. </el-form>
  56. </el-card>
  57. <br />
  58. <el-card class="box-card">
  59. <line-charts
  60. :list="tableDate"
  61. v-if="tableData.length"
  62. xName="date"
  63. :keys="chartKeys"
  64. ></line-charts>
  65. <el-table
  66. :data="tableDate"
  67. :header-cell-style="{ backgroundColor: '#f4f5f7', color: '#606266' }"
  68. style="width: 100%"
  69. >
  70. <el-table-column
  71. align="center"
  72. show-overflow-tooltip
  73. prop="date"
  74. label="日期"
  75. class-name="nowrap"
  76. />
  77. <el-table-column
  78. v-for="(item, i) in tableKeys"
  79. :key="'table' + i"
  80. align="center"
  81. :prop="item.key"
  82. :formatter="matrer"
  83. :label="item.name"
  84. >
  85. <el-table-column
  86. v-for="(li, o) in item.children"
  87. :key="i + '-' + o"
  88. :prop="li.key"
  89. :label="li.name"
  90. :formatter="matrer"
  91. />
  92. </el-table-column>
  93. </el-table>
  94. </el-card>
  95. </div>
  96. </template>
  97. <script>
  98. // @ is an alias to /src
  99. import { tvselectDate, tvcountry } from "@/api/kuyun";
  100. import lineCharts from "@/views/Country/components/lineCharts";
  101. import config from "@/config/index";
  102. export default {
  103. name: "Channel",
  104. data() {
  105. return {
  106. form: {
  107. filter: {},
  108. date: [],
  109. field: [
  110. "day",
  111. "channel_2",
  112. "indicators_arrive",
  113. "indicators_market_ratings",
  114. "indicators_tv_ratings",
  115. ],
  116. info: 1,
  117. org_id: 20,
  118. },
  119. searchDate: [],
  120. loading: false,
  121. loading1: false,
  122. tableData: [],
  123. };
  124. },
  125. mounted() {
  126. const d = new Date(Date.now() - 86400000);
  127. let Y = d.getFullYear(),
  128. M = d.getMonth() + 1,
  129. D = d.getDate();
  130. M > 9 ? "" : (M = "0" + M);
  131. D > 9 ? "" : (D = "0" + D);
  132. this.form.date = [[Y, M, D].join("-"), [Y, M, D].join("-")];
  133. this.loading = true;
  134. tvselectDate({
  135. date: this.form.date,
  136. key: "channel_2,area_t_1",
  137. org_id: 20,
  138. }).then(r => {
  139. let area = false;
  140. this.searchDate = r || [];
  141. for (let i = 0; i < this.searchDate.length; i++) {
  142. const v = this.searchDate[i];
  143. if (/area/.test(v.id)) {
  144. if (area) continue;
  145. area = true;
  146. this.form.filter[v.id] = [v.list[0].key + ""];
  147. continue;
  148. }
  149. this.form.filter[v.id] = [v.list[0].key + ""];
  150. }
  151. tvcountry(this.form)
  152. .then(res => {
  153. console.log(res);
  154. this.loading = false;
  155. this.tableData = res || [];
  156. })
  157. .catch(() => {
  158. this.loading = false;
  159. });
  160. });
  161. },
  162. computed: {
  163. tableDate() {
  164. if (!this.tableData.length) return [];
  165. const obj = {};
  166. const b = [
  167. {
  168. key: "indicators_tv_ratings",
  169. name: "直播关注度",
  170. },
  171. {
  172. key: "indicators_market_ratings",
  173. name: "市占率",
  174. },
  175. {
  176. key: "indicators_arrive",
  177. name: "到达率",
  178. },
  179. ];
  180. for (let i = 0; i < this.tableData.length; i++) {
  181. const v = this.tableData[i];
  182. if (typeof obj[v.channel_2] !== "object") obj[v.channel_2] = {};
  183. obj[v.channel_2][v.day] = v;
  184. }
  185. let li = [],
  186. keys = Object.keys(obj),
  187. dataLen = Object.keys(obj[keys[0]]);
  188. for (let i = 0; i < dataLen.length; i++) {
  189. let p = {};
  190. for (let o = 0; o < keys.length; o++) {
  191. const v = obj[keys[o]][dataLen[i]];
  192. b.map(k => {
  193. p[keys[o] + "_" + k.key] = v[k.key];
  194. });
  195. }
  196. li.push({
  197. date: dataLen[i],
  198. ...p,
  199. });
  200. }
  201. return li;
  202. },
  203. chartKeys() {
  204. const obj = {},
  205. li = [];
  206. for (let i = 0; i < this.tableData.length; i++) {
  207. const b = [
  208. {
  209. key: "indicators_tv_ratings",
  210. name: "直播关注度",
  211. },
  212. {
  213. key: "indicators_market_ratings",
  214. name: "市占率",
  215. },
  216. {
  217. key: "indicators_arrive",
  218. name: "到达率",
  219. },
  220. ];
  221. const v = this.tableData[i];
  222. if (obj[v.channel_2] === true) continue;
  223. obj[v.channel_2] = true;
  224. li.push(
  225. ...b.map(k => {
  226. k.key = v.channel_2 + "_" + k.key;
  227. k.name = v.channel_2 + "_" + k.name;
  228. return k;
  229. })
  230. );
  231. }
  232. console.log(li);
  233. return li;
  234. },
  235. tableKeys() {
  236. const obj = {},
  237. li = [];
  238. for (let i = 0; i < this.tableData.length; i++) {
  239. const b = [
  240. {
  241. key: "indicators_tv_ratings",
  242. name: "直播关注度",
  243. },
  244. {
  245. key: "indicators_market_ratings",
  246. name: "市占率",
  247. },
  248. {
  249. key: "indicators_arrive",
  250. name: "到达率",
  251. },
  252. ];
  253. const v = this.tableData[i];
  254. if (obj[v.channel_2] === true) continue;
  255. obj[v.channel_2] = true;
  256. li.push({
  257. name: v.channel_2,
  258. children: b.map(k => {
  259. k.key = v.channel_2 + "_" + k.key;
  260. return k;
  261. }),
  262. });
  263. }
  264. return li;
  265. },
  266. },
  267. methods: {
  268. onExport() {
  269. this.loading1 = true;
  270. let form = JSON.parse(JSON.stringify(this.form));
  271. fetch(
  272. config.base.kuyunApi +
  273. "/api/evaluation/eye/download/performance/tvkpi/download",
  274. {
  275. method: "post",
  276. responseType: "blob",
  277. body: JSON.stringify(form),
  278. }
  279. )
  280. .then(res => {
  281. return res.blob();
  282. })
  283. .then(blob => {
  284. new Blob([blob]);
  285. let fileName = "频道分地区收视.csv";
  286. var link = document.createElement("a");
  287. link.href = window.URL.createObjectURL(blob);
  288. link.download = fileName;
  289. link.click();
  290. window.URL.revokeObjectURL(link.href);
  291. this.loading1 = false;
  292. });
  293. },
  294. disabledDate(time) {
  295. return time.getTime() > Date.now() - 86400000;
  296. },
  297. onSubmit() {
  298. this.loading = true;
  299. let form = JSON.parse(JSON.stringify(this.form));
  300. let keys = Object.keys(this.form.filter);
  301. for (let i = 0; i < keys.length; i++) {
  302. const v = keys[i];
  303. if (form.filter[v] != -1) continue;
  304. for (let o = 0; o < this.searchDate.length; o++) {
  305. const item = this.searchDate[o];
  306. if (v === item.key) {
  307. form.filter[v] = item.list.map(v => v.key);
  308. break;
  309. }
  310. }
  311. }
  312. tvcountry(form)
  313. .then(r => {
  314. this.tableData = r || [];
  315. this.loading = false;
  316. })
  317. .catch(() => {
  318. this.loading = false;
  319. });
  320. },
  321. matrer(row, column, cellValue) {
  322. return (cellValue * 100).toFixed(4) - 0 + "%";
  323. },
  324. select(v, se) {
  325. if (v.id === "time") {
  326. this.timeSelect(se, v.id, "0000_2400");
  327. } else this.timeSelect(se, v.id, "-1");
  328. },
  329. timeSelect(a, key, all) {
  330. let ngx = new RegExp(all + ",?", "g");
  331. let end = (a || [])[(a || []).length - 1],
  332. s = (a || []).join(",").replace(ngx, "");
  333. if (end !== all) this.form.filter[key] = s ? s.split(",") : [];
  334. else this.form.filter[key] = [all];
  335. },
  336. },
  337. components: { lineCharts },
  338. };
  339. </script>
  340. <style>
  341. .SingleDay {
  342. margin: 10px 15px;
  343. }
  344. .SingleDay .nowrap .cell {
  345. white-space: nowrap;
  346. }
  347. </style>