chart.mixin.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // 统计数据
  2. // 统计类型 1:首页banner;2:直播模块;3:最新活动;4:热门文章;5:新品橱窗;6:活动列表
  3. import Vue from 'vue'
  4. const chartMixin = {
  5. data() {
  6. const currentDate = this.getDate({
  7. format: true
  8. })
  9. return {
  10. date: currentDate,
  11. current:0,
  12. timeList: [
  13. { label: '全年', current: 0 },
  14. { label: '半年', current: 1 },
  15. { label: '月', current: 2 },
  16. { label: '日', current: 3 }
  17. ]
  18. }
  19. },
  20. computed: {
  21. startDate() {
  22. return this.getDate('start')
  23. },
  24. endDate() {
  25. return this.getDate('end')
  26. }
  27. },
  28. methods: {
  29. handleTimeClick(type,index){
  30. //年月日点击
  31. this.current = index
  32. },
  33. bindStartDateChange(event) {
  34. //开始时间
  35. console.log('开始时间==>', event.detail.value)
  36. this.queryData.startAddTime = event.detail.value
  37. },
  38. bindEndDateChange(event) {
  39. //结束时间
  40. console.log('结束时间==>', event.detail.value)
  41. this.queryData.endAddTime = event.detail.value
  42. },
  43. getDate(type) {
  44. const date = new Date()
  45. let year = date.getFullYear()
  46. let month = date.getMonth() + 1
  47. let day = date.getDate()
  48. if (type === 'start') {
  49. year = year - 1
  50. } else if (type === 'end') {
  51. year = year + 1
  52. }
  53. month = month > 9 ? month : '0' + month
  54. day = day > 9 ? day : '0' + day
  55. return `${year}-${month}-${day}`
  56. }
  57. }
  58. }
  59. export default chartMixin