mirror of
https://git.beihong.wang/wangbeihong/iot-bedroom-environment-controller.git
synced 2026-04-23 11:53:03 +08:00
71 lines
1.3 KiB
JavaScript
71 lines
1.3 KiB
JavaScript
Component({
|
|
behaviors: ['wx://form-field-group'],
|
|
properties: {
|
|
name: {
|
|
type: String,
|
|
value: ''
|
|
},
|
|
value: {
|
|
type: String,
|
|
value: '',
|
|
observer(val) {
|
|
this.modelChange(val)
|
|
}
|
|
}
|
|
},
|
|
relations: {
|
|
'../fui-radio/fui-radio': {
|
|
type: 'descendant',
|
|
linked: function (target) {
|
|
this.data.childrens.push(target)
|
|
if (this.data.value) {
|
|
target.setData({
|
|
val: this.data.value === target.data.value
|
|
})
|
|
}
|
|
}
|
|
}
|
|
},
|
|
data: {
|
|
val: '',
|
|
childrens: []
|
|
},
|
|
methods: {
|
|
radioChange(e) {
|
|
this.triggerEvent('change', e)
|
|
this.setData({
|
|
value: e.value
|
|
})
|
|
},
|
|
changeValue(value, target) {
|
|
if (value === this.data.val) return;
|
|
this.setData({
|
|
val: value
|
|
})
|
|
this.data.childrens.forEach(item => {
|
|
if (item !== target) {
|
|
item.setData({
|
|
val: false
|
|
})
|
|
}
|
|
})
|
|
let e = {
|
|
value: value
|
|
}
|
|
this.radioChange(e)
|
|
},
|
|
modelChange(val) {
|
|
this.data.childrens.forEach(item => {
|
|
if (item.data.value === val) {
|
|
item.setData({
|
|
val: true
|
|
})
|
|
} else {
|
|
item.setData({
|
|
val: false
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}) |