Page({ /** * 页面的初始数据 */ data: { form: {}, showPage: false, showNull: false, roleKey: wx.getStorageSync('roleKey'), nextlevel: 0, showTabs: false, erectoListLevel: [], state: 0, listdata: [], active: 0, isadmin: true, bohui: true, show: false, text: '', itemId: '', // currentIndex:1, // totalPage:0, index: 1, total: 10, modalHidden: true, delModal: true, info1: 0, info2: 0, info3: 0, info4: 0, delDeviceId: 0, pageMask: false, prevBtnDis: true, nextBtnDis: false, properties: { currentIndex: { //当前页码 type: Number, value: 1 }, totalPage: { type: Number } }, }, lifetimes: { // 在组件实例进入页面节点树时执行 attached: function () { this.setData({ index: this.properties.currentIndex, total: this.properties.totalPage }) } }, // 详情展示 toxiangqin(e) { console.log(e.target.dataset.id) var id = e.target.dataset.id wx.navigateTo({ url: '/pages/xiangqing/xiangqing?id=' + id, }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, delAZ(e) { console.log(e); var item = e.currentTarget.dataset.base this.setData({ delModal: false, form: item, }) }, DelChange() { wx.request({ url: `https://puyue.yhupai.com/prod-api/iot/deviceOrder/${this.data.form.id}/${this.data.form.deviceId}`, method: "DELETE", header: { "Access-Control-Allow-Headers": 'token', Authorization: `Bearer ${wx.getStorageSync('token')}` }, success: (res, header) => { if (res.data.code == 200) { this.setData({ index: 1, delModal: true }) this.getNumInfo() this.getList() } else { this.setData({ index: 1, delModal: true }) this.getNumInfo() this.getList() } } }) }, DelCancel() { this.setData({ delModal: true }) }, // 设置异步请求之后的页面、总记录数 setPage(index, total) { this.setData({ index, total }) }, //每次改变页码就调用该函数 triggerParent: function () { // 通知父组件当前加载的页数 // 自定义组件向父组件传值 const option = { currentIndex: this.data.index }; // pagingChange 自定义名称事件,父组件中使用 this.triggerEvent('pagingChange', option) }, //开启页码弹窗 showPagePopUp: function () { this.setData({ pageMask: true }) }, //关闭页码弹窗 hidePagePopUp: function () { this.setData({ pageMask: false }) }, //更改页码点击事件 onChangePage: function (e) { //console.log("更改页码事件:",e); this.setData({ pageMask: false, index: e.currentTarget.dataset.index //点击的页数 }) this.getList() // 先判断当前页数,是否需要更新disabled的状态 this.updateBtnDis(); this.triggerParent(); }, //上一页点击事件 prevPage: function () { if (this.data.index <= 1) { this.setData({ prevBtnDis: false, }) return false } if (this.data.index <= this.data.total) { this.setData({ nextBtnDis: false, }) } let num = this.data.index - 1; this.setData({ index: num, prevBtnDis: true }) this.getList() this.triggerParent(); 更新按钮状态 this.updateBtnDis(); }, //下一页点击事件 nextPage: function () { if (this.data.index >= this.data.total) { this.setData({ nextBtnDis: false, }) return false } this.setData({ nextBtnDis: true, }) if (this.data.index >= 1) { this.setData({ prevBtnDis: false }) } let num = this.data.index + 1; this.setData({ index: num }) this.getList() this.triggerParent(); // 更新按钮状态 this.updateBtnDis(); }, onChange(event) { this.setData({ state: event.detail.index }) this.getNumInfo() this.getList() }, goTop() { // 一键回到顶部 wx.pageScrollTo({ scrollTop: 0, duration: 300 }); }, getList() { wx.showLoading({ title: '加载中', }) this.setData({ tableData: [] }) var erectoId = wx.getStorageSync("erectoId") var roleKey = wx.getStorageSync('roleKey') let data = { pageNum: this.data.index, pageSize: 5, state: this.data.state, orderType: 2, userId: erectoId } // if (roleKey == 'tenantservice') { // data.createUserId = 0 // data.erectoId = erectoId // } // if (roleKey == 'admin') { // data.createUserId = 0; // data.erectoId = 0; // } // if (roleKey == 'tenant' || roleKey == 'tenanthelper') { // data.createUserId = erectoId; // data.erectoId = 0; // } // if (this.data.active2 == 1) { //当选择下级时\ // data.createUserId = this.data.nextlevel // } console.log(data); wx.request({ url: 'https://puyue.yhupai.com/prod-api/iot/deviceOrder/list', method: "GET", header: { "Access-Control-Allow-Headers": 'token', Authorization: `Bearer ${wx.getStorageSync('token')}` }, data: data, success: (res, header) => { console.log(res); if (res.data.code == 200 && res.data.rows.length > 0) { let data = res.data let total = Math.ceil(res.data.total / 5) this.setData({ listdata: data.rows, total: total, showPage: true, showNull: false }) console.log(this.data.listdata); this.goTop() wx.hideLoading() } else { this.setData({ listdata: [], total: 0, showPage: false, showNull: true }) this.goTop() wx.hideLoading() } } }) }, openAddModal() { let data = { repairFlag: 0 } wx.request({ url: 'https://puyue.yhupai.com/prod-api/iot/device/shortListRepair', method: "GET", header: { "Access-Control-Allow-Headers": 'token', Authorization: `Bearer ${wx.getStorageSync('token')}` }, // data: data, success: (res, header) => { if (res.data.code != 200 || res.data.rows.length == 0) { wx.showToast({ title: '请先添加设备', icon:'none' }) return false } else { wx.navigateTo({ url: '/pages/repairTicketDetail/repairTicketDetail', }) } } }) }, getNumInfo() { var erectoId = wx.getStorageSync("erectoId") var roleKey = wx.getStorageSync('roleKey') let data = { orderType: '2', userId: erectoId, // state:this.data.state } if (roleKey == 'tenantservice') { data.createUserId = 0 data.erectoId = erectoId } if (roleKey == 'admin') { data.createUserId = 0; data.erectoId = 0; } if (roleKey == 'tenant' || roleKey == 'tenanthelper') { data.createUserId = erectoId; data.erectoId = 0; } if (this.data.active2 == 1) { //当选择下级时\ data.createUserId = this.data.nextlevel } wx.request({ url: `https://puyue.yhupai.com/prod-api/iot/deviceOrder/get`, method: "GET", header: { "Access-Control-Allow-Headers": 'token', Authorization: `Bearer ${wx.getStorageSync('token')}` }, data: data, success: (res, header) => { if (res.data.code == 200) { console.log(res); this.setData({ info1: res.data.data.deviceOrderUndeliveredorders, info2: res.data.data.deviceOrderDispatchedorders, info3: res.data.data.deviceOrderReceivedorders, info4: res.data.data.deviceOrderCompleted, }) } else { this.setData({ info1: 0, info2: 0, info3: 0, info4: 0, }) } } }) }, rate(e) { let item = JSON.parse(JSON.stringify(e.currentTarget.dataset.base)) let data = { id: item.id, userId: item.userId, orderType: item.orderType, isRate: 0, } wx.navigateTo({ url: `/pages/rate/rate?params=${JSON.stringify(data)}`, }) }, seeRate(e) { // let item = JSON.parse(JSON.stringify(e.currentTarget.dataset.base)) // let data = { // id: item.id, // userId: item.userId, // orderType: item.orderType, // isRate:1, // score:item.score, // evaluate:item.evaluate // } // wx.navigateTo({ // url: `/pages/rate/rate?params=${JSON.stringify(data)}`, // }) let item = JSON.parse(JSON.stringify(e.currentTarget.dataset.base)) wx.navigateTo({ url: '/pages/yetWX/yetWX?info=' + JSON.stringify(item), }) }, edit(e) { console.log(e); var item = e.currentTarget.dataset.base wx.navigateTo({ url: '/pages/repairTicketDetail/repairTicketDetail?info=' + JSON.stringify(item), }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getNumInfo() this.getList() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { // console.log(111111111) wx.switchTab({ url: '/pages/home/home', }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })