纸通宝SAAS仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

225 lines
7.5 KiB

// xtends//statics/index/index.js
import Scene from '../../../pages/index/scene'
import uCharts from '../../libs/u-charts';
import { getReceiptReport, getSalesReport } from "../../../api/saas"
const math = require('../../../utils/math')
import util from '../../../utils/util'
const app = getApp()
// var that;
// var canvaColumn = null;
// var windowWidth = 0;
Scene({
/**
* 页面的初始数据
*/
data: {
// cWidth: '',
// cHeight: '',
form1: {},
form2: {},
percent: 50,
show: false,
selectId: '',
reportInfo:{
totalOffsiteSettleWeight: 0,
totalOnsideSettleWeight: 0,
totalSettlePrice: 0,
totalSettleWeight: 0
},
saleReportInfo:{
carNumber: 0,
totalOutboundDeliveryNetWeight: 0,
totalSettlePrice: 0,
totalSettleWeight: 0
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// that = this
// windowWidth = wx.getSystemInfoSync().windowWidth
// this.data.cWidth = windowWidth - this.rpx2px(100)
// // math.divide
// this.data.cHeight = this.rpx2px(400)
// this.getServerData()
wx.showLoading({ title: '加载中', mask: true })
var min = new Date()
min.setFullYear(min.getFullYear() - 1, min.getMonth(), min.getDate())
min.setHours(0, 0, 0)
var minDate = min.getTime()
var today = new Date()
today.setHours(0, 0, 0)
var vdate = [today.getTime(), today.getTime()]
var vdateString = util.formatDate(new Date(), 'Y-M-D')
this.data.form1.dimensionDateStart = util.formatDate(today, 'Y-M-D')
this.data.form1.dimensionDateEnd = util.formatDate(today, 'Y-M-D')
this.data.form2.dimensionDateStart = util.formatDate(today, 'Y-M-D')
this.data.form2.dimensionDateEnd = util.formatDate(today, 'Y-M-D')
this.setData({ minDate, maxDate: today.getTime(), vdate, vdateString1: vdateString, vdateString2: vdateString })
this.fetchSummaryInfo(false)
this.fetchStatisticsInfo(true)
},
showCalendar: function(e){
this.data.selectId = e.currentTarget.id
var datetime = ''
if(this.data.selectId == 'form1') {
datetime = this.data.form1.dimensionDateStart + ' 00:00:00'
var start = new Date(datetime.replace(/-/g,'/'))
datetime = this.data.form1.dimensionDateEnd + ' 00:00:00'
var end = new Date(datetime.replace(/-/g,'/'))
this.data.vdate = [start.getTime(), end.getTime()]
} else {
datetime = this.data.form2.dimensionDateStart + ' 00:00:00'
var start = new Date(datetime.replace(/-/g,'/'))
datetime = this.data.form2.dimensionDateEnd + ' 00:00:00'
var end = new Date(datetime.replace(/-/g,'/'))
this.data.vdate = [start.getTime(), end.getTime()]
}
this.setData({ show: true, vdate: this.data.vdate })
},
onClose: function() {
this.setData({ show: false })
},
getDateString: function(start, end){
var vdateString1 = ''
if(start.getTime() == end.getTime()){
vdateString1 = util.formatDate(start, 'Y-M-D')
} else {
vdateString1 = util.formatDate(start, 'Y-M-D') + '至' + util.formatDate(end, 'Y-M-D')
}
return vdateString1
},
onSelect: function({detail}) {
var start = new Date(detail[0])
var end = new Date(detail[1])
wx.showLoading({ title: '加载中', mask: true })
if(this.data.selectId == 'form1') {
this.data.form1.dimensionDateStart = util.formatDate(start, 'Y-M-D')
this.data.form1.dimensionDateEnd = util.formatDate(end, 'Y-M-D')
this.setData({ show: false, vdateString1: this.getDateString(start, end) })
this.fetchSummaryInfo(true)
} else {
this.data.form2.dimensionDateStart = util.formatDate(start, 'Y-M-D')
this.data.form2.dimensionDateEnd = util.formatDate(end, 'Y-M-D')
this.setData({ show: false, vdateString2: this.getDateString(start, end) })
this.fetchStatisticsInfo(true)
}
},
fetchSummaryInfo: function(hide){
getReceiptReport(this.data.form1).then(result => {
if(result.data){
if(result.data.totalOffsiteSettleWeight > 0 && result.data.totalOnsideSettleWeight > 0){
var totalWeight = math.plus(result.data.totalOffsiteSettleWeight, result.data.totalOnsideSettleWeight)
this.data.percent = parseInt(math.times(math.divide(result.data.totalOffsiteSettleWeight, totalWeight), 100))
} else if(result.data.totalOffsiteSettleWeight > 0){
this.data.percent = 100
} else if(result.data.totalOnsideSettleWeight > 0){
this.data.percent = 0
} else {
this.data.percent = 50
}
this.setData({ reportInfo: result.data, percent: this.data.percent })
} else {
this.setData({ reportInfo: { totalOffsiteSettleWeight: 0, totalOnsideSettleWeight: 0, totalSettlePrice: 0, totalSettleWeight: 0 }, percent: 50 })
}
if(hide){
wx.hideLoading()
}
}).catch(err => {
if(hide){
wx.hideLoading()
}
})
},
fetchStatisticsInfo: function(hide){
getSalesReport(this.data.form2).then(result => {
if(result.data){
this.setData({ saleReportInfo: result.data })
} else {
this.setData({ saleReportInfo: { carNumber: 0, totalOutboundDeliveryNetWeight: 0, totalSettlePrice: 0, totalSettleWeight: 0 } })
}
if(hide){
wx.hideLoading()
}
}).catch(err => {
if(hide){
wx.hideLoading()
}
})
}
// rpx2px: function(rpx) {
// return rpx / 750 * windowWidth;
// },
// getServerData: function() {
// wx.request({
// url: 'https://www.ucharts.cn/data.json',
// success: function (res) {
// let Column = { categories: [], series: [] };
// Column.categories = res.data.data.Pie.categories;
// Column.series = res.data.data.Pie.series;
// // 自定义标签颜色和字体大小
// // Column.series[1].textColor = 'red';
// // Column.series[1].textSize = 18;
// that.showColumn("canvasColumn", Column);
// },
// fail: () => {
// console.log("请点击右上角【详情】,启用不校验合法域名");
// },
// })
// },
// showColumn(canvasId, chartData) {
// let ctx = wx.createCanvasContext(canvasId, this);
// canvaColumn = new uCharts({
// type: 'ring',
// context: ctx,
// // fontSize: 11,
// background: '#FFFFFF',
// pixelRatio: 1,
// // animation: true,
// // categories: chartData.categories,
// series: chartData.series,
// color: [ "#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc" ],
// dataLabel: true,
// width: that.data.cWidth,
// height: that.data.cHeight,
// legend: {
// show: false,
// position: "right",
// float: "center",
// padding: 5,
// margin: 5,
// fontSize: 13,
// fontColor: "#666666",
// lineHeight: 25,
// hiddenColor: "#CECECE",
// itemGap: 10
// },
// extra: {
// ring: {
// ringWidth: 30,
// centerColor: "#FFFFFF",
// activeOpacity: 0.5,
// activeRadius: 10,
// offsetAngle: 0,
// customRadius: 0,
// labelWidth: 15,
// border: true,
// borderWidth: 3,
// borderColor: "#FFFFFF",
// linearType: "none"
// }
// }
// });
// },
// touchColumn(e) {
// canvaColumn.showToolTip(e, {
// formatter: function (item) {
// console.log(item)
// return item.name + ':' + item.data
// }
// })
// }
})