index.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // index.ts
  2. // 获取应用实例
  3. let { getIndustry } = 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. time_select = [
  38. {
  39. index: 1,
  40. text: "近1个月",
  41. startDate: "",
  42. endDate: ""
  43. },
  44. ];
  45. o[1] === 1 ? (o[0] = o[0] - 1) : "";
  46. o[1] > 1 ? --o[1] : (o[1] = 12);
  47. let lastMonth = new Date(o[0], o[1], 0);
  48. time_select[0].startDate = `${o[0]}-${o[1] > 9 ? o[1] : "0" + o[1]}-01`;
  49. time_select[0].endDate = `${o[0]}-${o[1] > 9 ? o[1] : "0" + o[1]
  50. }-${lastMonth.getDate()}`;
  51. let len = [3, 6];
  52. for (let i = 0; i < len.length; i++) {
  53. let v = len[i];
  54. var date = new Date();
  55. date.setMonth(date.getMonth() - v - 1);
  56. time_select.push({
  57. index: i + 2,
  58. text: v === 3 ? "近三个月" : "近半年",
  59. startDate: `${date.getFullYear()}-${date.getMonth() > 9 ? date.getMonth() : "0" + date.getMonth()
  60. }-01`,
  61. endDate: time_select[0].endDate,
  62. });
  63. }
  64. time_select.push({
  65. index: 4,
  66. text: `${o[0]}年`,
  67. startDate: `${o[0]}-01-01`,
  68. endDate: `${o[0]}-12-31`,
  69. });
  70. return time_select;
  71. },
  72. bindPickerChange(event: wxPicker) {
  73. const item = this.data.array[Number(event.detail.value)];
  74. console.log(item)
  75. this.setData({
  76. array_act: Number(event.detail.value)
  77. })
  78. },
  79. channelChange(event: wxPicker) {
  80. this.setData({
  81. channelList_act: Number(event.detail.value)
  82. })
  83. },
  84. onLoad() {
  85. const user = wx.getStorageSync("userInfo") || {};
  86. let p = {
  87. userInfo: {},
  88. array: this.timeList(),
  89. channelList: [
  90. { channelId: -1, channelName: "", localIndex: -1 }
  91. ]
  92. };
  93. user.signature && (p.userInfo = user)
  94. getIndustry().then((li: { industryId: number, industryName: string }[]) => {
  95. p.channelList = (li || []).map((v, i) => {
  96. return {
  97. channelId: v.industryId,
  98. channelName: v.industryName,
  99. localIndex: i
  100. }
  101. })
  102. p.channelList.unshift({
  103. channelId: 0,
  104. channelName: "全行业",
  105. localIndex: -1
  106. })
  107. this.setData(p);
  108. })
  109. },
  110. getUserProfile() {
  111. // 获取用户信息,妥善保管用户快速填写的头像昵称,避免重复弹窗
  112. wx.getUserProfile({
  113. desc: '大数据平台账户信息完善', // 声明获取用户个人信息后的用途,后续会展示在弹窗中
  114. success: (res) => {
  115. if (!res.signature) return
  116. wx.setStorageSync("userInfo", res)
  117. this.setData({
  118. userInfo: res,
  119. })
  120. }
  121. })
  122. },
  123. })