You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
4.8 KiB
151 lines
4.8 KiB
Component({
|
|
properties: {
|
|
show: {
|
|
type: Boolean,
|
|
value: false
|
|
},
|
|
title: {
|
|
type: String,
|
|
value: ' '
|
|
},
|
|
formController: {
|
|
type: Object,
|
|
value: () => {
|
|
},
|
|
observer(val) {
|
|
this.setData({
|
|
formControllers: val
|
|
})
|
|
}
|
|
},
|
|
},
|
|
data: {
|
|
showDate: false,
|
|
dateKey: "",
|
|
defaultDate: "",
|
|
dateIndex: "",
|
|
formControllers: {},
|
|
showCheckbox: false,
|
|
checkboxTitle: '',
|
|
checkboxResult: [],
|
|
checkboxOptions: [],
|
|
checkboxIndex: ''
|
|
},
|
|
methods: {
|
|
onClose() {
|
|
this.triggerEvent('close')
|
|
},
|
|
onCloseCheckbox() {
|
|
this.setData({
|
|
showCheckbox: false
|
|
})
|
|
},
|
|
sureCheckbox() {
|
|
let formControllers = this.data.formControllers;
|
|
let checkboxResult = this.data.checkboxResult
|
|
let label = []
|
|
formControllers[this.data.checkboxIndex].value = checkboxResult.join(',');
|
|
checkboxResult.forEach(item => {
|
|
formControllers[this.data.checkboxIndex].options.forEach(option => {
|
|
if (option.value == item) {
|
|
label.push(option.label)
|
|
}
|
|
})
|
|
})
|
|
formControllers[this.data.checkboxIndex].selected = label.join(',');
|
|
this.setData({
|
|
formControllers,
|
|
showCheckbox: false
|
|
})
|
|
},
|
|
toggle(event) {
|
|
console.log(event)
|
|
const {index} = event.currentTarget.dataset;
|
|
const checkbox = this.selectComponent(`.checkboxes-${index}`);
|
|
console.log(checkbox)
|
|
checkbox.toggle();
|
|
},
|
|
onChangeCheckbox(event) {
|
|
this.setData({
|
|
checkboxResult: event.detail,
|
|
});
|
|
},
|
|
onShowCheckbox(e) {
|
|
let {options, value, label, index} = e.currentTarget.dataset
|
|
this.setData({
|
|
showCheckbox: true,
|
|
checkboxTitle: '选择' + label,
|
|
checkboxResult: value.split(','),
|
|
checkboxOptions: options,
|
|
checkboxIndex: index
|
|
})
|
|
},
|
|
onShowDate(e) {
|
|
let {key, value, index} = e.currentTarget.dataset
|
|
console.log(e.currentTarget.dataset)
|
|
this.setData({
|
|
showDate: true,
|
|
dateKey: key,
|
|
defaultDate: value,
|
|
dateIndex: index
|
|
})
|
|
},
|
|
onCloseDate(e) {
|
|
this.setData({
|
|
showDate: false
|
|
})
|
|
},
|
|
formatDate(date) {
|
|
date = new Date(date);
|
|
return `${date.getFullYear()}-${date.getMonth() + 1 > 10 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1)}-${date.getDate() > 10 ? date.getDate() : '0' + date.getDate()}`;
|
|
},
|
|
onConfirmDate(e) {
|
|
let formControllers = this.data.formControllers;
|
|
formControllers[this.data.dateIndex].value = this.formatDate(e.detail)
|
|
this.setData({
|
|
showDate: false,
|
|
formControllers
|
|
});
|
|
console.log(this.data.formControllers)
|
|
|
|
},
|
|
setVal(e) {
|
|
let formControllers = this.data.formControllers;
|
|
console.log(e)
|
|
formControllers[e.currentTarget.dataset.index].value = e.detail
|
|
this.setData({
|
|
showDate: false,
|
|
formControllers
|
|
});
|
|
console.log(this.data.formControllers)
|
|
},
|
|
pickerChange(e) {
|
|
let {valuekey, options, currentindex, key} = e.currentTarget.dataset
|
|
let index = e.detail.value
|
|
console.log(key, 'key')
|
|
let formControllers = this.data.formControllers;
|
|
let selected = options[index]
|
|
formControllers[currentindex].value = selected[valuekey]
|
|
formControllers[currentindex].valueIndex = e.detail.value
|
|
if (selected.masterControl) {
|
|
formControllers.forEach(item => {
|
|
if (item.showFlag) {
|
|
if (item.showFlag === selected[valuekey]) {
|
|
item.hide = false
|
|
} else {
|
|
item.hide = true
|
|
}
|
|
}
|
|
})
|
|
}
|
|
this.setData({
|
|
formControllers
|
|
})
|
|
},
|
|
sure() {
|
|
console.log('ok', this.data.formControllers)
|
|
this.triggerEvent('ok', this.data.formControllers)
|
|
this.onClose();
|
|
}
|
|
},
|
|
});
|
|
|