Commit 1d5683df by chenwq

时间组件

1 parent 3d384c4a
......@@ -13,6 +13,9 @@ Page({
navTitleStyle: "font-weight: 600; font- size: 34rpx; color: #282829;",
sceneFormList: constant.sceneFormList,
rankFormList: constant.rankFormList,
dateObj: {
today: new Date().format('yyyy-MM')
},
totalObj: {
purchaseMoney: 0,
totalMoney: 0
......@@ -26,6 +29,11 @@ Page({
pageNum: 1,
pageSize: 2
},
purObj: {
purchaseMoney: 0,
purchaseNum: 0
},
isShowPie: false,
purList: [],
purTotal: '-1',
purPageCof: {
......@@ -34,6 +42,66 @@ Page({
}
},
initTime() {
// 获取当前日期
const currentDate = new Date()
let today = currentDate.format('yyyy-MM-dd')
let NewYearDay = currentDate.format('yyyy')
let month = currentDate.getMonth() + 1 < 10 ? ('0' + (currentDate.getMonth() + 1)) : currentDate.getMonth() + 1
let firstDayOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).format('yyyy-MM-dd')
// console.log(NewYearDay)
this.setData({
dateObj: {
beginDateStr: firstDayOfMonth,
endDateStr: today,
today: today,
pointUnit: 2, // 1日,2月,默认日
type: 'month',
label: NewYearDay,
nowMonth: true,
timeTxt: NewYearDay + '年' + month + '月'
}
})
},
getLastDay(year, month) {
var new_year = year //取当前的年份
var new_month = month++ //取下一个月的第一天,方便计算(最后一天不固定)
if (month > 12) {
new_month -= 12 //月份减
new_year++ //年份增
}
var new_date = new Date(new_year, new_month, 1) //取当年当月中的第一天
return new Date(new_date.getTime() - 1000 * 60 * 60 * 24).getDate() //获取当月最后一天日期
},
// 获取选中天数
rangeSelect(e) {
console.log(e)
// let { date } = e.detail
let {
date
} = e.detail
let {
dateObj
} = this.data
// 按月份
dateObj = Object.assign(dateObj, date)
let [year, month] = date.end.split('-')
let day = this.getLastDay(year, month)
dateObj.beginDateStr = date.start + '-01'
dateObj.endDateStr = date.end + '-' + day
dateObj.pointUnit = 2
dateObj.type = 'month'
dateObj.nowMonth = false,
dateObj.timeTxt = year + '年' + month + '月'
this.dateObj = dateObj
this.setData({
dateObj
})
this.freshPage()
},
onInitChart(id, fnName) {
let ecComponent = this.ecComponent || this.selectComponent('#' + id)
ecComponent &&
......@@ -60,8 +128,6 @@ Page({
setBarOption(chart) {
let { diagramList } = this.data
console.log(diagramList, 'diagramList-==')
const abscissaDataList = [],
moneyTotalList = [],
stockList = []
......@@ -188,9 +254,10 @@ Page({
},
getOverview() {
let { dateObj } = this.data
const params = {
startDate: '2023-01-01',
endDate: '2023-01-31'
startDate: dateObj.beginDateStr,
endDate: dateObj.endDateStr
}
outputApi.getOverview(params).then(res => {
console.log(res)
......@@ -201,26 +268,30 @@ Page({
},
getFlowRank() {
let { dateObj } = this.data
const params = {
startDate: '2023-01-01',
endDate: '2023-01-31'
startDate: dateObj.beginDateStr,
endDate: dateObj.endDateStr,
}
outputApi.getFlowRank(params).then(res => {
let _flowRankList = res?.flowRankList || []
_flowRankList = _flowRankList.concat(new Array(3).fill({ flowCount: '', merchantName: '' })).slice(0, 3)
this.setData({
flowRankList: _flowRankList,
pieChartList: res?.pieChartList || []
pieChartList: res?.pieChartList || [],
isShowPie: !!res?.pieChartList.length
})
this.onInitChart('mychart-dom-pie', 'setPieOption')
if (res?.pieChartList.length) {
this.onInitChart('mychart-dom-pie', 'setPieOption')
}
})
},
getRankList() {
const { rankPageCof, rankList } = this.data
const { rankPageCof, rankList, dateObj } = this.data
const params = {
startDate: '2023-01-01',
endDate: '2023-01-31',
startDate: dateObj.beginDateStr,
endDate: dateObj.endDateStr,
...rankPageCof
}
outputApi.getRankList(params).then(res => {
......@@ -254,19 +325,42 @@ Page({
outputApi.getPurTendency({}).then(res => {
console.log(res, 'getPurTendency--')
this.setData({
diagramList: res?.diagramList || []
diagramList: res?.diagramList || [],
purObj: {
purchaseMoney: res.purchaseMoney || 0,
purchaseNum: res.purchaseNum || 0
}
})
this.onInitChart('mychart-dom-bar', 'setBarOption')
})
},
freshPage() {
this.setData({
totalObj: {
purchaseMoney: 0,
totalMoney: 0
},
flowRankList: [],
pieChartList: [],
rankList: [],
rankTotal: '-1',
rankPageCof: {
pageNum: 1,
pageSize: 2
}
})
this.getOverview()
this.getFlowRank()
this.getRankList()
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getOverview()
this.getFlowRank()
this.getRankList()
this.initTime()
this.freshPage()
this.getPurchaseList()
this.getPurTendency()
},
......
{
"navigationStyle": "custom",
"usingComponents": {
"ec-canvas": "../../components/ec-canvas/ec-canvas"
"ec-canvas": "../../components/ec-canvas/ec-canvas",
"CalendarMonth": "/components/CalendarMonth/CalendarMonth"
}
}
\ No newline at end of file
......@@ -41,10 +41,31 @@
margin-bottom: 24rpx;
.title {
display: flex;
justify-content: space-between;
font-weight: 600;
font-size: 28rpx;
color: #323436;
margin-bottom: 24rpx;
.title-tips {
display: flex;
font-size: 24rpx;
color: #333333;
.icon_down {
width: 40rpx;
height: 40rpx;
}
}
.title-tips.no-bold {
font-weight: 400;
}
.txt-red {
color: #F24724;
}
}
}
......@@ -255,6 +276,18 @@
.ec-canvas {
width: 675rpx;
height: 415rpx;
.no-data {
width: 100%;
text-align: center;
font-size: 24rpx;
color: #8A8C90;
.icon-empty {
width: 172rpx;
height: 172rpx;
}
}
}
.ec-canvas.bar {
......
......@@ -7,10 +7,19 @@
<glsx-image src="{{'output/background.png'}}" class="image_class" />
<view class="top-tip">本页面仅统计太阳膜业务经营数据</view>
</view>
<scroll-view class="business-analysis" id="scroller" scroll-y enable-back-to-top refresher-enabled="{{true}}" style="margin-top:calc({{statusBarHeight + navigationBarHeight + 34}}px);">
<scroll-view class="business-analysis" id="scroller" scroll-y enable-back-to-top refresher-enabled="{{false}}" style="margin-top:calc({{statusBarHeight + navigationBarHeight + 34}}px);">
<!-- 产值 -->
<view class="box">
<view class="title">精品升级-太阳膜</view>
<view class="title">
精品升级-太阳膜
<view class="title-tips">
<CalendarMonth allowSameDay shortcut bind:select="rangeSelect" rangeAll dateType="range" calenderColor="#3666FE" vertical minDate="2020-10-01" maxDate="{{ dateObj.today }}" isComponents isChangeType="{{ false }}" forceFullSucreen="{{ bottomLift>0?true:false }}" dayType="{{ 0 }}">
<!-- {{dateObj.timeTxt}} -->
{{filter.dateFormatSlash(dateObj.beginDateStr)}}-{{filter.dateFormatSlash(dateObj.endDateStr)}}
<glsx-image src="{{'output/drop_down.png'}}" class="icon_down" />
</CalendarMonth>
</view>
</view>
<view class="output">
<view wx:for="{{sceneFormList}}" wx:for-item="subItem" wx:for-index="idx" wx:key="idx" class="cur-block">
<view class="label">{{subItem.label}}</view>
......@@ -54,19 +63,27 @@
<view class="title">引流分析</view>
<view class="ec-canvas">
<!-- force-use-old-canvas="true" -->
<ec-canvas class="echart-box" id="mychart-dom-pie" canvas-id="mychart-pie" ec="{{ ec }}"></ec-canvas>
<ec-canvas wx:if="{{isShowPie}}" class="echart-box" id="mychart-dom-pie" canvas-id="mychart-pie" ec="{{ ec }}"></ec-canvas>
<view wx:else class="no-data">
<glsx-image src="{{'output/icon-empty.png'}}" class="icon-empty" />
<view>暂无数据</view>
</view>
</view>
</view>
<!-- 采购金额 -->
<view class="box">
<!-- 采购金额走势 -->
<view class="title">采购金额走势</view>
<view class="title">采购金额走势
<view class="title-tips no-bold">总采购金额<text class="txt-red">¥{{purObj.purchaseMoney}}</text></view>
</view>
<view class="ec-canvas bar">
<!-- force-use-old-canvas="true" -->
<ec-canvas class="echart-box" id="mychart-dom-bar" canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>
</view>
<!-- 采购数量 -->
<view class="title">采购数量</view>
<view class="title">采购数量
<view class="title-tips no-bold">总采购数量{{purObj.purchaseNum}}卷</view>
</view>
<view class="rank-list purchase">
<view wx:for="{{purList}}" wx:key="index" class="rank-block">
......
......@@ -53,11 +53,36 @@ var filterDate = function (n) {
return n && year + '/' + month
}
var dateFormatSlash = function (date) {
// 验证日期格式
if (!date) return;
console.log(date);
// var regex = /^\d{4}-\d{2}-\d{2}$/; 不支持正则表达式
// if (typeof date !== 'string' || !regex.test(date)) {
// console.log('Invalid date format. Expected format: "YYYY-MM-DD"');
// return
// }
// 解构赋值提取年、月和日
var parts = date.split('-');
var year = parts[0];
var month = parts[1];
var day = parts[2] || '';
// 构建日期字符串
if (day) {
return year + '/' + month + '/' + day; // 带有日的格式:YY/MM/DD
} else {
return year + '/' + month; // 只有年月的格式:YY/MM
}
}
/*
* 导出
*/
module.exports = {
setPrice: setPrice,
money_three_for_two_thousands: threeNumForTwo.money_three_for_two_thousands, //暴露接口调用
filterDate: filterDate
filterDate: filterDate,
dateFormatSlash: dateFormatSlash
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!