// miniprogram/pages/applog/applog.js var app = getApp() Page({ /** * 页面的初始数据 */ data: { defaultDay:[ new Date().getTime(), new Date().getTime()+24*60*60*1000, ], projectoption: [], devtypeList:[], personoption: [], installtimeFmt: '', show: false, minDate: new Date(2010, 0, 1).getTime(), devcode: '', project: '', devtype: '', installPerson:'', minDate: new Date(2018, 0, 1).getTime(), // maxDate: new Date(2018, 0, 31).getTime(), }, onDisplay() { this.setData({ show: true }); }, onClose() { this.setData({ show: false }); }, formatDate(date) { date = new Date(date); // return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`; var seperator1 = "-"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate; return currentdate; }, onConfirm(event) { // this.setData({ // show: false, // installtimeFmt: this.formatDate(event.detail), // }); const [start, end] = event.detail; this.setData({ show: false, installtimeFmt: `${this.formatDate(start)}~${this.formatDate(end)}`, }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var _this=this /** * 获取所属项目下拉列表 */ wx.cloud.callFunction({ name: 'getProject', data: { url: app.globalData.url + "project/getProject" }, }).then(res => { if (res.result.code == 200) { var projectList = res.result.data var projectArr = []; for (var i = 0; i < projectList.length; i++) { var project = { text: projectList[i].projectName, value: projectList[i].projectName }; projectArr.push(project); } _this.setData({ projectoption: projectArr }) } }).catch(err => { console.error(err); }) /** * 获取设备类型下拉列表 */ wx.cloud.callFunction({ name: 'getTypeList', data: { url: app.globalData.url + "deviceType/deviceType" }, }).then(res => { if (res.result.code == 200) { var TypeList = res.result.data var typeArr = []; for (var i = 0; i < TypeList.length; i++) { var type = { text: TypeList[i].productName, value: TypeList[i].productName }; typeArr.push(type); } _this.setData({ devtypeList: typeArr }) } }).catch(err => { console.error(err); }) //获取人员下拉列表 wx.cloud.callFunction({ name: 'getPerson', data: { url: app.globalData.url + "deviceType/getUser" }, }).then(res => { if (res.result.code == 200) { var users = res.result.data var personArr = []; for (var i = 0; i < users.length; i++) { var person = { text: users[i].name, value: users[i].name }; personArr.push(person); } _this.setData({ personoption: personArr }) } }).catch(err => { console.error(err); }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, scan() { var _this=this; wx.scanCode({ success(res) { var devcode=res.result _this.setData({ devcode: devcode, }); } }) }, confirm(event) { var that = this; var formValue = event.detail; var formName = event.target.dataset.id; that.setData({ [formName]: formValue }) }, selectprojectValue(event) { var that = this; that.setData({ project: event.detail }) }, selectDevType(event) { var that = this; that.setData({ devtype: event.detail }) }, selectpersonValue(event) { var that = this; that.setData({ installPerson: event.detail }) }, query: function (event) { var data={ devcode: this.data.devcode, installtimeFmt: this.data.installtimeFmt, project: this.data.project, devtype: this.data.devtype, installPerson:this.data.installPerson } wx.reLaunch({ url: '../applog/applog?params=' + JSON.stringify(data) }) // var that = this; // wx.cloud.callFunction({ // name: 'devicelog', // data: { // devcode: that.data.devcode, // installtimeFmt: that.data.installtimeFmt, // project: that.data.project, // devtype: that.data.devtype, // }, // }).then(res => { // // var resultObj=JSON.parse(res.result); // var resultObj=res.result; // if (resultObj.code == 200) { // wx.reLaunch({ // url: '../applog/applog?applogList=' + JSON.stringify(resultObj.data.rows) // }) // } // }).catch(err => { // console.error(err); // wx.showToast({ // title: "查询失败", // }) // }) }, })