index.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. console.log(item)
  59. this.setData({
  60. array_act: Number(event.detail.value)
  61. })
  62. },
  63. channelChange(event: wxPicker) {
  64. this.setData({
  65. channelList_act: Number(event.detail.value)
  66. })
  67. },
  68. onLoad() {
  69. const user = wx.getStorageSync("userInfo") || {};
  70. let p = {
  71. userInfo: {},
  72. array: this.timeList(),
  73. channelList: [
  74. { channelId: -1, channelName: "", localIndex: -1 }
  75. ]
  76. };
  77. user.signature && (p.userInfo = user)
  78. getChannel().then((li: { channelId: number, channelName: string }[]) => {
  79. p.channelList = (li || []).map((v, i) => {
  80. return {
  81. channelId: v.channelId,
  82. channelName: v.channelName,
  83. localIndex: i
  84. }
  85. })
  86. this.setData(p);
  87. })
  88. },
  89. getUserProfile() {
  90. // 获取用户信息,妥善保管用户快速填写的头像昵称,避免重复弹窗
  91. wx.getUserProfile({
  92. desc: '大数据平台账户信息完善', // 声明获取用户个人信息后的用途,后续会展示在弹窗中
  93. success: (res) => {
  94. if (!res.signature) return
  95. wx.setStorageSync("userInfo", res)
  96. this.setData({
  97. userInfo: res,
  98. })
  99. }
  100. })
  101. },
  102. })