完成账单用电初始版本(未联调)
This commit is contained in:
77
components/timePicker/index.js
Normal file
77
components/timePicker/index.js
Normal 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 })
|
||||
}
|
||||
}
|
||||
})
|
8
components/timePicker/index.json
Normal file
8
components/timePicker/index.json
Normal 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"
|
||||
}
|
||||
}
|
44
components/timePicker/index.wxml
Normal file
44
components/timePicker/index.wxml
Normal 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>
|
1
components/timePicker/index.wxss
Normal file
1
components/timePicker/index.wxss
Normal file
@@ -0,0 +1 @@
|
||||
/* components/timePicker/index.wxss */
|
Reference in New Issue
Block a user