form-field-datetime.js
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const {
buildDatetimePickerState,
clampDateTimeToNow,
resolveNotAfterNow
} = require('../../form-engine/datetime-picker-mode.js')
const {
buildUpgradeIconUrl,
FORM_FIELD_ARROW_ICON
} = require('../../utils/upgrade-icon-url.js')
Component({
properties: {
field: { type: Object, value: {} },
value: { type: null },
disabled: { type: Boolean, value: false },
error: { type: String, value: '' },
groupKey: { type: String, value: '' },
rowIndex: { type: Number, value: -1 }
},
data: {
useMinutePicker: false,
displayLabel: '',
maxDateKind: '',
minutePickerVisible: false,
pickerMode: 'date',
pickerValue: '',
dateStart: '',
endDate: '',
arrowIconUrl: ''
},
lifetimes: {
attached() {
this.setData({
arrowIconUrl: buildUpgradeIconUrl(FORM_FIELD_ARROW_ICON)
})
}
},
observers: {
'field, value': function (field, value) {
this.setData(buildDatetimePickerState(field, value))
}
},
methods: {
buildChangeDetail(nextValue) {
const detail = { key: this.data.field.key, value: nextValue }
if (this.properties.groupKey) {
detail.groupKey = this.properties.groupKey
const rowIndex = Number(this.properties.rowIndex)
if (!Number.isNaN(rowIndex) && rowIndex >= 0) {
detail.rowIndex = rowIndex
}
}
return detail
},
emitMergedValue(nextValue) {
const field = this.properties.field
const state = buildDatetimePickerState(field, nextValue)
this.setData({
...state,
minutePickerVisible: false
})
this.triggerEvent('change', this.buildChangeDetail(nextValue))
},
onChange(e) {
if (this.properties.disabled) return
// 确认选日期后写入标量(自然清除 partialFromPlanImport 豁免)
const nextValue = e.detail.value
this.setData({
displayLabel: nextValue,
pickerValue: nextValue
})
this.triggerEvent('change', this.buildChangeDetail(nextValue))
},
normalizeMergedValue(merged) {
const field = this.properties.field
if (resolveNotAfterNow(field)) {
return clampDateTimeToNow(merged)
}
return merged
},
onOpenMinutePicker() {
if (this.properties.disabled) return
this.setData({ minutePickerVisible: true })
},
onMinutePickerConfirm(e) {
if (this.properties.disabled) return
const merged = this.normalizeMergedValue(e.detail?.value || '')
this.emitMergedValue(merged)
},
onMinutePickerCancel() {
this.setData({ minutePickerVisible: false })
}
}
})