From 4dd1014eccdc14b1674f2b232b80e4a1635e37e4 Mon Sep 17 00:00:00 2001 From: "liujw155@outlook.com" Date: Sun, 27 Sep 2020 19:06:20 +0800 Subject: [PATCH] fix & add calendar --- src/pages/collection/record/record.vue | 6 +- src/pages/time_select/date/date.vue | 54 +++++++------- src/pages/time_select/month/month.vue | 124 +++++++++++++++++++++++++++++++-- src/pages/time_select/year/year.vue | 62 +++++++++++++++-- src/pages/turnover/turnover.vue | 56 +++++---------- 5 files changed, 222 insertions(+), 80 deletions(-) diff --git a/src/pages/collection/record/record.vue b/src/pages/collection/record/record.vue index a224e16..2398f82 100644 --- a/src/pages/collection/record/record.vue +++ b/src/pages/collection/record/record.vue @@ -25,7 +25,7 @@ {{formatDate(e.date || '') }} - ¥{{e.sum || 0}} + ¥{{numeral(e.sum || 0).format('0.00')}} 当日无交易 收款{{e.in_count || 0}}笔(¥{{e.in_sum || 0}}),退款{{e.out_count || 0}}笔(¥{{e.out_sum || 0}}) @@ -41,6 +41,7 @@ import { API } from '../../../js/api' import { servers } from '../../../js/server' import util from '../../../utils/util' import { mapState } from 'vuex'; +import numeral from 'numeral'; export default { computed: { ...mapState(['brandInfo']), @@ -56,6 +57,9 @@ export default { if(util.isSameDay(new Date().getTime(), new Date(date.replace(/\-/g,'/')).getTime()))return '今天' return util.formatDate({ date: date, partition: 'zh' }).substr(5) } + }, + numeral(){ + return numeral } }, data(){ diff --git a/src/pages/time_select/date/date.vue b/src/pages/time_select/date/date.vue index 885370f..f4dcf63 100644 --- a/src/pages/time_select/date/date.vue +++ b/src/pages/time_select/date/date.vue @@ -12,8 +12,8 @@ {{e.showMonth}} - - {{item.showDate}} + + {{item.showDate}} ¥{{item.money}} @@ -33,15 +33,19 @@ import util from '../../../utils/util' export default { data(){ return { - recordInfo: {}, - calendarData: [], - curDay: '' + // calendarData: [], + curDay: '', + serverRecord: [], } }, computed: { - isSameDay(){ + isSameDay(){ // 判断选中 let { curDay } = this; - return (date='')=>util.isSameDay(new Date(curDay.replace(/\-/,'/')).getTime(),new Date(date.replace(/\-/,'/')).getTime()) + return (date='')=>util.isSameDay(new Date(curDay.replace(/\-/g,'/')).getTime(),new Date(date.replace(/\-/g,'/')).getTime()); + }, + calendarData(){ + let { serverRecord } = this; + return this.getMonthArr(serverRecord) || []; } }, onLoad(options){ @@ -50,18 +54,15 @@ export default { // this.getDateArr({}); }, methods: { - timeChange(time){ + timeChange(e){ + if(e.isUnStart)return; util.previousPageFunction({ fnName: 'timeChange', - query: { - detail: { - value: time - } - } + query: e.defineDate }); util.routeTo(); }, - getMonthArr(serverArr){ + getMonthArr(serverArr = []){ const TOTAL_MONTH = 6; // 需要加载月份数量 let dateObj = new Date(); let _curYear = dateObj.getFullYear(); @@ -80,26 +81,21 @@ export default { return _calendarData || []; // this.calendarData = _calendarData; }, - getCalendar({ - curYear, - monthArr, - }){ - return monthArr.map((e,i)=>{ - - }) - }, + // 计算日历列表 getDateArr({ year = 2020, month = 9, serverArr = [], }){ let _dateAmount = new Date(year, month, 0).getDate(); // 当月天总数 - + let _toDay = new Date(); let _dateArr = new Array(_dateAmount).fill(1).map((e,i)=>{ + let _date = `${year}/${util.formatNumber(month)}/${util.formatNumber(i+1)}` let _obj = { - defineDate: `${year}-${util.formatNumber(month)}-${util.formatNumber(i+1)}`, + defineDate: _date.replace(/\//g, '-'), showDate: util.formatNumber(i+1), - money: 0 + money: 0, + isUnStart: _toDay.getTime() < new Date(_date).getTime() } try{ // 后台金额赋值显示 @@ -116,6 +112,7 @@ export default { return _dateArr }, + // 获取后端数据记录 getRecord(){ util.showLoad(); servers.get({ @@ -124,8 +121,8 @@ export default { failMsg: '加载失败!', }) .then(e=>{ - this.recordInfo = e; - this.calendarData = this.getMonthArr(e || []); + this.serverRecord = e; + // this.calendarData = this.getMonthArr(e || []); this.$nextTick(util.hideLoad); }) .catch(util.hideLoad); @@ -214,6 +211,9 @@ export default { color: #9c9c9f; } } + .unstart-active{ + opacity: .14; + } } .active{ background-color: #f2f2f7; diff --git a/src/pages/time_select/month/month.vue b/src/pages/time_select/month/month.vue index 6aa7859..24c9e9c 100644 --- a/src/pages/time_select/month/month.vue +++ b/src/pages/time_select/month/month.vue @@ -2,15 +2,17 @@ 仅保留最近3年日报数据 - + - 2019年 + {{e.year}}年 - - - 9月 - ¥0.00 + + + {{item.showMonth}} + + ¥{{item.money || '0.00'}} + @@ -20,8 +22,112 @@ @@ -91,11 +197,15 @@ export default { color: #1a1a1a; } &+view{ - font-size: 20upx; line-height: 28upx; + height: 28upx; + font-size: 20upx; color: #9c9c9f; } } + .un-active{ + opacity: .14; + } } .active{ background-color: #f2f2f7; diff --git a/src/pages/time_select/year/year.vue b/src/pages/time_select/year/year.vue index 4eb0e0d..2b2984c 100644 --- a/src/pages/time_select/year/year.vue +++ b/src/pages/time_select/year/year.vue @@ -2,18 +2,70 @@ 仅保留最近10年日报数据 - - - 2018年 - ¥1000000000000000000.00 + + + {{e.year || '-'}}年 + ¥{{e.money || '0.00'}}