123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 |
- const wxCharts = require('../../../utils/wxcharts.js');
- const util = require('../../../utils/util.js');
- const api = require('../../../utils/api.js');
- const app = getApp()
- let ringChart = null;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- userInfo: '',
- totalInfo: '',
- startDate: '',
- endDate: '',
- listCollege: '',
- listDept: '',
- userArray: [
- [],
- []
- ],
- value: [0, 0],
- state: '',
- type: 1,
- listTitle: '无进出记录人员',
- list: []
- },
- getCurrentDate: function(e) {
- let date = new Date();
- let year = date.getFullYear();
- let month = date.getMonth() + 1;
- let day = date.getDate();
- month = month < 10 ? "0" + month : month;
- day = day < 10 ? "0" + day : day;
- date = year + '-' + month + '-' + day
- this.setData({
- startDate: date,
- endDate: date
- })
- },
- bindStartDateChange: function(e) {
- this.setData({
- startDate: e.detail.value
- })
- this.getStatisticsInfo();
- this.qiehuan(this.data.type);
- },
- bindendDateChange: function(e) {
- this.setData({
- endDate: e.detail.value
- })
- this.getStatisticsInfo();
- this.qiehuan(this.data.type);
- },
- getCollegeInfo: function(e) {
- const that = this;
- util.httpRequest(api.getDeptInfo, {
- companyId: that.data.userInfo.companyId,
- level: 1
- }, 'post').then(res => {
- let arrayCollege = [];
- if (res.data.length >= 1) {
- for (let i = 0; i < res.data.length; i++) {
- arrayCollege.push(res.data[i].deptName)
- if (i == res.data.length - 1) {
- let userArray = that.data.userArray;
- userArray[0] = arrayCollege;
- that.setData({
- userArray: userArray,
- listCollege: res.data
- })
- that.getDeptInfo();
- }
- }
- }
- })
- },
- getDeptInfo: function(e) {
- const that = this;
- util.httpRequest(api.getDeptInfo, {
- companyId: that.data.userInfo.companyId,
- parentId: that.data.listCollege[that.data.value[0]].deptId
- }, 'post').then(res => {
- let arrayDept = [];
- if (res.data.length >= 1) {
- for (let i = 0; i < res.data.length; i++) {
- arrayDept.push(res.data[i].deptName)
- if (i == res.data.length - 1) {
- let userArray = that.data.userArray
- userArray[1] = arrayDept
- that.setData({
- userArray: userArray,
- listDept: res.data
- })
- that.getStatisticsInfo();
- that.qiehuan(that.data.type);
- }
- }
- } else {
- that.getStatisticsInfo();
- that.qiehuan(that.data.type);
- let userArray = that.data.userArray;
- userArray[1] = arrayDept
- that.setData({
- userArray: userArray,
- listDept: '',
- list: ''
- })
- }
- })
- },
- bindUserChange: function(e) {
- },
- columnChange: function(e) {
- const that = this;
- let value = that.data.value
- if (e.detail.column == 0) {
- value[1] = 0
- }
- value[e.detail.column] = e.detail.value
- that.setData({
- value: value
- })
- if (e.detail.column == 0) {
- that.setData({
- listDept: '',
- list: ''
- })
- that.getDeptInfo()
- } else if (e.detail.column == 1) {
- that.getStatisticsInfo();
- that.qiehuan(that.data.type)
- }
- },
- getChart: function(e) {
- const that = this;
- let unAccessCountP = (that.data.totalInfo.unAccessCount / that.data.totalInfo.total).toFixed(2)*100;
- let outP = (that.data.totalInfo.out / that.data.totalInfo.total).toFixed(2)*100;
- let inP = (that.data.totalInfo.in / that.data.totalInfo.total).toFixed(2)*100;
- let laterInP = (that.data.totalInfo.laterIn / that.data.totalInfo.total).toFixed(2)*100;
- let unInP = (that.data.totalInfo.unIn / that.data.totalInfo.total).toFixed(2)*100;
- let unOutP = (that.data.totalInfo.unOut / that.data.totalInfo.total).toFixed(2)*100;
- that.setData({
- 'totalInfo.unAccessCountP': unAccessCountP
- })
- if (that.data.totalInfo.total == 0) {
- ringChart = new wxCharts({
- animation: true,
- canvasId: 'ringCanvas',
- type: 'ring',
- extra: {
- ringWidth: 10,
- pie: {
- offsetAngle: -40
- }
- },
- title: {
- name: '归勤率',
- color: '#333',
- fontSize: 15
- },
- subtitle: {
- name: '100%',
- color: '#6282f4',
- fontSize: 18
- },
- series: [{
- name: '已归宿舍人员',
- data: 1,
- stroke: false,
- color: '#7792f5'
- }, ],
- disablePieStroke: true,
- width: 160,
- height: 160,
- dataLabel: false,
- legend: false,
- background: '#fff',
- padding: 0
- });
- ringChart.addEventListener('renderComplete', () => {
- console.log('renderComplete');
- });
- setTimeout(() => {
- ringChart.stopAnimation();
- }, 500);
- } else {
- ringChart = new wxCharts({
- animation: true,
- canvasId: 'ringCanvas',
- type: 'ring',
- extra: {
- ringWidth: 10,
- pie: {
- offsetAngle: -40
- }
- },
- title: {
- name: '归勤率',
- color: '#333',
- fontSize: 15
- },
- subtitle: {
- name: that.data.totalInfo.attendance * 100 + '%',
- color: '#6282f4',
- fontSize: 18
- },
- series: [{
- name: '无进出记录人员',
- data: that.data.totalInfo.unAccessCount / that.data.totalInfo.total,
- stroke: false,
- color: '#ed5c68'
- }, {
- name: '已出宿舍人员',
- data: that.data.totalInfo.out / that.data.totalInfo.total,
- stroke: false,
- color: '#f5a786'
- }, {
- name: '已归宿舍人员',
- data: that.data.totalInfo.in / that.data.totalInfo.total,
- stroke: false,
- color: '#7792f5'
- }, {
- name: '晚归宿舍人员',
- data: that.data.totalInfo.laterIn / that.data.totalInfo.total,
- stroke: false,
- color: '#79bef4'
- }, {
- name: '未归宿舍人员',
- data: that.data.totalInfo.unIn / that.data.totalInfo.total,
- stroke: false,
- color: '#5be0c1'
- }, {
- name: '未出宿舍人员',
- data: that.data.totalInfo.unOut / that.data.totalInfo.total,
- stroke: false,
- color: '#ac91f7'
- }],
- disablePieStroke: true,
- width: 160,
- height: 160,
- dataLabel: false,
- legend: false,
- background: '#fff',
- padding: 0
- });
- ringChart.addEventListener('renderComplete', () => {
- console.log('renderComplete');
- });
- setTimeout(() => {
- ringChart.stopAnimation();
- }, 500);
- }
- },
- touchHandler: function(e) {
- console.log(ringChart.getCurrentDataIndex(e));
- },
- getStatisticsInfo: function(e) {
- const that = this;
- let deptId;
- if (that.data.listDept != '') {
- deptId = that.data.listDept[that.data.value[1]].deptId
- } else {
- deptId = that.data.listCollege[that.data.value[0]].deptId
- }
- util.httpRequest(api.getStatisticsInfo, {
- start: that.data.startDate,
- end: that.data.endDate,
- deptId: deptId
- }, 'post').then(res => {
- that.setData({
- totalInfo: res.data.data
- })
- that.getChart();
- })
- },
- getUnInInfo: function(e) {
- const that = this;
- let deptId;
- if (that.data.listDept != '') {
- deptId = that.data.listDept[that.data.value[1]].deptId
- } else {
- deptId = that.data.listCollege[that.data.value[0]].deptId
- }
- util.httpRequest(api.getUnInInfo, {
- start: that.data.startDate,
- end: that.data.endDate,
- page: 1,
- rows: 20,
- deptId: deptId
- }, 'post').then(res => {
- that.setData({
- list: res.data.data.data
- })
- })
- },
- getOutAndInInfo: function(e) {
- const that = this;
- let deptId;
- if (that.data.listDept != '') {
- deptId = that.data.listDept[that.data.value[1]].deptId
- } else {
- deptId = that.data.listCollege[that.data.value[0]].deptId
- }
- util.httpRequest(api.getOutAndInInfo, {
- startDate: that.data.startDate,
- endDate: that.data.endDate,
- page: 1,
- rows: 20,
- deptId: deptId,
- state: that.data.state
- }, 'post').then(res => {
- that.setData({
- list: res.data.data.data
- })
- })
- },
- getUnOut: function(e) {
- const that = this;
- let deptId;
- if (that.data.listDept != '') {
- deptId = that.data.listDept[that.data.value[1]].deptId
- } else {
- deptId = that.data.listCollege[that.data.value[0]].deptId
- }
- util.httpRequest(api.getUnOut, {
- start: that.data.startDate,
- end: that.data.endDate,
- page: 1,
- rows: 20,
- deptId: deptId
- }, 'post').then(res => {
- that.setData({
- list: res.data.data.data
- })
- })
- },
- getLateIn: function(e) {
- const that = this;
- let deptId;
- if (that.data.listDept != '') {
- deptId = that.data.listDept[that.data.value[1]].deptId
- } else {
- deptId = that.data.listCollege[that.data.value[0]].deptId
- }
- util.httpRequest(api.getLateIn, {
- start: that.data.startDate,
- end: that.data.endDate,
- page: 1,
- rows: 20,
- deptId: deptId
- }, 'post').then(res => {
- that.setData({
- list: res.data.data.data
- })
- })
- },
- getInUnOut: function(e) {
- const that = this;
- let deptId;
- if (that.data.listDept != '') {
- deptId = that.data.listDept[that.data.value[1]].deptId
- } else {
- deptId = that.data.listCollege[that.data.value[0]].deptId
- }
- util.httpRequest(api.getInUnOunt, {
- start: that.data.startDate,
- end: that.data.endDate,
- page: 1,
- rows: 20,
- deptId: deptId
- }, 'post').then(res => {
- that.setData({
- list: res.data.data.data
- })
- })
- },
- qiehuan: function(e) {
- const that = this;
- let type = e.currentTarget ? e.currentTarget.dataset.type : e;
- let state = e.currentTarget ? e.currentTarget.dataset.state : that.data.state;
- if (type == 1) {
- that.setData({
- listTitle: '无进出记录人员',
- type: 1
- })
- that.getUnOut();
- } else if (type == 2) {
- that.setData({
- listTitle: '已出宿舍人员',
- type: 2,
- state: state
- })
- that.getOutAndInInfo();
- } else if (type == 3) {
- that.setData({
- listTitle: '已归宿舍人员',
- type: 3,
- state: state
- })
- that.getOutAndInInfo();
- } else if (type == 4) {
- that.setData({
- listTitle: '晚归宿舍人员',
- type: 4
- })
- that.getLateIn();
- } else if (type == 5) {
- that.setData({
- listTitle: '未归宿舍人员',
- type: 5
- })
- that.getUnInInfo();
- } else if (type == 6) {
- that.setData({
- listTitle: '未出宿舍人员',
- type: 6
- })
- that.getInUnOut();
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- const that = this;
- that.getCurrentDate();
- that.data.userInfo = wx.getStorageSync('user');
- that.getCollegeInfo();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- }
- })
|