|
@@ -0,0 +1,80 @@
|
|
|
+const month = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
|
|
|
+ day = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'],
|
|
|
+ getTime = require("../../utils/getTime");
|
|
|
+Component({
|
|
|
+ /**
|
|
|
+ * 组件的属性列表
|
|
|
+ */
|
|
|
+ properties: {
|
|
|
+ startDate: {
|
|
|
+ type: String,
|
|
|
+ value: "2012-02-08"
|
|
|
+ },
|
|
|
+ endDate: {
|
|
|
+ type: String,
|
|
|
+ value: getTime.formatTime(new Date(), '-').split(' ')[0]
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组件的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ value: [9, 3, 3]
|
|
|
+ },
|
|
|
+ lifetimes: {
|
|
|
+ ready() {
|
|
|
+ let end = this.data.endDate.split('-')[0];
|
|
|
+ let years = [];
|
|
|
+ for (let start = this.data.startDate.split('-')[0] - 0; start <= end; start++) {
|
|
|
+ years.push(start)
|
|
|
+ };
|
|
|
+ this.setData({
|
|
|
+ years
|
|
|
+ });
|
|
|
+ this.handleChange(this.data.startDate)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 组件的方法列表
|
|
|
+ */
|
|
|
+ methods: {
|
|
|
+ handleChange(date) {
|
|
|
+ let arr = date.split('-'),
|
|
|
+ start = this.data.startDate.split('-');
|
|
|
+ let m = arr[1] - 0,
|
|
|
+ d = arr[2] - 0;
|
|
|
+ console.log(arr)
|
|
|
+ this.setData({
|
|
|
+ months: (arr[0] == start[0]) ? month.slice(start[1] - 1) : month
|
|
|
+ })
|
|
|
+ if (arr[0] == start[0]) {
|
|
|
+ this.handleDays(arr[0], m, (m == start[1] - 0) ? start[2] - 0 : 0);
|
|
|
+ } else {
|
|
|
+ this.handleDays(arr[0], m, 0);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleDays(y, m, d) {
|
|
|
+ let arr1 = [1, 3, 5, 7, 8, 10, 12];
|
|
|
+ let days = JSON.parse(JSON.stringify(day))
|
|
|
+ if (m == 2) {
|
|
|
+ days = (y % 4 == 0) ? days.slice(0, 29) : days.slice(0, 28)
|
|
|
+ } else {
|
|
|
+ (arr1.includes(m)) ? '' : days.pop();
|
|
|
+ }
|
|
|
+ console.log(days)
|
|
|
+ this.setData({
|
|
|
+ days: (d == 0) ? days : days.slice(d - 1)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ pickerChange({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ let arr = detail.value;
|
|
|
+ this.handleChange(`${this.data.years[arr[0]]}-${this.data.months[arr[1]]}-${this.data.days[arr[2]]}`)
|
|
|
+ setTimeout(() => {
|
|
|
+ console.log(`${this.data.years[arr[0]]}-${this.data.months[arr[1]]}-${this.data.days[arr[2]]}`)
|
|
|
+ }, 300)
|
|
|
+ },
|
|
|
+ }
|
|
|
+})
|