index.js 1.3 KB

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