// index.ts // 获取应用实例 let { getIndustry } = require('../../utils/api') Page({ data: { userInfo: {}, onInitChart: undefined, array_act: 0, channelList_act: 0, array: [ { text: "", startDate: "", endDate: "" } ], channelList: [ { channelId: -1, channelName: "", localIndex: -1 } ] }, dateFommat(clearDay = 0): (string | number)[] { // 格式化日期 【年,月,日】 const nowTime = new Date(); let nowDate = new Date(nowTime.getTime() - clearDay * 86400000), month = nowDate.getMonth() + 1 > 9 ? nowDate.getMonth() + 1 : "0" + (nowDate.getMonth() + 1), day = nowDate.getDate() > 9 ? nowDate.getDate() : "0" + nowDate.getDate(); return [nowDate.getFullYear(), month, day]; }, timeList(): { text: string; startDate: string; endDate: string; }[] { let o = this.dateFommat(1), time_select = [ { index: 1, text: "近1个月", startDate: "", endDate: "" }, ]; o[1] === 1 ? (o[0] = o[0] - 1) : ""; o[1] > 1 ? --o[1] : (o[1] = 12); let lastMonth = new Date(o[0], o[1], 0); time_select[0].startDate = `${o[0]}-${o[1] > 9 ? o[1] : "0" + o[1]}-01`; time_select[0].endDate = `${o[0]}-${o[1] > 9 ? o[1] : "0" + o[1] }-${lastMonth.getDate()}`; let len = [3, 6]; for (let i = 0; i < len.length; i++) { let v = len[i]; var date = new Date(); date.setMonth(date.getMonth() - v - 1); time_select.push({ index: i + 2, text: v === 3 ? "近三个月" : "近半年", startDate: `${date.getFullYear()}-${date.getMonth() > 9 ? date.getMonth() : "0" + date.getMonth() }-01`, endDate: time_select[0].endDate, }); } time_select.push({ index: 4, text: `${o[0]}年`, startDate: `${o[0]}-01-01`, endDate: `${o[0]}-12-31`, }); return time_select; }, bindPickerChange(event: wxPicker) { const item = this.data.array[Number(event.detail.value)]; console.log(item) this.setData({ array_act: Number(event.detail.value) }) }, channelChange(event: wxPicker) { this.setData({ channelList_act: Number(event.detail.value) }) }, onLoad() { const user = wx.getStorageSync("userInfo") || {}; let p = { userInfo: {}, array: this.timeList(), channelList: [ { channelId: -1, channelName: "", localIndex: -1 } ] }; user.signature && (p.userInfo = user) getIndustry().then((li: { industryId: number, industryName: string }[]) => { p.channelList = (li || []).map((v, i) => { return { channelId: v.industryId, channelName: v.industryName, localIndex: i } }) p.channelList.unshift({ channelId: 0, channelName: "全行业", localIndex: -1 }) this.setData(p); }) }, getUserProfile() { // // 获取用户信息,妥善保管用户快速填写的头像昵称,避免重复弹窗 // wx.getUserProfile({ // desc: '大数据平台账户信息完善', // 声明获取用户个人信息后的用途,后续会展示在弹窗中 // success: (res) => { // if (!res.signature) return // wx.setStorageSync("userInfo", res) // this.setData({ // userInfo: res, // }) // } // }) }, })