|
|
import { FetchInitBorrowerNumStatistics, FetchInitArchivesTypeNum, FetchInitArchivesTypeStatistics, FetchStorageStatistics, FetchInitArchivesSearchRanking, FetchInitAddArchivesStatistics } from '@/api/archivesManage/statistics'// import qs from 'qs'
export const statisticsCrud = { // 组件共用属性
data() { return { cateDate: '', typeDate: '', inOutStorageDate: '', arcSearchDate: '', arcAddDate: '', pickerOptions: { disabledDate(time) { return time.getTime() > Date.now() - 8.64e6 } }, lendData: [], cateData: [], typeData: [], storageData: { storageMonths: [], inStorageData: [], outStorageData: [] }, searchAcrivesData: { searchName: [], searchValue: [] }, addArcivesData: { addArcivesMonth: [], addArcivesNum: [] }, numTop: '10', options: [{ value: '10', label: '10' }, { value: '20', label: '20' }, { value: '30', label: '30' }, { value: '40', label: '40' }, { value: '50', label: '50' }] } }, // 组件挂载时的共用方法
mounted() { this.getBorrowerNumSta() this.getArchivesTypeNum() this.getArchivesTypeStatistics() this.getStorageStatistics() this.getArchivesSearchRanking() this.getAddArchivesStatistics() }, // 组件共用方法
methods: { // 档案借阅统计
// getBorrowerNumSta() {
// FetchInitBorrowerNumStatistics().then(res => {
// if (res) {
// delete res.total
// // 固定排序 '在库档案', '已借档案', '待借档案', '逾期档案', '异常档案'
// const borrowerArr = []
// for (const i in res) {
// const obj = {}
// obj.name = i
// obj.value = res[i]
// if (i === 'inStorage') {
// obj.sequence = 1
// } else if (i === 'borrow') {
// obj.sequence = 2
// } else if (i === 'waitBorrow') {
// obj.sequence = 3
// } else if (i === 'overdue') {
// obj.sequence = 4
// } else if (i === 'abnormal') {
// obj.sequence = 5
// }
// borrowerArr.push(obj)
// }
// this.arrSortByKey(borrowerArr, 'sequence', false)
// borrowerArr.forEach(item => {
// this.lendData.push(item.value)
// console.log(this.lendData)
// })
// }
// })
// },
getBorrowerNumSta() { FetchInitBorrowerNumStatistics().then(res => { if (res) { delete res.total // 新的固定排序: '逾期档案', '已借档案', '在库档案'
const borrowerArr = [] for (const i in res) { const obj = {} obj.name = i obj.value = res[i] // 重新定义排序序号
if (i === 'overdue') { // 逾期档案 - 第1位
obj.sequence = 1 } else if (i === 'borrow') { // 已借档案 - 第2位
obj.sequence = 2 } else if (i === 'inStorage') { // 在库档案 - 第3位
obj.sequence = 3 } // 只添加需要的三类数据,过滤掉待借、异常档案
if (obj.sequence) { borrowerArr.push(obj) } } // 按sequence排序
this.arrSortByKey(borrowerArr, 'sequence', true) // 清空原有数据(避免多次调用累加)
this.lendData = [] borrowerArr.forEach(item => { this.lendData.push(item.value) }) } }) }, // 档案类别 - 年选择
handleCateDate() { this.cateData = [] this.getArchivesTypeNum() }, // 档案类别
getArchivesTypeNum() { let params if (this.cateDate) { params = { 'year': this.cateDate } } else { params = { 'year': null } } FetchInitArchivesTypeNum(params).then(res => { if (res) { for (const i in res) { this.cateData.push(res[i]) } } }) }, // 档案类型 - 月选择
handleTypeDate() { this.typeData = [] this.getArchivesTypeStatistics() }, // 档案类型
getArchivesTypeStatistics() { let params if (this.typeDate) { params = { 'yearMonth': this.typeDate } } else { params = { 'yearMonth': null } } FetchInitArchivesTypeStatistics(params).then(res => { if (res) { res.map(item => { const obj = {} obj.name = item.archivesType obj.value = item.archivesNum this.typeData.push(obj) }) } }) }, // 档案类别 - 年选择
handleStorageDate() { this.getStorageStatistics() }, // 出入库管理情况
getStorageStatistics() { let params let getYear if (this.inOutStorageDate) { params = { 'year': this.inOutStorageDate } getYear = this.inOutStorageDate } else { params = { 'year': null } getYear = new Date().getFullYear() } FetchStorageStatistics(params).then(res => { if (res) { this.storageData.storageMonths = [] res.months.forEach(item => { this.storageData.storageMonths.push(getYear + '/' + item) }) this.storageData.inStorageData = res.inStorage this.storageData.outStorageData = res.outStorage } }) }, handleSearchDate() { this.getArchivesSearchRanking() }, selectNumTop(val) { this.numTop = val this.searchAcrivesData = { searchName: [], searchValue: [] } this.getArchivesSearchRanking() }, // 档案检索排名
getArchivesSearchRanking() { let params if (this.arcSearchDate) { params = { 'yearMonth': this.arcSearchDate, 'top': this.numTop } } else { params = { 'yearMonth': null, 'top': this.numTop } } FetchInitArchivesSearchRanking(params).then(res => { if (res) { this.arrSortByKey(res, 'num', true) this.searchAcrivesData.searchName = res.map(item => item.cnName) this.searchAcrivesData.searchValue = res.map(item => item.num) } }) }, handleArcAddSta() { this.getAddArchivesStatistics() }, // 档案实际情况
getAddArchivesStatistics() { let params let getYear if (this.arcAddDate) { params = { 'year': this.arcAddDate } getYear = this.arcAddDate } else { params = { 'year': null } getYear = new Date().getFullYear() } FetchInitAddArchivesStatistics(params).then(res => { if (res) { this.addArcivesData.addArcivesMonth = [] res.months.forEach(item => { this.addArcivesData.addArcivesMonth.push(getYear + '/' + item) }) this.addArcivesData.addArcivesNum = res.nums } }) }, // array: 需要进行排序的数组
// key: 根据某个属性进行排序
// order: 升序/降序 true:升序 false:降序
arrSortByKey(array, property, order) { return array.sort(function(a, b) { const value1 = a[property] const value2 = b[property] if (order) { // 升序
return value1 - value2 } else { // 降序
return value2 - value1 } }) } }}
|