index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {
  2. getSaleData,
  3. getIncomeList
  4. } from '~/api/sale'
  5. import event from '~/mixins/event'
  6. Page({
  7. behaviors: [event],
  8. data: {
  9. currentIndex: 1,
  10. categoryList: [{
  11. id: 1,
  12. title: '全部'
  13. }, {
  14. id: 2,
  15. title: '7日'
  16. }, {
  17. id: 3,
  18. title: '月'
  19. }, {
  20. id: 4,
  21. title: '季'
  22. }, {
  23. id: 5,
  24. title: '半年'
  25. }],
  26. allIncome: {},
  27. orderList: {},
  28. orderListKey: []
  29. },
  30. async onShow() {
  31. let allIncome = await getSaleData()
  32. this.getData()
  33. this.setData({
  34. allIncome,
  35. })
  36. },
  37. async getData() {
  38. let data = await getIncomeList({
  39. pageSize: 1000,
  40. type: this.data.currentIndex
  41. })
  42. let detailedList = {}
  43. data.list.forEach(item => {
  44. if (detailedList.hasOwnProperty(item.dateStr)) {
  45. detailedList[item.dateStr].push(item)
  46. } else {
  47. detailedList[item.dateStr] = [item]
  48. }
  49. })
  50. this.setData({
  51. orderList: detailedList,
  52. orderListKey: Object.keys(detailedList)
  53. })
  54. },
  55. setClass({
  56. currentTarget
  57. }) {
  58. this.setData({
  59. currentIndex: currentTarget.dataset.index,
  60. });
  61. this.getData()
  62. },
  63. })