newHome.vue 29 KB

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