import Scene from '../../../pages/index/scene' import { getGrossReport } from "../../../api/saas" import util from '../../../utils/util' const app = getApp() Scene({ /** * 页面的初始数据 */ data: { height: app.globalData.fragmentHeight, form: {}, columns: [ { prop: 'productCategoryName', width: 200, label: '品类', color: '#55C355' }, { prop: 'receiptPrice', width: 200, label: '采购金额(元)' }, { prop: 'salesPrice', width: 200, label: '销售金额(元)' }, { prop: 'grossProfit', width: 150, label: '毛利(元)' } ], reportInfo:{ productGrossProfitReportList: [], totalGrossProfit: 0, totalSalesPrice: 0, totalReceiptPrice: 0 }, show: false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { 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 maxDate = today.getTime() var vdate = [today.getTime(), today.getTime()] var vdateString = util.formatDate(today, 'Y-M-D') this.data.form.dimensionDateStart = util.formatDate(today, 'Y-M-D') this.data.form.dimensionDateEnd = util.formatDate(today, 'Y-M-D') this.setData({ height: app.globalData.fragmentHeight - 404, minDate, maxDate, vdate, vdateString }) this.fetchStatisticsInfo() }, showCalendar: function(){ this.setData({ show: true }) }, onClose: function() { this.setData({ show: false }) }, onSelect: function({detail}) { var start = new Date(detail[0]) var end = new Date(detail[1]) var vdateString = '' if(start.getTime() == end.getTime()){ vdateString = util.formatDate(start, 'Y-M-D') } else { vdateString = util.formatDate(start, 'Y-M-D') + '至' + util.formatDate(end, 'Y-M-D') } this.data.form.dimensionDateStart = util.formatDate(start, 'Y-M-D') this.data.form.dimensionDateEnd = util.formatDate(end, 'Y-M-D') this.setData({ show: false, vdateString }) wx.showLoading({ title: '加载中', mask: true }) this.fetchStatisticsInfo() }, fetchStatisticsInfo: function(){ getGrossReport(this.data.form).then(result => { if(result.data){ this.setData({ reportInfo: result.data }) } else { this.setData({ reportInfo: { productGrossProfitReportList: [], totalGrossProfit: 0, totalSalesPrice: 0, totalReceiptPrice: 0 } }) } wx.hideLoading() }).catch(err => { wx.hideLoading() }) } })