// pages/module_ledger/ledgerhome/ledgerhome.js
|
const ledgerservice = require("../../../service/ledgerservice")
|
const moment = require('../../../utils/moment.min')
|
const app = getApp()
|
|
Page({
|
|
/**
|
* 页面的初始数据
|
*/
|
data: {
|
thisMonth: '',
|
lastMonth: '',
|
|
//提交期限
|
deadline: '',
|
//剩余提交天数
|
leftday: 0,
|
|
//本月汇总
|
thisMonthInfo: {
|
//必填项总数
|
totalMust: 0,
|
//必填项提交数
|
finishedMust: 0,
|
//选填项总数
|
totalSelect: 0,
|
//选填项提交数
|
finishedSelect: 0,
|
//提交情况
|
status: '',
|
//超时情况
|
overtime: '',
|
//建议
|
suggestion: ''
|
},
|
//上月汇总
|
lastMonthInfo: {
|
totalMust: 0,
|
finishedMust: 0,
|
totalSelect: 0,
|
finishedSelect: 0,
|
status: '',
|
overtime: '',
|
suggestion: ''
|
},
|
|
//选项卡相关
|
currentTab: 0,
|
tabList: [],
|
pageList: [],
|
pageheight: '300px',
|
|
//当前显示月份
|
showThisMonth: true,
|
},
|
|
//每月台账提交期限日
|
DEADLINEDAY: 10,
|
|
/**
|
* 生命周期函数--监听页面加载
|
*/
|
onLoad(options) {
|
let now = moment()
|
let deadline = now.format(`MM-${this.DEADLINEDAY}`)
|
let leftday = this.DEADLINEDAY + 1 - now.date()
|
let thisMonth = now.format('YYYY-MM')
|
let lastMonth = now.add(-1, 'M').format('YYYY-MM')
|
this.setData({
|
deadline,
|
leftday,
|
thisMonth,
|
lastMonth
|
})
|
|
now = moment()
|
this.getLedgerType(now.format('YYYY-MM-DD'), r => {
|
this.setData({
|
tabList: r[0],
|
pageList: r[1],
|
thisMonthInfo: r[2]
|
})
|
}) //本月
|
this.getLedgerType(now.add(-1, 'M').format('YYYY-MM-DD'), r => {
|
this.setData({
|
lastMonthInfo: r[2]
|
})
|
}, true) //上月
|
},
|
|
/**
|
* 生命周期函数--监听页面初次渲染完成
|
*/
|
onReady() {
|
|
},
|
|
/**
|
* 生命周期函数--监听页面显示
|
*/
|
onShow() {
|
|
},
|
|
getLedgerType(time, success, lastMonth) {
|
var that = this
|
// var time = moment().format('YYYY-MM-DD')
|
ledgerservice.getLedgerSummary(app.globalData.accessToken.userId, app.globalData.userInfo.extension2, time, {
|
success(res) {
|
let r = that.parseLedgerType(res, lastMonth)
|
success(r)
|
}
|
})
|
},
|
|
parseLedgerType(subtypes, lastMonth) {
|
let monthInfo = {
|
totalMust: 0,
|
finishedMust: 0,
|
totalSelect: 0,
|
finishedSelect: 0,
|
status: '',
|
overtime: '',
|
suggestion: ''
|
}
|
let map = new Map()
|
subtypes.forEach(s => {
|
//月度统计
|
if (s.needUpdate) {
|
monthInfo.totalMust++
|
if (s.upLoad) {
|
monthInfo.finishedMust++
|
}
|
} else {
|
monthInfo.totalSelect++
|
if (s.upLoad) {
|
monthInfo.finishedSelect++
|
}
|
}
|
|
//选项卡
|
if (s.upLoad) {
|
s.tag = '/res/icons/round_check_fill.png'
|
} else if (s.ledgerFinished) {
|
s.tag = '/res/icons/warning_yellow.png'
|
} else if (!s.needUpdate) {
|
s.tag = '/res/icons/round_check_fill.png'
|
} else {
|
s.tag = '/res/icons/warning_red.png'
|
}
|
if (!map.has(s.ledgerType)) {
|
map.set(s.ledgerType, [])
|
}
|
map.get(s.ledgerType).push(s)
|
});
|
|
//
|
if (monthInfo.finishedMust == 0) {
|
monthInfo.status = '未提交'
|
if (lastMonth) {
|
monthInfo.suggestion = '当期台账完全未提交,严重影响评估结果,后续请注意'
|
} else {
|
monthInfo.suggestion = '请尽快提交台账'
|
}
|
} else if (monthInfo.finishedMust < monthInfo.totalMust) {
|
monthInfo.status = '部分提交'
|
if (lastMonth) {
|
monthInfo.suggestion = '当期台账部分未提交,会影响评估结果,后续请尽量提交所有台账'
|
} else {
|
monthInfo.suggestion = '当前已提交部分台账,请补全剩余台账'
|
}
|
} else {
|
monthInfo.status = '已提交'
|
if (lastMonth) {
|
monthInfo.suggestion = '当期台账已全部提交,请保持'
|
} else {
|
monthInfo.suggestion = '本期台账已全部提交'
|
}
|
}
|
monthInfo.overtime = moment().date() - this.DEADLINEDAY
|
monthInfo.percent = Math.round(monthInfo.finishedMust / monthInfo.totalMust * 100)
|
|
console.log(lastMonth);
|
console.log(monthInfo);
|
|
//选项卡
|
var t = []
|
var p = []
|
for (let item of map) {
|
console.log(item);
|
let notUpload = 0
|
item[1].forEach(l => {
|
if (l.needUpdate && !l.upLoad) {
|
notUpload++
|
}
|
});
|
t.push({
|
name: item[0],
|
tag: notUpload,
|
total: item[1].length
|
})
|
p.push(item[1])
|
}
|
|
return [t, p, monthInfo]
|
},
|
|
gotoLedgerDetail(e) {
|
var i = e.currentTarget.dataset.index.split(',')
|
var indexGroup = [parseInt(i[0]), parseInt(i[1])]
|
var ledger = this.data.pageList[indexGroup[0]][indexGroup[1]]
|
console.log(ledger);
|
|
var that = this
|
wx.navigateTo({
|
url: '/pages/module_ledger/ledgerupload/ledgerupload',
|
events: {
|
uploadOver: function (data) {
|
let i = data.indexGroup
|
let pageList = that.data.pageList
|
pageList[i[0]][i[1]].upLoad = true
|
pageList[i[0]][i[1]].tag = '/res/icons/round_check_fill.png'
|
that.setData({
|
pageList
|
})
|
}
|
},
|
success: (res) => {
|
// 通过 eventChannel 向被打开页面传送数据
|
res.eventChannel.emit('acceptDataFromOpenerPage', {
|
ledger: ledger,
|
indexGroup: indexGroup
|
})
|
},
|
})
|
},
|
|
gotoHistory(){
|
let tabList = this.data.tabList
|
wx.navigateTo({
|
url: '/pages/module_ledger/ledgerhistory/ledgerhistory',
|
success: (res) => {
|
// 通过 eventChannel 向被打开页面传送数据
|
res.eventChannel.emit('acceptDataFromOpenerPage', {
|
tabList: tabList,
|
})
|
},
|
})
|
},
|
|
|
//计算swiper高度方法(在切换的时候调用)
|
tabsHeight(element) {
|
let that = this;
|
let query = wx.createSelectorQuery(); //必须要先创建一个查询
|
query.select(element).boundingClientRect(function (rect) {
|
console.log(rect.height);
|
let pageheight = that.data.pageheight.split('px')[0]
|
pageheight = parseInt(pageheight)
|
if (rect.height > pageheight) {
|
that.setData({
|
pageheight: rect.height + 'px'
|
});
|
}
|
}).exec();
|
},
|
swichNav: function (e) {
|
var that = this;
|
if (this.data.currentTab === e.target.dataset.current) {
|
return false;
|
} else {
|
that.setData({
|
currentTab: e.target.dataset.current,
|
navScrollLeft: e.target.dataset.current >= 3 ? ((e.target.dataset.current) * 60) : 0 //判断当前选中的个数是否是第5个
|
})
|
// that.tabsHeight('.page' + e.target.dataset.current); //查询哪一个元素
|
}
|
},
|
bindChange: function (e) {
|
var that = this;
|
that.setData({
|
currentTab: e.detail.current,
|
navScrollLeft: e.detail.current >= 3 ? ((e.detail.current) * 60) : 0 //判断当前选中的个数是否是第5个
|
});
|
that.tabsHeight('.page' + e.detail.current); //查询哪一个元素
|
},
|
|
changeMonth(){
|
let showThisMonth = !this.data.showThisMonth
|
this.setData({showThisMonth})
|
}
|
})
|