newHome.vue 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  1. <template>
  2. <div class="homePage">
  3. <div>
  4. <a-row :gutter="16">
  5. <a-col :span="24">
  6. <a-card :bordered="false" class="search-box">
  7. <div class="time" @click="opendate" >
  8. <datePick :dateValue.sync='dateValue' :type.sync='type' />
  9. </div>
  10. </a-card>
  11. </a-col>
  12. <a-col :sm="24" :md="12" :xl="6" :xxl="6" class="topBox">
  13. <div class="showBox">
  14. <div class="title">
  15. 总消耗
  16. <p class="numshow">¥{{cost.weekCostSum | decimalsHandle}}</p>
  17. <a-tooltip>
  18. <template slot="title">最近七天的总消耗</template>
  19. <span>
  20. <a-icon type="exclamation-circle" />
  21. </span>
  22. </a-tooltip>
  23. </div>
  24. <div id="costChart" style="width:100%;height:70px" ref="costChart"></div>
  25. <div class="footerInfo">
  26. 周环比
  27. <span class="num">
  28. <span v-if="cost.weekCostSumLink">{{cost.weekCostSumLink|toPercentage}}</span>
  29. <span v-else>{{'-'}}</span>
  30. <span
  31. class="redIcon"
  32. v-if="cost.weekCostSumLink>0"
  33. ></span>
  34. <span class="greenIcon" v-else></span>
  35. </span>
  36. </div>
  37. </div>
  38. </a-col>
  39. <a-col :sm="24" :md="12" :xl="6" :xxl="6" class="topBox">
  40. <div class="showBox">
  41. <div class="title">
  42. 点击数
  43. <p class="numshow">{{click.weekClickSum | formatCurrency}}</p>
  44. <a-tooltip>
  45. <template slot="title">最近七天的点击数</template>
  46. <span>
  47. <a-icon type="exclamation-circle" />
  48. </span>
  49. </a-tooltip>
  50. </div>
  51. <div id="clickChart" style="width:100%;height:70px" ref="clickChart"></div>
  52. <div class="footerInfo">
  53. 周环比
  54. <span class="num">
  55. <span v-if="click.weekClickSumLink">{{click.weekClickSumLink|toPercentage}}</span>
  56. <span v-else>{{'-'}}</span>
  57. <span
  58. class="redIcon"
  59. v-if="click.weekClickSumLink>0"
  60. ></span>
  61. <span class="greenIcon" v-else></span>
  62. </span>
  63. </div>
  64. </div>
  65. </a-col>
  66. <a-col :sm="24" :md="12" :xl="6" :xxl="6" class="topBox">
  67. <div class="showBox">
  68. <div class="title">
  69. 展示数
  70. <p class="numshow">{{showNum.weekShowNumSum | formatCurrency}}</p>
  71. <a-tooltip>
  72. <template slot="title">最近七天的展示数</template>
  73. <span>
  74. <a-icon type="exclamation-circle" />
  75. </span>
  76. </a-tooltip>
  77. </div>
  78. <div id="showChart" style="width:100%;height:70px" ref="showChart"></div>
  79. <div class="footerInfo">
  80. 周环比
  81. <span class="num">
  82. <span v-if="showNum.weekShowNumSumLink">{{showNum.weekShowNumSumLink | toPercentage}}</span>
  83. <span v-else>{{'-'}}</span>
  84. <span
  85. class="redIcon"
  86. v-if="showNum.weekShowNumSumLink>0"
  87. ></span>
  88. <span class="greenIcon" v-else></span>
  89. </span>
  90. </div>
  91. </div>
  92. </a-col>
  93. <a-col :sm="24" :md="12" :xl="6" :xxl="6" class="topBox">
  94. <div class="showBox">
  95. <div class="title">
  96. Top7账户消耗
  97. <a-tooltip>
  98. <template slot="title">最近七天的top7项目消耗</template>
  99. <span class="icon">
  100. <a-icon type="exclamation-circle" />
  101. </span>
  102. </a-tooltip>
  103. </div>
  104. <div id="topChart" style="width:100%;height:100px" ref="topChart"></div>
  105. <div class="footerInfo">TOP1: <span class="num">¥{{this.topOption.series[0].data[0] | decimalsHandle}}</span> </div>
  106. </div>
  107. </a-col>
  108. </a-row>
  109. </div>
  110. <!-- 折线图模块 -->
  111. <div class="section">
  112. <a-spin :spinning="spinning">
  113. <a-tabs default-active-key="cost" @change="callback" >
  114. <a-tab-pane key="cost" tab="总消耗">
  115. </a-tab-pane>
  116. <a-tab-pane key="click" tab="点击数" >
  117. </a-tab-pane>
  118. <a-tab-pane key="showNum" tab="展示数">
  119. </a-tab-pane>
  120. </a-tabs>
  121. <div id="sectionChart" style='width:100%;height:300px' ref="sectionChart"></div>
  122. <a-button class="duibi" @click="comparehandle" type='primary' >数据对比</a-button>
  123. </a-spin>
  124. </div>
  125. <!-- table数据 -->
  126. <div class="tableshow">
  127. <p><span>{{dateValue[0].format('YYYY-MM-DD')+'~'+dateValue[1].format('YYYY-MM-DD')}}</span></p>
  128. <a-table
  129. size="middle"
  130. :columns="columns"
  131. :dataSource="tableData"
  132. :pagination=false
  133. bordered
  134. id="outTable"
  135. :loading="loading"
  136. style="word-break: break-all;font-size:16px;font-weight:600"
  137. >
  138. <span slot="costProportion" slot-scope="costProportion">{{ costProportion | toPercentage }}</span>
  139. <span slot="cost" slot-scope="cost">{{ cost | decimalsHandle }}</span>
  140. <span slot="click" slot-scope="click">{{ click | formatCurrency }}</span>
  141. <span slot="showNum" slot-scope="showNum">{{ showNum | formatCurrency }}</span>
  142. <!-- <span slot="statDatetime" slot-scope>{{ dateValue[0].format('YYYY-MM-DD')+'~'+dateValue[1].format('YYYY-MM-DD')}}</span> -->
  143. </a-table>
  144. </div>
  145. <!-- <p class="footertip">我们是有底线的~</p> -->
  146. <CompareData :compareVisiable.sync='compareVisiable' @close_modal='close_modal' ref="compareData"/>
  147. </div>
  148. </template>
  149. <script>
  150. import moment from 'moment'
  151. import DatePicker from '@/components/DatePicker.vue'
  152. import datePick from './components/datePick'
  153. import CompareData from './CompareData.vue'
  154. import timeCheck from './components/timeCheck'
  155. import { getAction, postAction, downFile, downFilePost } from '@/api/manage'
  156. // import vueEchart from './components/vueEchart'
  157. // 引入基本模板
  158. var echarts = require('echarts')
  159. // 引入柱状图组件
  160. require('echarts/lib/chart/bar')
  161. require('echarts/lib/chart/pie')
  162. require('echarts/lib/chart/line')
  163. // 引入提示框和title组件
  164. require('echarts/lib/component/tooltip')
  165. require('echarts/lib/component/title')
  166. require('echarts/lib/component/graphic')
  167. require('echarts/lib/component/toolbox')
  168. require('echarts/lib/component/legend')
  169. let option = {
  170. color: ['#1890ff'],
  171. tooltip: {
  172. trigger: 'axis',
  173. axisPointer: {
  174. // 坐标轴指示器,坐标轴触发有效
  175. type: 'line' // 默认为直线,可选为:'line' | 'shadow'
  176. }
  177. },
  178. grid: {
  179. left: '0%',
  180. right: '0%',
  181. bottom: '0%',
  182. top: '12%',
  183. containLabel: false,
  184. },
  185. xAxis: [
  186. {
  187. type: 'category',
  188. data: [],
  189. show: true,
  190. axisTick: {
  191. alignWithLabel: true
  192. }
  193. }
  194. ],
  195. yAxis: [
  196. {
  197. type: 'value',
  198. show: false
  199. }
  200. ],
  201. series: [
  202. {
  203. name: '',
  204. type: 'bar',
  205. barWidth: '40%',
  206. smooth: true,
  207. areaStyle:{},
  208. itemStyle: {
  209. color: new echarts.graphic.LinearGradient(
  210. 0, 0, 0, 1,
  211. [
  212. {offset: 0, color: '#1890ff'},
  213. {offset: 1, color: '#FFF'}
  214. ]
  215. )
  216. },
  217. data: []
  218. }
  219. ]
  220. }
  221. let lineStyle= {
  222. color:{
  223. type: 'linear',
  224. x: 0,
  225. y: 0,
  226. x2: 0,
  227. y2: 1,
  228. colorStops: [{
  229. offset: 0, color: '#1890ff' // 0% 处的颜色
  230. }, {
  231. offset: 1, color: '#fff' // 100% 处的颜色
  232. }],
  233. global: false // 缺省为 false
  234. },
  235. // color: '#1890ff'
  236. }
  237. let sectionOption={
  238. tooltip: {
  239. trigger: 'axis',
  240. axisPointer: {
  241. // 坐标轴指示器,坐标轴触发有效
  242. type: 'line', // 默认为直线,可选为:'line' | 'shadow',
  243. }, 
  244. },
  245. legend: {
  246. data: ['总消耗']
  247. },
  248. grid: {
  249. left: '2%',
  250. right: '0%',
  251. bottom: '0%',
  252. top: '12%',
  253. containLabel: true
  254. },
  255. xAxis: [
  256. {
  257. type: 'category',
  258. data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
  259. axisTick: {
  260. alignWithLabel: true
  261. }
  262. }
  263. ],
  264. yAxis: [
  265. {
  266. type: 'value',
  267. show: true
  268. }
  269. ],
  270. series: [
  271. {
  272. name: '总消耗',
  273. type: 'line',
  274. smooth: true,
  275. data: [820, 932, 901, 934, 1290, 1330, 1320],
  276. color:'#32CD32'
  277. },
  278. {
  279. name: '',
  280. type: 'line',
  281. smooth: true,
  282. data: [],
  283. color:'#8A2BE2'
  284. },
  285. ]
  286. }
  287. let init={
  288. today:{
  289. x:['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00','07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00','19:00', '20:00', '21:00', '22:00', '23:00'],
  290. y:[],
  291. name:"今天"
  292. },
  293. yesterday:{
  294. x:['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00','07:00', '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00','19:00', '20:00', '21:00', '22:00', '23:00'],
  295. y:[],
  296. name:"昨天"
  297. },
  298. // huanbi:{
  299. // name:'环比',
  300. // y:[]
  301. // }
  302. }
  303. let columns = [
  304. {
  305. title: '时间',
  306. dataIndex: 'statDate',
  307. scopedSlots: { customRender: 'statDate' },
  308. align: 'center',
  309. key:'statDate'
  310. },
  311. {
  312. title: '消耗(元)',
  313. dataIndex: 'cost',
  314. scopedSlots: { customRender: 'cost' },
  315. align: 'center',
  316. key:'cost'
  317. },
  318. {
  319. title: '消耗环比',
  320. dataIndex: 'costProportion',
  321. scopedSlots: { customRender: 'costProportion' },
  322. align: 'center',
  323. key:"costProportion"
  324. },
  325. {
  326. title: '点击数',
  327. dataIndex: 'click',
  328. align: 'center',
  329. scopedSlots: { customRender: 'click' },
  330. key:'click'
  331. },
  332. {
  333. title: '点击率',
  334. dataIndex: 'clickRate',
  335. align: 'center',
  336. scopedSlots: { customRender: 'clickRate' },
  337. key:'clickRate'
  338. },
  339. {
  340. title: '展示数',
  341. dataIndex: 'showNum',
  342. align: 'center',
  343. scopedSlots: { customRender: 'showNum' },
  344. key:"showNum"
  345. },
  346. {
  347. title: '平均千次展现费用(元)',
  348. dataIndex: 'cpm',
  349. align: 'center',
  350. scopedSlots: { customRender: 'cpm' },
  351. key:'cpm'
  352. },
  353. {
  354. title: '平均点击单价(元)',
  355. dataIndex: 'cp',
  356. align: 'center',
  357. scopedSlots: { customRender: 'cp' },
  358. key:"cp"
  359. },
  360. ]
  361. export default {
  362. components:{
  363. DatePicker,
  364. CompareData,
  365. timeCheck,
  366. datePick
  367. },
  368. data() {
  369. return {
  370. //echart的配置项option
  371. topOption: JSON.parse(JSON.stringify(option)),
  372. costOption: JSON.parse(JSON.stringify(option)),
  373. clickOption: JSON.parse(JSON.stringify(option)),
  374. showOption: JSON.parse(JSON.stringify(option)),
  375. sectionOption:JSON.parse(JSON.stringify(sectionOption)),
  376. //页面四个块的数据
  377. cost: {},
  378. click: {},
  379. showNum: {},
  380. //tab的选中key
  381. tabKey:'',
  382. tabCost:{},
  383. tabClick:{},
  384. tabShowNum:{},
  385. //对比的模态框
  386. compareVisiable:false,
  387. //table
  388. loading: false,
  389. columns,
  390. tableData:[],
  391. //子元素的数据存储
  392. type:1,
  393. dateValue:[moment(), moment()],
  394. //日期矿打开
  395. openOptions:false,
  396. spinning:false,
  397. }
  398. },
  399. watch:{
  400. type(n,o){
  401. console.log(n,o)
  402. // console.log(this.type)
  403. if(this.type<9){
  404. this.sectionHttp({type:this.type})
  405. }else if(this.type==9){
  406. this.sectionHttp({
  407. type:this.type,
  408. startDate:this.dateValue[0].format('YYYY-MM-DD'),
  409. endDate:this.dateValue[1].format('YYYY-MM-DD')
  410. })
  411. }
  412. },
  413. dateValue: {
  414. handler(newName, oldName) {
  415. console.log(newName,oldName)
  416. if(newName.length>1){
  417. this.sectionHttp({
  418. type:this.type,
  419. startDate:this.dateValue[0].format('YYYY-MM-DD'),
  420. endDate:this.dateValue[1].format('YYYY-MM-DD')
  421. })
  422. }
  423. },
  424. immediate: true,
  425. deep: true
  426. }
  427. },
  428. methods: {
  429. //获取echart的值
  430. getEchartData(idName, optionName) {
  431. const chart = this.$refs[idName]
  432. // console.log(chart)
  433. if (chart) {
  434. const myChart = echarts.init(document.getElementById(idName))
  435. myChart.setOption(optionName)
  436. window.addEventListener('resize', function() {
  437. myChart.resize()
  438. })
  439. }
  440. },
  441. //网络请求方法
  442. echartsHttp() {
  443. return new Promise((resolve, reject) => {
  444. postAction('/ctop/byteDance/homePage/report/week', {}).then(res => {
  445. // console.log(res)
  446. if (res.success) {
  447. this.loading = false
  448. this.cost = res.result.costWeekLink
  449. this.click = res.result.clickWeekLink
  450. this.showNum = res.result.showNumWeekLink
  451. res.result.top.top7.forEach((element, index) => {
  452. this.topOption.xAxis[0].data.push(element.authName)
  453. this.topOption.series[0].data.push(element.cost)
  454. })
  455. res.result.costWeek.forEach((ele)=>{
  456. this.costOption.xAxis[0].data.push(ele.statDate)
  457. this.costOption.series[0].data.push(ele.cost)
  458. })
  459. res.result.clickWeek.forEach((ele)=>{
  460. this.clickOption.xAxis[0].data.push(ele.statDate)
  461. this.clickOption.series[0].data.push(ele.click)
  462. })
  463. res.result.showNumWeek.forEach((ele)=>{
  464. this.showOption.xAxis[0].data.push(ele.statDate)
  465. this.showOption.series[0].data.push(ele.showNum)
  466. })
  467. this.getEchartData('topChart', this.topOption)
  468. this.getEchartData('costChart', this.costOption)
  469. this.getEchartData('clickChart', this.clickOption)
  470. this.getEchartData('showChart', this.showOption)
  471. }
  472. })
  473. })
  474. },
  475. //处理echart
  476. sectionHttp(params) {
  477. this.loading = true;
  478. this.spinning=true;
  479. this.sectionOption=JSON.parse(JSON.stringify(sectionOption));
  480. return new Promise((resolve, reject) => {
  481. postAction('/ctop/byteDance/homePage/report/chart', params).then(res => {
  482. // console.log(res)
  483. if (res.success) {
  484. this.loading = false
  485. this.spinning=false;
  486. //处理今天
  487. if(res.result){
  488. if(res.result.chart[0].afterData && res.result.chart[0].afterData.statDate==moment().format('YYYY-MM-DD')){
  489. this.tabCost=JSON.parse(JSON.stringify(init))
  490. this.tabClick=JSON.parse(JSON.stringify(init))
  491. this.tabShowNum=JSON.parse(JSON.stringify(init))
  492. res.result.chart.forEach((item,index)=>{
  493. this.tabClick.yesterday.y.push(item.click)
  494. this.tabCost.yesterday.y.push(item.cost)
  495. this.tabShowNum.yesterday.y.push(item.showNum)
  496. if(item.afterData){
  497. this.tabClick.today.y.push(item.afterData.click)
  498. this.tabCost.today.y.push(item.afterData.cost)
  499. this.tabShowNum.today.y.push(item.afterData.showNum)
  500. }else{
  501. this.tabClick.today.y.push(0)
  502. this.tabCost.today.y.push(0)
  503. this.tabShowNum.today.y.push(0)
  504. }
  505. });
  506. // res.result.list.forEach((item)=>{
  507. // if(!item.costProportion){
  508. // // console.log(item.costProportion)
  509. // this.tabCost.huanbi.y.push('-')
  510. // }else{
  511. // let huanbi=(item.costProportion*100).toFixed(2)+'%'
  512. // this.tabCost.huanbi.y.push(huanbi)
  513. // }
  514. // })
  515. this.sectionOption.legend.data=['今天','昨天'];
  516. this.sectionOption.xAxis[0].data=this.tabCost.today.x;
  517. this.sectionOption.series[0].data=this.tabCost.today.y;
  518. this.sectionOption.series[0].name=this.tabCost.today.name;
  519. this.sectionOption.series[1].data=this.tabCost.yesterday.y;
  520. this.sectionOption.series[1].name=this.tabCost.yesterday.name;
  521. // this.sectionOption.series[2].data=this.tabCost.huanbi.y;
  522. // this.sectionOption.series[2].name=this.tabCost.huanbi.name;
  523. }else if(res.result.chart[0].afterData&& res.result.chart[0].afterData.statDate==moment().subtract(1,'days').format('YYYY-MM-DD')){
  524. //处理昨天
  525. this.tabCost=[]
  526. this.tabClick=[]
  527. this.tabShowNum=[]
  528. res.result.chart.forEach((item,index)=>{
  529. if(item.afterData){
  530. this.tabClick.push(item.afterData.click)
  531. this.tabCost.push(item.afterData.cost)
  532. this.tabShowNum.push(item.afterData.showNum)
  533. }else{
  534. this.tabClick.push(0)
  535. this.tabCost.push(0)
  536. this.tabShowNum.push(0)
  537. }
  538. });
  539. if(this.tabKey=='click'){
  540. this.sectionOption.legend.data=['点击数'];
  541. this.sectionOption.xAxis[0].data=init.today.x;
  542. this.sectionOption.series[0].data=this.tabClick;
  543. this.sectionOption.series[0].name='点击数';
  544. }else if(this.tabKey=='showNum'){
  545. this.sectionOption.legend.data=['展示数'];
  546. this.sectionOption.xAxis[0].data=init.today.x;
  547. this.sectionOption.series[0].data=this.tabShowNum;
  548. this.sectionOption.series[0].name='展示数';
  549. }else{
  550. this.sectionOption.xAxis[0].data=init.today.x;
  551. this.sectionOption.series[0].data=this.tabCost;
  552. }
  553. }else{
  554. this.tabCost={x:[],y:[]}
  555. this.tabClick={x:[],y:[]}
  556. this.tabShowNum={x:[],y:[]}
  557. res.result.chart.forEach((item,index)=>{
  558. this.tabClick.y.push(item.click)
  559. this.tabCost.y.push(item.cost)
  560. this.tabShowNum.y.push(item.showNum)
  561. this.tabClick.x.push(item.statDate)
  562. this.tabCost.x.push(item.statDate)
  563. this.tabShowNum.x.push(item.statDate)
  564. });
  565. if(this.tabKey=='click'){
  566. this.sectionOption.legend.data=['点击数'];
  567. this.sectionOption.xAxis[0].data=this.tabClick.x;
  568. this.sectionOption.series[0].data=this.tabClick.y;
  569. this.sectionOption.series[0].name='点击数';
  570. }else if(this.tabKey=='showNum'){
  571. this.sectionOption.legend.data=['展示数'];
  572. this.sectionOption.xAxis[0].data=this.tabShowNum.x;
  573. this.sectionOption.series[0].data=this.tabShowNum.y;
  574. this.sectionOption.series[0].name='展示数';
  575. }else{
  576. this.sectionOption.xAxis[0].data=this.tabCost.x;
  577. this.sectionOption.series[0].data=this.tabCost.y;
  578. }
  579. }
  580. this.getEchartData('sectionChart', this.sectionOption);
  581. //处理表格数据
  582. let total={
  583. statDate:'总计',
  584. cost:0,
  585. click:0,
  586. clickRate:0,
  587. costProportion:'-',
  588. cp:0,
  589. cpm:0,
  590. showNum:0
  591. }
  592. var afterData=[];
  593. res.result.list.forEach((ele,index)=>{
  594. if(ele.afterData){
  595. if(!ele.afterData.costProportion){
  596. ele.afterData.costProportion='-'
  597. }
  598. if(ele.afterData.statHour||ele.afterData.statHour==0){
  599. ele.afterData.statHour=ele.afterData.statHour > 9 ? `${ele.afterData.statHour}:00` : ` 0${ele.afterData.statHour}:00`
  600. ele.afterData.statDate=ele.afterData.statDate+' '+ele.afterData.statHour
  601. }
  602. ele.afterData.key=index+1
  603. total.click+=ele.afterData.click
  604. total.cost+=ele.afterData.cost
  605. total.showNum+=ele.afterData.showNum;
  606. afterData.push(ele.afterData)
  607. }else{
  608. if(!ele.costProportion){
  609. ele.costProportion='-'
  610. }
  611. if(ele.statHour||ele.statHour==0){
  612. ele.statHour=ele.statHour > 9 ? `${ele.statHour}:00` : ` 0${ele.statHour}:00`
  613. ele.statDate=ele.statDate+' '+ele.statHour
  614. }
  615. ele.key=index+1
  616. total.click+=ele.click
  617. total.cost+=ele.cost
  618. total.showNum+=ele.showNum
  619. }
  620. })
  621. total.cost=(total.cost).toFixed(2)
  622. total.clickRate=(total.click/total.showNum*100).toFixed(2)+'%'
  623. total.cp=(total.cost/total.click).toFixed(2)
  624. total.cpm=(total.cost/total.showNum*1000).toFixed(2)
  625. if(afterData.length>0){
  626. const defaultAfterData = afterData;
  627. defaultAfterData.forEach(item => {
  628. item.clickRate = Number(item.clickRate) + '%';
  629. });
  630. this.tableData = [total,...defaultAfterData]
  631. }else{
  632. const defaultData = res.result.list;
  633. defaultData.forEach(item => {
  634. item.clickRate = Number(item.clickRate) + '%';
  635. });
  636. this.tableData = [total,...defaultData]
  637. }
  638. }
  639. }
  640. })
  641. })
  642. },
  643. //tab切换页的事件
  644. callback(key) {
  645. // console.log(key);
  646. this.tabKey=key;
  647. this.sectionOption=JSON.parse(JSON.stringify(sectionOption))
  648. if(key=='cost'){
  649. if(this.type==1){
  650. this.sectionOption.legend.data=['今天','昨天'];
  651. this.sectionOption.xAxis[0].data=this.tabCost.today.x;
  652. this.sectionOption.series[0].data=this.tabCost.today.y;
  653. this.sectionOption.series[0].name=this.tabCost.today.name;
  654. this.sectionOption.series[1].data=this.tabCost.yesterday.y;
  655. this.sectionOption.series[1].name=this.tabCost.yesterday.name;
  656. }else if(this.type==2){
  657. this.sectionOption.xAxis[0].data=init.today.x;
  658. this.sectionOption.series[0].data=this.tabCost;
  659. }else{
  660. this.sectionOption.xAxis[0].data=this.tabCost.x;
  661. this.sectionOption.series[0].data=this.tabCost.y;
  662. }
  663. }else if(key=='click'){
  664. if(this.type==1){
  665. this.sectionOption.legend.data=['今天','昨天'];
  666. this.sectionOption.xAxis[0].data=this.tabClick.today.x;
  667. this.sectionOption.series[0].data=this.tabClick.today.y;
  668. this.sectionOption.series[0].name=this.tabClick.today.name;
  669. this.sectionOption.series[1].data=this.tabClick.yesterday.y;
  670. this.sectionOption.series[1].name=this.tabClick.yesterday.name;
  671. }else if(this.type==2){
  672. this.sectionOption.legend.data=['点击数'];
  673. this.sectionOption.xAxis[0].data=init.today.x;
  674. this.sectionOption.series[0].data=this.tabClick;
  675. this.sectionOption.series[0].name='点击数';
  676. }else{
  677. this.sectionOption.legend.data=['点击数'];
  678. this.sectionOption.xAxis[0].data=this.tabClick.x;
  679. this.sectionOption.series[0].data=this.tabClick.y;
  680. this.sectionOption.series[0].name='点击数';
  681. }
  682. }else{
  683. if(this.type==1){
  684. this.sectionOption.legend.data=['今天','昨天'];
  685. this.sectionOption.xAxis[0].data=this.tabShowNum.today.x;
  686. this.sectionOption.series[0].data=this.tabShowNum.today.y;
  687. this.sectionOption.series[0].name=this.tabShowNum.today.name;
  688. this.sectionOption.series[1].data=this.tabShowNum.yesterday.y;
  689. this.sectionOption.series[1].name=this.tabShowNum.yesterday.name;
  690. }else if(this.type==2){
  691. this.sectionOption.legend.data=['展示数'];
  692. this.sectionOption.xAxis[0].data=init.today.x;
  693. this.sectionOption.series[0].data=this.tabShowNum;
  694. this.sectionOption.series[0].name='展示数';
  695. }else{
  696. this.sectionOption.legend.data=['展示数'];
  697. this.sectionOption.xAxis[0].data=this.tabShowNum.x;
  698. this.sectionOption.series[0].data=this.tabShowNum.y;
  699. this.sectionOption.series[0].name='展示数';
  700. }
  701. }
  702. this.getEchartData('sectionChart', this.sectionOption)
  703. },
  704. //打开日期框
  705. opendate(){
  706. this.openOptions=!this.openOptions;
  707. // console.log(this.openOptions)
  708. },
  709. opendateClose(){
  710. this.openOptions=false;
  711. // console.log(this.openOptions)
  712. },
  713. //对比按钮的事件
  714. comparehandle(){
  715. this.compareVisiable=true;
  716. this.$refs.compareData.sectionHttp({
  717. type: 10,
  718. sign: 'month',
  719. smallDate: moment()
  720. .subtract(1, 'months')
  721. .format('YYYY-MM'),
  722. bigDate: moment().format('YYYY-MM')
  723. })
  724. },
  725. close_modal(n){
  726. // console.log(n)
  727. this.compareVisiable=n;
  728. },
  729. //对比模块的tab事件
  730. compareTab(key){
  731. console.log(key)
  732. }
  733. },
  734. mounted() {
  735. //处理四个图标的样式
  736. this.costOption.series[0].type = 'line';
  737. this.costOption.series[0].itemStyle = {};
  738. this.costOption.series[0].areaStyle = lineStyle;
  739. this.costOption.xAxis[0].boundaryGap = false
  740. this.showOption.series[0].type = 'line'
  741. this.showOption.series[0].itemStyle = {};
  742. this.showOption.series[0].areaStyle = lineStyle;
  743. this.showOption.xAxis[0].boundaryGap = false
  744. this.echartsHttp();
  745. this.sectionHttp({type:this.type});
  746. },
  747. filters: {
  748. toPercentage(val) {
  749. if(typeof val != 'string'){
  750. return (val * 100).toFixed(2) + '%'
  751. }else{
  752. return val
  753. }
  754. },
  755. //保留两位小数并且变成货币格式
  756. decimalsHandle(val){
  757. if(val && typeof val !='string'){
  758. if(val>=0){
  759. val=parseFloat(val).toFixed(2);
  760. let numberStr = val.toString()
  761. let str = numberStr.split('.')
  762. let str0=str[0].split('').reverse();
  763. for (let i = 0; i < str0.length; i++) {
  764. if ((i + 1) % 4 === 0) {
  765. str0.splice(i, 0, ',')
  766. }
  767. }
  768. str0.reverse()
  769. let handleResult = ''
  770. for (let j = 0; j < str0.length; j++) {
  771. handleResult += str0[j]
  772. }
  773. return handleResult+'.'+str[1]
  774. }else{
  775. val=parseFloat(val).toFixed(2);
  776. let numberStr = val.toString()
  777. let str = numberStr.split('.')
  778. let str0=str[0].substr(1).split('').reverse();
  779. for (let i = 0; i < str0.length; i++) {
  780. if ((i + 1) % 4 === 0) {
  781. str0.splice(i, 0, ',')
  782. }
  783. }
  784. str0.reverse()
  785. let handleResult = ''
  786. for (let j = 0; j < str0.length; j++) {
  787. handleResult += str0[j]
  788. }
  789. return '-'+handleResult+'.'+str[1]
  790. }
  791. }else if(typeof val =='string'){
  792. return val
  793. }
  794. else{
  795. return 0
  796. }
  797. },
  798. //变成货币格式
  799. formatCurrency(val){
  800. if(val){
  801. let numberStr = val.toString()
  802. let str = numberStr.split('').reverse()
  803. for (let i = 0; i < str.length; i++) {
  804. if ((i + 1) % 4 === 0) {
  805. str.splice(i, 0, ',')
  806. }
  807. }
  808. str.reverse()
  809. let handleResult = ''
  810. for (let j = 0; j < str.length; j++) {
  811. handleResult += str[j]
  812. }
  813. return handleResult
  814. }
  815. }
  816. }
  817. }
  818. </script>
  819. <style lang="scss" scoped>
  820. .homePage {
  821. p {
  822. margin-bottom: 0;
  823. }
  824. .topBox{
  825. margin-bottom: 12px;
  826. margin-top: 12px;
  827. border-radius: 2px;
  828. }
  829. .showBox {
  830. width: 100%;
  831. box-sizing: border-box;
  832. margin-right: 20px;
  833. padding: 25px 25px 0;
  834. background-color: #fff;
  835. border-radius: 2px;
  836. .title {
  837. color: #999;
  838. font-size: 16px;
  839. position: relative;
  840. span {
  841. font-size: 1rem;
  842. // color: #1890ff;
  843. position: absolute;
  844. top: 0;
  845. right: 0;
  846. cursor: pointer;
  847. }
  848. }
  849. .num{
  850. color: #000;
  851. font-size: 16px;;
  852. }
  853. .numshow {
  854. color:#333 ;
  855. font-weight: 500;
  856. font-size: 24px;
  857. padding: 5px 0;
  858. height: 30px;
  859. margin-bottom: 0;
  860. }
  861. }
  862. .topBox:last-child{
  863. margin-right: 0;
  864. }
  865. .footerInfo {
  866. margin-top: 10px;
  867. border-top: 1px solid #eee;
  868. padding: 10px 0;
  869. color: #666;
  870. font-size: 16px;
  871. position: relative;
  872. white-space: nowrap;
  873. overflow: hidden;
  874. text-overflow: ellipsis;
  875. .num {
  876. display: inline-block;
  877. margin-left: 10px;
  878. padding-right: 15px;
  879. position: relative;
  880. font-weight: 500;
  881. }
  882. .redIcon {
  883. width: 0;
  884. height: 0;
  885. border-left: 4px solid transparent;
  886. border-right: 4px solid transparent;
  887. border-bottom: 8px solid red;
  888. position: absolute;
  889. top: 40%;
  890. right: 0;
  891. }
  892. .greenIcon {
  893. width: 0;
  894. height: 0;
  895. border-left: 4px solid transparent;
  896. border-right: 4px solid transparent;
  897. border-top: 8px solid green;
  898. position: absolute;
  899. top: 40%;
  900. right: 0;
  901. }
  902. }
  903. .section{
  904. #sectionChart{
  905. padding: 0px 30px;
  906. }
  907. width: 100%;
  908. background-color: #fff;
  909. padding: 10px 0 20px;
  910. position: relative;
  911. margin-bottom: 12px;;
  912. border-radius: 2px;
  913. .duibi{
  914. position: absolute;
  915. height: 30px;
  916. line-height: 30px;
  917. padding: 0 15px;
  918. top: 8px;
  919. right: 20px;
  920. // border: 1px solid #666;
  921. cursor: pointer;
  922. }
  923. .time{
  924. position: absolute;
  925. width:280px;
  926. top: 15px;
  927. right: 0px;
  928. cursor: pointer;
  929. }
  930. }
  931. .tableshow{
  932. width: 100%;
  933. padding: 20px 15px;
  934. background-color: #fff;
  935. border-radius: 2px;
  936. p{
  937. width: 100%;
  938. border-bottom: 1px solid #ccc;
  939. padding-bottom: 20px;
  940. span{
  941. display: inline-block;
  942. border: 1px solid #ccc;
  943. padding: 5px 15px;
  944. border-radius: 5px;
  945. }
  946. }
  947. }
  948. .footertip{
  949. background: #fff;
  950. padding: 0 15px 20px;
  951. font-size: 16px;
  952. text-align: center;
  953. }
  954. }
  955. </style>