index.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // index.ts
  2. // 获取应用实例
  3. let { getChannel } = require('../../utils/api')
  4. Page({
  5. data: {
  6. userInfo: {},
  7. onInitChart: undefined,
  8. array_act: 0,
  9. channelList_act: 0,
  10. array: [
  11. {
  12. text: "", startDate: "", endDate: ""
  13. }
  14. ],
  15. channelList: [
  16. {
  17. channelId: -1,
  18. channelName: "",
  19. localIndex: -1
  20. }
  21. ]
  22. },
  23. dateFommat(clearDay = 0): (string | number)[] {
  24. // 格式化日期 【年,月,日】
  25. const nowTime = new Date();
  26. let nowDate = new Date(nowTime.getTime() - clearDay * 86400000),
  27. month =
  28. nowDate.getMonth() + 1 > 9
  29. ? nowDate.getMonth() + 1
  30. : "0" + (nowDate.getMonth() + 1),
  31. day =
  32. nowDate.getDate() > 9 ? nowDate.getDate() : "0" + nowDate.getDate();
  33. return [nowDate.getFullYear(), month, day];
  34. },
  35. timeList(): { text: string; startDate: string; endDate: string; }[] {
  36. let o = this.dateFommat(1),
  37. oldT = this.dateFommat(7),
  38. timeSelect = [
  39. {
  40. text: "最近7天",
  41. startDate: oldT.join("-"),
  42. endDate: o.join("-"),
  43. },
  44. ];
  45. for (let i = 1; i <= 3; i++) {
  46. let T = this.dateFommat(30 * i),
  47. lastDay = new Date(Number(T[0]), Number(T[1]), 0);
  48. timeSelect.push({
  49. text: `${T[0]}年${T[1]}月`,
  50. startDate: `${T[0]}-${T[1]}-01`,
  51. endDate: `${T[0]}-${T[1]}-${lastDay.getDate()}`,
  52. });
  53. }
  54. return timeSelect;
  55. },
  56. bindPickerChange(event: wxPicker) {
  57. // const item = this.data.array[Number(event.detail.value)];
  58. this.setData({
  59. array_act: Number(event.detail.value)
  60. })
  61. },
  62. channelChange(event: wxPicker) {
  63. this.setData({
  64. channelList_act: Number(event.detail.value)
  65. })
  66. },
  67. onLoad() {
  68. const user = wx.getStorageSync("userInfo") || {};
  69. let p = {
  70. userInfo: {},
  71. array: this.timeList(),
  72. channelList: [
  73. { channelId: -1, channelName: "", localIndex: -1 }
  74. ]
  75. };
  76. user.signature && (p.userInfo = user)
  77. getChannel().then((li: { channelId: number, channelName: string }[]) => {
  78. p.channelList = (li || []).map((v, i) => {
  79. return {
  80. channelId: v.channelId,
  81. channelName: v.channelName,
  82. localIndex: i
  83. }
  84. })
  85. this.setData(p);
  86. })
  87. },
  88. })