完成账单用电初始版本(未联调)

This commit is contained in:
2024-04-29 17:26:51 +08:00
parent 8d0f1931a9
commit 9c717eeb80
21 changed files with 374 additions and 32 deletions

View File

@@ -0,0 +1,77 @@
// components/timePicker/index.js
const dayjs = require("../../utils/dayjs");
function generateYearArray(startYear) {
const currentYear = new Date().getFullYear();
const years = [];
for (let i = startYear; i <= currentYear; i++) {
years.push(i);
}
return years;
}
Component({
/**
* 组件的属性列表
*/
properties: {
type: String,
value: Number,
show: Boolean,
year: String,
month: Number,
day: Number,
},
/**
* 组件的初始数据
*/
data: {
minDate: new Date(2024,0,1).getTime(),
maxDate: new Date().getTime(),
formatter(type, value) {
if (type === 'year') {
return `${value}`;
}
if (type === 'month') {
return `${value}`;
}
if (type === 'day') {
return `${value}`;
}
return value;
},
years: generateYearArray(2024)
},
/**
* 组件的方法列表
*/
methods: {
onInput(e) {
},
onClose() {
this.triggerEvent("close")
},
onCancel() {
this.triggerEvent("cancel")
},
onConfirm(e) {
const { type } = this.data;
let time;
switch(type) {
case "day":
time = dayjs(new Date(e.detail)).format('YYYY-MM-DD');
break;
case 'month':
time = dayjs(new Date(e.detail)).format('YYYY-MM');
break;
case 'year':
time = dayjs(new Date(e.detail.value, 0, 1)).format('YYYY');
break;
}
this.triggerEvent("confirm", { type, time })
}
}
})

View File

@@ -0,0 +1,8 @@
{
"component": true,
"usingComponents": {
"van-datetime-picker": "@vant/weapp/datetime-picker/index",
"van-popup": "@vant/weapp/popup/index",
"van-picker": "@vant/weapp/picker/index"
}
}

View File

@@ -0,0 +1,44 @@
<!--components/timePicker/index.wxml-->
<van-popup
show="{{ show }}"
position="bottom"
bind:close="onClose"
>
<van-datetime-picker
bind:confirm="onConfirm"
bind:cancel="onCancel"
wx:if="{{ type === 'day' }}"
type="date"
value="{{ day }}"
min-date="{{ minDate }}"
max-date="{{ maxDate }}"
bind:input="onInput"
formatter="{{formatter}}"
title="日期"
/>
<van-datetime-picker
bind:confirm="onConfirm"
bind:cancel="onCancel"
wx:if="{{ type === 'month' }}"
value="{{ month }}"
type="year-month"
value="{{ currentDate }}"
min-date="{{ minDate }}"
max-date="{{ maxDate }}"
bind:input="onInput"
formatter="{{formatter}}"
title="月份"
/>
<van-picker
bind:confirm="onConfirm"
bind:cancel="onCancel"
wx:if="{{ type === 'year' }}"
columns="{{ years }}"
bind:change="onChange"
title="年份"
show-toolbar="{{true}}"
cancel-button-text="取消"
confirm-button-text="确定"
/>
</van-popup>

View File

@@ -0,0 +1 @@
/* components/timePicker/index.wxss */