yuminge-app/yun-min-program-plugin-master/packageE/healthy/component/healthy_height/healthy_height.js

72 lines
1.4 KiB
JavaScript

// packageE/healthy/component/healthy_height/healthy_height.js
const tempHeightList = [];
for (let i = 100; i <= 200; i++) {
tempHeightList.push(i);
}
Component({
/**
* 组件的属性列表
*/
properties: {
question: {
type: Object,
value: {},
},
answer: {
type: Object,
value: {},
},
site: {
type: Number,
value: 0,
},
},
/**
* 组件的初始数据
*/
data: {
heightList: tempHeightList,
selected: [0],
},
ready() {
let answer = parseInt(this.data.answer.answer);
console.log(this.data.question);
let heightList = this.data.question.interval;
if (heightList.length == 0) heightList = tempHeightList;
this.setData({ heightList });
if (answer) {
let select =
heightList.indexOf(answer) > -1 ? heightList.indexOf(answer) : 0;
this.setData({
selected: [select],
});
} else {
this.triggerEvent("quesCallback", {
question: this.data.question,
site: this.data.site,
answer: heightList[this.data.selected[0]],
});
}
},
/**
* 组件的方法列表
*/
methods: {
change(event) {
let arr = event.detail.value;
this.setData({ selected: arr });
this.triggerEvent("quesCallback", {
question: this.data.question,
site: this.data.site,
answer: this.data.heightList[arr[0]],
});
},
},
});