ComplianceServer/oldcode/Core.Web/h5/mobile/js/utils.js

293 lines
8.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 获取顶部八大数据
function getDashboardData(opt) {
console.log('八大项->>>>>', opt)
let dayMap = [
{
title: '当日收款',
price: formatterPrice(opt.payprice),
},
{
title: '当日退款',
price: formatterPrice(opt.Refundprice),
},
{
title: '当日渠道消费',
price: formatterPrice(opt.DepConsume),
},
{
title: '当日实际收款',
price: formatterPrice(opt.netPayprice),
},
],
monMap = [
{
title: '当月收款',
price: formatterPrice(opt.monPayprice),
},
{
title: '当月退款',
price: formatterPrice(opt.monRefundprice),
},
{
title: '当月渠道消费',
price: formatterPrice(opt.monDepConsume),
},
{
title: '当月实际收款',
price: formatterPrice(opt.monNetPayprice),
},
],
orderMap = [
{
title: '月订单数',
num: formatterPrice(opt.monOrderNum),
},
{
title: '月退款订单数',
num: formatterPrice(opt.monRefundOrderNum),
},
{
title: '月实际收款订单数',
num: formatterPrice(opt.monNetOrderNum),
},
]
// return [dayMap.concat(monMap), orderMap]
return [monMap.concat(dayMap), orderMap]
// return { dayMap, monMap, orderMap }
console.log(dayMap, monMap, orderMap)
// opt.map((item) => {
// })
// 当日收款 当日退款 当日渠道消费 当日实际收款
// const { payprice, Refundprice, DepConsume, netPayprice } = opt
// 当月收款 当月退款 当月渠道消费 当月实际收款
// const { monPayprice, monRefundprice, monDepConsume, monNetPayprice } = opt
// '月订单数 月退款订单数 月实际收款订单数
// const { monOrderNum, monRefundOrderNum, monNetOrderNum } = opt
// 当日formatter
// ;[payprice, Refundprice, DepConsume, netPayprice].map((item) => {
// console.log('item', formatterPrice(item))
// formatterPrice(item)
// console.log(formatterPrice(item))
// })
// return
}
// 获取当天 收款明细数据
/**
* 收款金额
* 退款金额
* 实际收款金额
**/
// 获取当前节点对应的事业部
function getdeNameById(idList, treeData) {
// console.log()
// let flatList = treeToArray(treeData)
// flatList.map((item) => {
// if (idList.includes(item.itemid)) {
// console.log(item)
// // 遍历出 X 轴
// }
// })
// console.log(idList, treeData)
}
//扁平化tree
function treeToArray(tree) {
console.log(tree)
let res = []
for (const item of tree) {
const { childItemTrees, ...i } = item
if (childItemTrees && childItemTrees.length) {
res = res.concat(treeToArray(childItemTrees))
}
res.push(i)
}
return res
}
// 创建对象和遍历数据
function MapData(nowData, defaultDepData) {
//console.log('nowData->>>>>', typeof nowData)
if (typeof nowData == 'string') return
let xAxis = [], // 创建X轴 [事业部1,事业部2,....]
// 当日对象 所有
nowDayMap = {
payPriceList: [], //当日收款
RefundpriceList: [], // 当日退款
DepConsumeList: [], //当日渠道消费
netPaypriceList: [], // 当日实际收款
},
// 当月对象 所有
nowMonMap = {
monOrderNumList: [],
monPaypriceList: [],
monRefundOrderNumList: [],
monRefundpriceList: [],
monDepConsumeList: [],
monNetOrderNumList: [],
monNetPaypriceList: [],
},
nowDayTableData = [],
nowMonTableData = [],
indicators = getDashboardData(nowData.result[0])
nowData.result.map((child) => {
// console.log(child)
if (defaultDepData.length > 0 && defaultDepData.includes(child.itemId)) {
// 当日
const { item, payprice, Refundprice, DepConsume, netPayprice } = child
// 当月
const {
monOrderNum,
monPayprice,
monRefundOrderNum,
monRefundprice,
monDepConsume,
monNetOrderNum,
monNetPayprice,
} = child
xAxis.push(child.item) // 选中的事业部
// 当日数据(图)
nowDayMap.payPriceList.push(payprice)
nowDayMap.RefundpriceList.push(Refundprice)
nowDayMap.DepConsumeList.push(DepConsume)
nowDayMap.netPaypriceList.push(netPayprice)
//当日数据(表)
nowDayTableData.push({
depName: item,
payprice: payprice,
Refundprice: Refundprice,
DepConsume: DepConsume,
netPayprice: netPayprice,
})
// 当月数据(图)
nowMonMap.monOrderNumList.push(monOrderNum)
nowMonMap.monPaypriceList.push(monPayprice)
nowMonMap.monRefundOrderNumList.push(monRefundOrderNum)
nowMonMap.monRefundpriceList.push(monRefundprice)
nowMonMap.monDepConsumeList.push(monDepConsume)
nowMonMap.monNetOrderNumList.push(monNetOrderNum)
nowMonMap.monNetPaypriceList.push(monNetPayprice)
// 当月数据(表)
nowMonTableData.push({
depName: item,
monOrderNum: monOrderNum,
monPayprice: monPayprice,
monRefundOrderNum: monRefundOrderNum,
monRefundprice: monRefundprice,
monDepConsume: monDepConsume,
monNetOrderNum: monNetOrderNum,
monNetPayprice: monNetPayprice,
})
}
})
return { xAxis, nowDayMap, nowMonMap, nowDayTableData, nowMonTableData, indicators }
}
// 获取当天日期
function getCurrDate() {
var date = new Date()
var sep = '-'
var year = date.getFullYear() //获取完整的年份(4位)
var month = date.getMonth() + 1 //获取当前月份(0-11,0代表1月)
var day = date.getDate() //获取当前日
if (month <= 9) {
month = '0' + month
}
if (day <= 9) {
day = '0' + day
}
var currentdate = year + sep + month + sep + day
return currentdate
}
// 金额转化
function formatterPrice(value) {
// w 转化
var param = {}
var k = 10000,
sizes = ['', '万', '亿', '万亿'],
i
if (value < k) {
param.value = value
param.unit = ''
} else {
i = Math.floor(Math.log(value) / Math.log(k))
param.value = (value / Math.pow(k, i)).toFixed(2)
param.unit = sizes[i]
}
console.log(param)
return param
//精准转化
// let num = (value + '').indexOf('.') != -1 ? value.toFixed(2) : value
// // console.log(num)
// str = num.toString()
// var reg = str.indexOf('.') > -1 ? /\B(?=(\d{3})+\.)/g : /\B(?=(\d{3})+$)/g
// // console.log('格式化', value, str.replace(reg, ','))
// console.log(str.replace(reg, ','))
// return str.replace(reg, ',')
}
// 获取图数据
function getNowDataCharst(opt) {
console.log(opt)
if (!opt) {
return
}
const { auditItemResults } = opt
// 获取X轴income 为 0 的月份不展示,按照当前的年
let dateList = [],
xAxisData = [], // X轴显示的月份
costMap = {
// 成本占比表
costperList: [], // 成本占比列表
checkCostpriceList: [], //成本列表
modulePriceList: [], // 订单金额列表
}
auditItemResults.forEach((item) => {
let nowDate = new Date().getFullYear()
// console.log(item.mon.toString().indexOf(nowDate))
if (item.mon.toString().indexOf(nowDate) > -1 && item.income != 0) {
// console.log(item.mon.toString().slice(nowDate.toString().length))
let num = item.mon.toString().slice(nowDate.toString().length) // 月份
// console.log(num)
// 上半年默认展示 ,展示最近六个月
if (num <= 6) {
let costperItem = item.costper.substring(0, item.costper.length - 1) // 去掉 %
dateList.push(item) // 每一项
xAxisData.push(num + '月') // 拼接
costMap.costperList.push(costperItem) // 成本占比
costMap.checkCostpriceList.push(item.checkCostprice) // 成本
costMap.modulePriceList.push(item.modulePrice) //订单金额
}
}
})
return [xAxisData, costMap]
}
// Storage
const storage = {
getStroage() {
return JSON.parse(window.localStorage.getItem('depArea') || '{}')
},
setItem(key, val) {
let storage = this.getStroage()
storage[key] = val
window.localStorage.setItem('depArea', JSON.stringify(storage))
},
getItem(key) {
return this.getStroage()[key]
},
clearItem(key) {
let storage = this.getStroage()
delete storage[key]
window.localStorage.setItem('depArea', JSON.stringify(storage))
},
clearAll() {
window.localStorage.clear()
},
}