newHome.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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. this.tableData=[total,...afterData]
  627. }else{
  628. this.tableData=[total,...res.result.list]
  629. }
  630. }
  631. }
  632. })
  633. })
  634. },
  635. //tab切换页的事件
  636. callback(key) {
  637. // console.log(key);
  638. this.tabKey=key;
  639. this.sectionOption=JSON.parse(JSON.stringify(sectionOption))
  640. if(key=='cost'){
  641. if(this.type==1){
  642. this.sectionOption.legend.data=['今天','昨天'];
  643. this.sectionOption.xAxis[0].data=this.tabCost.today.x;
  644. this.sectionOption.series[0].data=this.tabCost.today.y;
  645. this.sectionOption.series[0].name=this.tabCost.today.name;
  646. this.sectionOption.series[1].data=this.tabCost.yesterday.y;
  647. this.sectionOption.series[1].name=this.tabCost.yesterday.name;
  648. }else if(this.type==2){
  649. this.sectionOption.xAxis[0].data=init.today.x;
  650. this.sectionOption.series[0].data=this.tabCost;
  651. }else{
  652. this.sectionOption.xAxis[0].data=this.tabCost.x;
  653. this.sectionOption.series[0].data=this.tabCost.y;
  654. }
  655. }else if(key=='click'){
  656. if(this.type==1){
  657. this.sectionOption.legend.data=['今天','昨天'];
  658. this.sectionOption.xAxis[0].data=this.tabClick.today.x;
  659. this.sectionOption.series[0].data=this.tabClick.today.y;
  660. this.sectionOption.series[0].name=this.tabClick.today.name;
  661. this.sectionOption.series[1].data=this.tabClick.yesterday.y;
  662. this.sectionOption.series[1].name=this.tabClick.yesterday.name;
  663. }else if(this.type==2){
  664. this.sectionOption.legend.data=['点击数'];
  665. this.sectionOption.xAxis[0].data=init.today.x;
  666. this.sectionOption.series[0].data=this.tabClick;
  667. this.sectionOption.series[0].name='点击数';
  668. }else{
  669. this.sectionOption.legend.data=['点击数'];
  670. this.sectionOption.xAxis[0].data=this.tabClick.x;
  671. this.sectionOption.series[0].data=this.tabClick.y;
  672. this.sectionOption.series[0].name='点击数';
  673. }
  674. }else{
  675. if(this.type==1){
  676. this.sectionOption.legend.data=['今天','昨天'];
  677. this.sectionOption.xAxis[0].data=this.tabShowNum.today.x;
  678. this.sectionOption.series[0].data=this.tabShowNum.today.y;
  679. this.sectionOption.series[0].name=this.tabShowNum.today.name;
  680. this.sectionOption.series[1].data=this.tabShowNum.yesterday.y;
  681. this.sectionOption.series[1].name=this.tabShowNum.yesterday.name;
  682. }else if(this.type==2){
  683. this.sectionOption.legend.data=['展示数'];
  684. this.sectionOption.xAxis[0].data=init.today.x;
  685. this.sectionOption.series[0].data=this.tabShowNum;
  686. this.sectionOption.series[0].name='展示数';
  687. }else{
  688. this.sectionOption.legend.data=['展示数'];
  689. this.sectionOption.xAxis[0].data=this.tabShowNum.x;
  690. this.sectionOption.series[0].data=this.tabShowNum.y;
  691. this.sectionOption.series[0].name='展示数';
  692. }
  693. }
  694. this.getEchartData('sectionChart', this.sectionOption)
  695. },
  696. //打开日期框
  697. opendate(){
  698. this.openOptions=!this.openOptions;
  699. // console.log(this.openOptions)
  700. },
  701. opendateClose(){
  702. this.openOptions=false;
  703. // console.log(this.openOptions)
  704. },
  705. //对比按钮的事件
  706. comparehandle(){
  707. this.compareVisiable=true;
  708. this.$refs.compareData.sectionHttp({
  709. type: 10,
  710. sign: 'month',
  711. smallDate: moment()
  712. .subtract(1, 'months')
  713. .format('YYYY-MM'),
  714. bigDate: moment().format('YYYY-MM')
  715. })
  716. },
  717. close_modal(n){
  718. // console.log(n)
  719. this.compareVisiable=n;
  720. },
  721. //对比模块的tab事件
  722. compareTab(key){
  723. console.log(key)
  724. }
  725. },
  726. mounted() {
  727. //处理四个图标的样式
  728. this.costOption.series[0].type = 'line';
  729. this.costOption.series[0].itemStyle = {};
  730. this.costOption.series[0].areaStyle = lineStyle;
  731. this.costOption.xAxis[0].boundaryGap = false
  732. this.showOption.series[0].type = 'line'
  733. this.showOption.series[0].itemStyle = {};
  734. this.showOption.series[0].areaStyle = lineStyle;
  735. this.showOption.xAxis[0].boundaryGap = false
  736. this.echartsHttp();
  737. this.sectionHttp({type:this.type});
  738. },
  739. filters: {
  740. toPercentage(val) {
  741. if(typeof val != 'string'){
  742. return (val * 100).toFixed(2) + '%'
  743. }else{
  744. return val
  745. }
  746. },
  747. //保留两位小数并且变成货币格式
  748. decimalsHandle(val){
  749. if(val && typeof val !='string'){
  750. if(val>=0){
  751. val=parseFloat(val).toFixed(2);
  752. let numberStr = val.toString()
  753. let str = numberStr.split('.')
  754. let str0=str[0].split('').reverse();
  755. for (let i = 0; i < str0.length; i++) {
  756. if ((i + 1) % 4 === 0) {
  757. str0.splice(i, 0, ',')
  758. }
  759. }
  760. str0.reverse()
  761. let handleResult = ''
  762. for (let j = 0; j < str0.length; j++) {
  763. handleResult += str0[j]
  764. }
  765. return handleResult+'.'+str[1]
  766. }else{
  767. val=parseFloat(val).toFixed(2);
  768. let numberStr = val.toString()
  769. let str = numberStr.split('.')
  770. let str0=str[0].substr(1).split('').reverse();
  771. for (let i = 0; i < str0.length; i++) {
  772. if ((i + 1) % 4 === 0) {
  773. str0.splice(i, 0, ',')
  774. }
  775. }
  776. str0.reverse()
  777. let handleResult = ''
  778. for (let j = 0; j < str0.length; j++) {
  779. handleResult += str0[j]
  780. }
  781. return '-'+handleResult+'.'+str[1]
  782. }
  783. }else if(typeof val =='string'){
  784. return val
  785. }
  786. else{
  787. return 0
  788. }
  789. },
  790. //变成货币格式
  791. formatCurrency(val){
  792. if(val){
  793. let numberStr = val.toString()
  794. let str = numberStr.split('').reverse()
  795. for (let i = 0; i < str.length; i++) {
  796. if ((i + 1) % 4 === 0) {
  797. str.splice(i, 0, ',')
  798. }
  799. }
  800. str.reverse()
  801. let handleResult = ''
  802. for (let j = 0; j < str.length; j++) {
  803. handleResult += str[j]
  804. }
  805. return handleResult
  806. }
  807. }
  808. }
  809. }
  810. </script>
  811. <style lang="scss" scoped>
  812. .homePage {
  813. p {
  814. margin-bottom: 0;
  815. }
  816. .topBox{
  817. margin-bottom: 12px;
  818. margin-top: 12px;
  819. border-radius: 2px;
  820. }
  821. .showBox {
  822. width: 100%;
  823. box-sizing: border-box;
  824. margin-right: 20px;
  825. padding: 25px 25px 0;
  826. background-color: #fff;
  827. border-radius: 2px;
  828. .title {
  829. color: #999;
  830. font-size: 16px;
  831. position: relative;
  832. span {
  833. font-size: 1rem;
  834. // color: #1890ff;
  835. position: absolute;
  836. top: 0;
  837. right: 0;
  838. cursor: pointer;
  839. }
  840. }
  841. .num{
  842. color: #000;
  843. font-size: 16px;;
  844. }
  845. .numshow {
  846. color:#333 ;
  847. font-weight: 500;
  848. font-size: 24px;
  849. padding: 5px 0;
  850. height: 30px;
  851. margin-bottom: 0;
  852. }
  853. }
  854. .topBox:last-child{
  855. margin-right: 0;
  856. }
  857. .footerInfo {
  858. margin-top: 10px;
  859. border-top: 1px solid #eee;
  860. padding: 10px 0;
  861. color: #666;
  862. font-size: 16px;
  863. position: relative;
  864. white-space: nowrap;
  865. overflow: hidden;
  866. text-overflow: ellipsis;
  867. .num {
  868. display: inline-block;
  869. margin-left: 10px;
  870. padding-right: 15px;
  871. position: relative;
  872. font-weight: 500;
  873. }
  874. .redIcon {
  875. width: 0;
  876. height: 0;
  877. border-left: 4px solid transparent;
  878. border-right: 4px solid transparent;
  879. border-bottom: 8px solid red;
  880. position: absolute;
  881. top: 40%;
  882. right: 0;
  883. }
  884. .greenIcon {
  885. width: 0;
  886. height: 0;
  887. border-left: 4px solid transparent;
  888. border-right: 4px solid transparent;
  889. border-top: 8px solid green;
  890. position: absolute;
  891. top: 40%;
  892. right: 0;
  893. }
  894. }
  895. .section{
  896. #sectionChart{
  897. padding: 0px 30px;
  898. }
  899. width: 100%;
  900. background-color: #fff;
  901. padding: 10px 0 20px;
  902. position: relative;
  903. margin-bottom: 12px;;
  904. border-radius: 2px;
  905. .duibi{
  906. position: absolute;
  907. height: 30px;
  908. line-height: 30px;
  909. padding: 0 15px;
  910. top: 8px;
  911. right: 20px;
  912. // border: 1px solid #666;
  913. cursor: pointer;
  914. }
  915. .time{
  916. position: absolute;
  917. width:280px;
  918. top: 15px;
  919. right: 0px;
  920. cursor: pointer;
  921. }
  922. }
  923. .tableshow{
  924. width: 100%;
  925. padding: 20px 15px;
  926. background-color: #fff;
  927. border-radius: 2px;
  928. p{
  929. width: 100%;
  930. border-bottom: 1px solid #ccc;
  931. padding-bottom: 20px;
  932. span{
  933. display: inline-block;
  934. border: 1px solid #ccc;
  935. padding: 5px 15px;
  936. border-radius: 5px;
  937. }
  938. }
  939. }
  940. .footertip{
  941. background: #fff;
  942. padding: 0 15px 20px;
  943. font-size: 16px;
  944. text-align: center;
  945. }
  946. }
  947. </style>