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