newHome.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  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. }
  280. let init={
  281. today:{
  282. 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'],
  283. y:[],
  284. name:"今天"
  285. },
  286. yesterday:{
  287. 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'],
  288. y:[],
  289. name:"昨天"
  290. },
  291. // huanbi:{
  292. // name:'环比',
  293. // y:[]
  294. // }
  295. }
  296. let columns = [
  297. {
  298. title: '时间',
  299. dataIndex: 'statDate',
  300. scopedSlots: { customRender: 'statDate' },
  301. align: 'center',
  302. key:'statDate'
  303. },
  304. {
  305. title: '消耗(元)',
  306. dataIndex: 'cost',
  307. scopedSlots: { customRender: 'cost' },
  308. align: 'center',
  309. key:'cost'
  310. },
  311. {
  312. title: '消耗环比',
  313. dataIndex: 'costProportion',
  314. scopedSlots: { customRender: 'costProportion' },
  315. align: 'center',
  316. key:"costProportion"
  317. },
  318. {
  319. title: '点击数',
  320. dataIndex: 'click',
  321. align: 'center',
  322. scopedSlots: { customRender: 'click' },
  323. key:'click'
  324. },
  325. {
  326. title: '点击率',
  327. dataIndex: 'clickRate',
  328. align: 'center',
  329. scopedSlots: { customRender: 'clickRate' },
  330. key:'clickRate'
  331. },
  332. {
  333. title: '展示数',
  334. dataIndex: 'showNum',
  335. align: 'center',
  336. scopedSlots: { customRender: 'showNum' },
  337. key:"showNum"
  338. },
  339. {
  340. title: '平均千次展现费用(元)',
  341. dataIndex: 'cpm',
  342. align: 'center',
  343. scopedSlots: { customRender: 'cpm' },
  344. key:'cpm'
  345. },
  346. {
  347. title: '平均点击单价(元)',
  348. dataIndex: 'cp',
  349. align: 'center',
  350. scopedSlots: { customRender: 'cp' },
  351. key:"cp"
  352. },
  353. ]
  354. export default {
  355. components:{
  356. DatePicker,
  357. CompareData
  358. },
  359. data() {
  360. return {
  361. //echart的配置项option
  362. topOption: JSON.parse(JSON.stringify(option)),
  363. costOption: JSON.parse(JSON.stringify(option)),
  364. clickOption: JSON.parse(JSON.stringify(option)),
  365. showOption: JSON.parse(JSON.stringify(option)),
  366. sectionOption:JSON.parse(JSON.stringify(sectionOption)),
  367. //页面四个块的数据
  368. cost: {},
  369. click: {},
  370. showNum: {},
  371. //tab的选中key
  372. tabKey:'',
  373. tabCost:{},
  374. tabClick:{},
  375. tabShowNum:{},
  376. //对比的模态框
  377. compareVisiable:false,
  378. //table
  379. loading: false,
  380. columns,
  381. tableData:[],
  382. //子元素的数据存储
  383. type:1,
  384. dateValue:[moment(),moment()],
  385. //日期矿打开
  386. openOptions:false,
  387. }
  388. },
  389. watch:{
  390. type(n,o){
  391. // console.log(n,o)
  392. // console.log(this.type)
  393. if(this.type<9){
  394. this.sectionHttp({type:this.type})
  395. }else if(this.type==9){
  396. this.sectionHttp({
  397. type:this.type,
  398. startDate:this.dateValue[0].format('YYYY-MM-DD'),
  399. endDate:this.dateValue[1].format('YYYY-MM-DD')
  400. })
  401. }
  402. },
  403. dateValue: {
  404. handler(newName, oldName) {
  405. console.log(newName,oldName)
  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. immediate: true,
  413. deep: true
  414. }
  415. },
  416. methods: {
  417. //获取echart的值
  418. getEchartData(idName, optionName) {
  419. const chart = this.$refs[idName]
  420. // console.log(chart)
  421. if (chart) {
  422. const myChart = echarts.init(document.getElementById(idName))
  423. myChart.setOption(optionName)
  424. window.addEventListener('resize', function() {
  425. myChart.resize()
  426. })
  427. }
  428. },
  429. //网络请求方法
  430. echartsHttp() {
  431. return new Promise((resolve, reject) => {
  432. postAction('/ctop/byteDance/homePage/report/week', {}).then(res => {
  433. // console.log(res)
  434. if (res.success) {
  435. this.loading = false
  436. this.cost = res.result.costWeekLink
  437. this.click = res.result.clickWeekLink
  438. this.showNum = res.result.showNumWeekLink
  439. res.result.top.top7.forEach((element, index) => {
  440. this.topOption.xAxis[0].data.push(element.authName)
  441. this.topOption.series[0].data.push(element.cost)
  442. })
  443. res.result.costWeek.forEach((ele)=>{
  444. this.costOption.xAxis[0].data.push(ele.statDate)
  445. this.costOption.series[0].data.push(ele.cost)
  446. })
  447. res.result.clickWeek.forEach((ele)=>{
  448. this.clickOption.xAxis[0].data.push(ele.statDate)
  449. this.clickOption.series[0].data.push(ele.click)
  450. })
  451. res.result.showNumWeek.forEach((ele)=>{
  452. this.showOption.xAxis[0].data.push(ele.statDate)
  453. this.showOption.series[0].data.push(ele.showNum)
  454. })
  455. this.getEchartData('topChart', this.topOption)
  456. this.getEchartData('costChart', this.costOption)
  457. this.getEchartData('clickChart', this.clickOption)
  458. this.getEchartData('showChart', this.showOption)
  459. }
  460. })
  461. })
  462. },
  463. //处理echart
  464. sectionHttp(params) {
  465. this.loading = true
  466. this.sectionOption=JSON.parse(JSON.stringify(sectionOption));
  467. return new Promise((resolve, reject) => {
  468. postAction('/ctop/byteDance/homePage/report/chart', params).then(res => {
  469. // console.log(res)
  470. if (res.success) {
  471. this.loading = false
  472. //处理今天
  473. if(res.result){
  474. if(res.result.chart[0].afterData && res.result.chart[0].afterData.statDate==moment().format('YYYY-MM-DD')){
  475. this.tabCost=JSON.parse(JSON.stringify(init))
  476. this.tabClick=JSON.parse(JSON.stringify(init))
  477. this.tabShowNum=JSON.parse(JSON.stringify(init))
  478. res.result.chart.forEach((item,index)=>{
  479. this.tabClick.yesterday.y.push(item.click)
  480. this.tabCost.yesterday.y.push(item.cost)
  481. this.tabShowNum.yesterday.y.push(item.showNum)
  482. if(item.afterData){
  483. this.tabClick.today.y.push(item.afterData.click)
  484. this.tabCost.today.y.push(item.afterData.cost)
  485. this.tabShowNum.today.y.push(item.afterData.showNum)
  486. }else{
  487. this.tabClick.today.y.push(0)
  488. this.tabCost.today.y.push(0)
  489. this.tabShowNum.today.y.push(0)
  490. }
  491. });
  492. // res.result.list.forEach((item)=>{
  493. // if(!item.costProportion){
  494. // // console.log(item.costProportion)
  495. // this.tabCost.huanbi.y.push('-')
  496. // }else{
  497. // let huanbi=(item.costProportion*100).toFixed(2)+'%'
  498. // this.tabCost.huanbi.y.push(huanbi)
  499. // }
  500. // })
  501. this.sectionOption.legend.data=['今天','昨天'];
  502. this.sectionOption.xAxis[0].data=this.tabCost.today.x;
  503. this.sectionOption.series[0].data=this.tabCost.today.y;
  504. this.sectionOption.series[0].name=this.tabCost.today.name;
  505. this.sectionOption.series[1].data=this.tabCost.yesterday.y;
  506. this.sectionOption.series[1].name=this.tabCost.yesterday.name;
  507. // this.sectionOption.series[2].data=this.tabCost.huanbi.y;
  508. // this.sectionOption.series[2].name=this.tabCost.huanbi.name;
  509. }else if(res.result.chart[0].afterData&& res.result.chart[0].afterData.statDate==moment().subtract(1,'days').format('YYYY-MM-DD')){
  510. //处理昨天
  511. this.tabCost=[]
  512. this.tabClick=[]
  513. this.tabShowNum=[]
  514. res.result.chart.forEach((item,index)=>{
  515. if(item.afterData){
  516. this.tabClick.push(item.afterData.click)
  517. this.tabCost.push(item.afterData.cost)
  518. this.tabShowNum.push(item.afterData.showNum)
  519. }else{
  520. this.tabClick.push(0)
  521. this.tabCost.push(0)
  522. this.tabShowNum.push(0)
  523. }
  524. });
  525. if(this.tabKey=='click'){
  526. this.sectionOption.legend.data=['点击数'];
  527. this.sectionOption.xAxis[0].data=init.today.x;
  528. this.sectionOption.series[0].data=this.tabClick;
  529. this.sectionOption.series[0].name='点击数';
  530. }else if(this.tabKey=='showNum'){
  531. this.sectionOption.legend.data=['展示数'];
  532. this.sectionOption.xAxis[0].data=init.today.x;
  533. this.sectionOption.series[0].data=this.tabShowNum;
  534. this.sectionOption.series[0].name='展示数';
  535. }else{
  536. this.sectionOption.xAxis[0].data=init.today.x;
  537. this.sectionOption.series[0].data=this.tabCost;
  538. }
  539. }else{
  540. this.tabCost={x:[],y:[]}
  541. this.tabClick={x:[],y:[]}
  542. this.tabShowNum={x:[],y:[]}
  543. res.result.chart.forEach((item,index)=>{
  544. this.tabClick.y.push(item.click)
  545. this.tabCost.y.push(item.cost)
  546. this.tabShowNum.y.push(item.showNum)
  547. this.tabClick.x.push(item.statDate)
  548. this.tabCost.x.push(item.statDate)
  549. this.tabShowNum.x.push(item.statDate)
  550. });
  551. if(this.tabKey=='click'){
  552. this.sectionOption.legend.data=['点击数'];
  553. this.sectionOption.xAxis[0].data=this.tabClick.x;
  554. this.sectionOption.series[0].data=this.tabClick.y;
  555. this.sectionOption.series[0].name='点击数';
  556. }else if(this.tabKey=='showNum'){
  557. this.sectionOption.legend.data=['展示数'];
  558. this.sectionOption.xAxis[0].data=this.tabShowNum.x;
  559. this.sectionOption.series[0].data=this.tabShowNum.y;
  560. this.sectionOption.series[0].name='展示数';
  561. }else{
  562. this.sectionOption.xAxis[0].data=this.tabCost.x;
  563. this.sectionOption.series[0].data=this.tabCost.y;
  564. }
  565. }
  566. this.getEchartData('sectionChart', this.sectionOption);
  567. //处理表格数据
  568. let total={
  569. statDate:'总计',
  570. cost:0,
  571. click:0,
  572. clickRate:0,
  573. costProportion:'-',
  574. cp:0,
  575. cpm:0,
  576. showNum:0
  577. }
  578. res.result.list.forEach((ele,index)=>{
  579. if(!ele.costProportion){
  580. ele.costProportion='-'
  581. }
  582. if(ele.statHour||ele.statHour==0){
  583. ele.statHour=ele.statHour > 9 ? `${ele.statHour}:00` : ` 0${ele.statHour}:00`
  584. ele.statDate=ele.statDate+' '+ele.statHour
  585. }
  586. ele.key=index+1
  587. total.click+=ele.click
  588. total.cost+=ele.cost
  589. total.showNum+=ele.showNum
  590. })
  591. total.cost=(total.cost).toFixed(2)
  592. total.clickRate=(total.click/total.showNum*100).toFixed(2)+'%'
  593. total.cp=(total.cost/total.click).toFixed(2)
  594. total.cpm=(total.cost/total.showNum*1000).toFixed(2)
  595. this.tableData=[total,...res.result.list]
  596. }
  597. }
  598. })
  599. })
  600. },
  601. //tab切换页的事件
  602. callback(key) {
  603. // console.log(key);
  604. this.tabKey=key;
  605. this.sectionOption=JSON.parse(JSON.stringify(sectionOption))
  606. if(key=='cost'){
  607. if(this.type==1){
  608. this.sectionOption.legend.data=['今天','昨天'];
  609. this.sectionOption.xAxis[0].data=this.tabCost.today.x;
  610. this.sectionOption.series[0].data=this.tabCost.today.y;
  611. this.sectionOption.series[0].name=this.tabCost.today.name;
  612. this.sectionOption.series[1].data=this.tabCost.yesterday.y;
  613. this.sectionOption.series[1].name=this.tabCost.yesterday.name;
  614. }else if(this.type==2){
  615. this.sectionOption.xAxis[0].data=init.today.x;
  616. this.sectionOption.series[0].data=this.tabCost;
  617. }else{
  618. this.sectionOption.xAxis[0].data=this.tabCost.x;
  619. this.sectionOption.series[0].data=this.tabCost.y;
  620. }
  621. }else if(key=='click'){
  622. if(this.type==1){
  623. this.sectionOption.legend.data=['今天','昨天'];
  624. this.sectionOption.xAxis[0].data=this.tabClick.today.x;
  625. this.sectionOption.series[0].data=this.tabClick.today.y;
  626. this.sectionOption.series[0].name=this.tabClick.today.name;
  627. this.sectionOption.series[1].data=this.tabClick.yesterday.y;
  628. this.sectionOption.series[1].name=this.tabClick.yesterday.name;
  629. }else if(this.type==2){
  630. this.sectionOption.legend.data=['点击数'];
  631. this.sectionOption.xAxis[0].data=init.today.x;
  632. this.sectionOption.series[0].data=this.tabClick;
  633. this.sectionOption.series[0].name='点击数';
  634. }else{
  635. this.sectionOption.legend.data=['点击数'];
  636. this.sectionOption.xAxis[0].data=this.tabClick.x;
  637. this.sectionOption.series[0].data=this.tabClick.y;
  638. this.sectionOption.series[0].name='点击数';
  639. }
  640. }else{
  641. if(this.type==1){
  642. this.sectionOption.legend.data=['今天','昨天'];
  643. this.sectionOption.xAxis[0].data=this.tabShowNum.today.x;
  644. this.sectionOption.series[0].data=this.tabShowNum.today.y;
  645. this.sectionOption.series[0].name=this.tabShowNum.today.name;
  646. this.sectionOption.series[1].data=this.tabShowNum.yesterday.y;
  647. this.sectionOption.series[1].name=this.tabShowNum.yesterday.name;
  648. }else if(this.type==2){
  649. this.sectionOption.legend.data=['展示数'];
  650. this.sectionOption.xAxis[0].data=init.today.x;
  651. this.sectionOption.series[0].data=this.tabShowNum;
  652. this.sectionOption.series[0].name='展示数';
  653. }else{
  654. this.sectionOption.legend.data=['展示数'];
  655. this.sectionOption.xAxis[0].data=this.tabShowNum.x;
  656. this.sectionOption.series[0].data=this.tabShowNum.y;
  657. this.sectionOption.series[0].name='展示数';
  658. }
  659. }
  660. this.getEchartData('sectionChart', this.sectionOption)
  661. },
  662. //打开日期框
  663. opendate(){
  664. this.openOptions=!this.openOptions;
  665. // console.log(this.openOptions)
  666. },
  667. opendateClose(){
  668. this.openOptions=false;
  669. // console.log(this.openOptions)
  670. },
  671. //对比按钮的事件
  672. comparehandle(){
  673. this.compareVisiable=true;
  674. this.$refs.compareData.sectionHttp({
  675. type: 10,
  676. sign: 'month',
  677. smallDate: moment()
  678. .subtract(1, 'months')
  679. .format('YYYY-MM'),
  680. bigDate: moment().format('YYYY-MM')
  681. })
  682. },
  683. close_modal(n){
  684. // console.log(n)
  685. this.compareVisiable=n;
  686. },
  687. //对比模块的tab事件
  688. compareTab(key){
  689. console.log(key)
  690. }
  691. },
  692. mounted() {
  693. //处理四个图标的样式
  694. this.costOption.series[0].type = 'line';
  695. this.costOption.series[0].itemStyle = {};
  696. this.costOption.series[0].areaStyle = lineStyle;
  697. this.costOption.xAxis[0].boundaryGap = false
  698. this.showOption.series[0].type = 'line'
  699. this.showOption.series[0].itemStyle = {};
  700. this.showOption.series[0].areaStyle = lineStyle;
  701. this.showOption.xAxis[0].boundaryGap = false
  702. this.echartsHttp();
  703. this.sectionHttp({type:this.type});
  704. },
  705. filters: {
  706. toPercentage(val) {
  707. if(typeof val != 'string'){
  708. return (val * 100).toFixed(2) + '%'
  709. }else{
  710. return val
  711. }
  712. },
  713. //保留两位小数并且变成货币格式
  714. decimalsHandle(val){
  715. // console.log(val)
  716. if(val){
  717. val=parseFloat(val).toFixed(2);
  718. let numberStr = val.toString()
  719. let str = numberStr.split('.')
  720. let str0=str[0].split('').reverse();
  721. for (let i = 0; i < str0.length; i++) {
  722. if ((i + 1) % 4 === 0) {
  723. str0.splice(i, 0, ',')
  724. }
  725. }
  726. str0.reverse()
  727. let handleResult = ''
  728. for (let j = 0; j < str0.length; j++) {
  729. handleResult += str0[j]
  730. }
  731. return handleResult+'.'+str[1]
  732. }
  733. },
  734. //变成货币格式
  735. formatCurrency(val){
  736. if(val){
  737. let numberStr = val.toString()
  738. let str = numberStr.split('').reverse()
  739. for (let i = 0; i < str.length; i++) {
  740. if ((i + 1) % 4 === 0) {
  741. str.splice(i, 0, ',')
  742. }
  743. }
  744. str.reverse()
  745. let handleResult = ''
  746. for (let j = 0; j < str.length; j++) {
  747. handleResult += str[j]
  748. }
  749. return handleResult
  750. }
  751. }
  752. }
  753. }
  754. </script>
  755. <style lang="scss" scoped>
  756. .homePage {
  757. .topBox{
  758. margin-bottom: 20px;
  759. }
  760. .showBox {
  761. width: 98%;
  762. box-sizing: border-box;
  763. margin-right: 20px;
  764. padding: 25px 25px 0;
  765. background-color: #fff;
  766. .title {
  767. color: #999;
  768. font-size: 16px;
  769. position: relative;
  770. span {
  771. font-size: 1rem;
  772. // color: #1890ff;
  773. position: absolute;
  774. top: 0;
  775. right: 0;
  776. cursor: pointer;
  777. }
  778. }
  779. .num{
  780. color: #000;
  781. font-size: 16px;;
  782. }
  783. .numshow {
  784. color:#333 ;
  785. font-weight: 500;
  786. font-size: 24px;
  787. padding: 5px 0;
  788. height: 30px;
  789. margin-bottom: 0;
  790. }
  791. }
  792. .footerInfo {
  793. margin-top: 10px;
  794. border-top: 1px solid #eee;
  795. padding: 10px 0;
  796. color: #666;
  797. font-size: 16px;
  798. position: relative;
  799. white-space: nowrap;
  800. overflow: hidden;
  801. text-overflow: ellipsis;
  802. .num {
  803. display: inline-block;
  804. margin-left: 10px;
  805. padding-right: 15px;
  806. position: relative;
  807. font-weight: 500;
  808. }
  809. .redIcon {
  810. width: 0;
  811. height: 0;
  812. border-left: 4px solid transparent;
  813. border-right: 4px solid transparent;
  814. border-bottom: 8px solid red;
  815. position: absolute;
  816. top: 40%;
  817. right: 0;
  818. }
  819. .greenIcon {
  820. width: 0;
  821. height: 0;
  822. border-left: 4px solid transparent;
  823. border-right: 4px solid transparent;
  824. border-top: 8px solid green;
  825. position: absolute;
  826. top: 40%;
  827. right: 0;
  828. }
  829. }
  830. .section{
  831. width: 100%;
  832. background-color: #fff;
  833. padding: 10px 15px 20px;
  834. position: relative;
  835. margin-bottom: 20px;;
  836. .duibi{
  837. position: absolute;
  838. height: 30px;
  839. line-height: 30px;
  840. padding: 0 15px;
  841. top: 15px;
  842. right: 300px;
  843. // border: 1px solid #666;
  844. cursor: pointer;
  845. }
  846. .time{
  847. position: absolute;
  848. width:280px;
  849. top: 15px;
  850. right: 0px;
  851. cursor: pointer;
  852. }
  853. }
  854. .tableshow{
  855. width: 100%;
  856. padding: 20px 15px;
  857. background-color: #fff;
  858. p{
  859. width: 100%;
  860. border-bottom: 1px solid #ccc;
  861. padding-bottom: 20px;
  862. span{
  863. display: inline-block;
  864. border: 1px solid #ccc;
  865. padding: 5px 15px;
  866. border-radius: 5px;
  867. }
  868. }
  869. }
  870. .footertip{
  871. background: #fff;
  872. padding: 0 15px 20px;
  873. font-size: 16px;
  874. text-align: center;
  875. }
  876. }
  877. </style>