// components/dropdownMenu/dropdownMenu.js
const defaultSource = [{
id: 0,
title: "排序",
content: { name: "未选择" },
options: [
{ name: "首付比例" },
{ name: "余值比例" },
{ name: "期次" },
{ name: "租金范围" },
],
},
{
id: 1,
title: "方式",
content: { name: "未选择" },
options: [
{ name: "升序" },
{ name: "降序" }
],
}];
Component({
properties: {
source: {
type: Array,
value: defaultSource,
description: '数据源'
}
},
data: {
currentActivity: defaultSource[0],
currentOption: defaultSource[0].options,
hidePannel: true,
selectedPannelItem: '',
componentHeight: '50vh',
},
ready: function() {
const that = this;
const query = wx.createSelectorQuery().in(this)
const screenHeight = wx.getSystemInfoSync().screenHeight;
query.select("#component-container").boundingClientRect(function (res) {
const height = screenHeight - res.top - 64 + 'px';
that.setData({ componentHeight: height });
}).exec();
},
methods: {
switchPannel: function(e) {
const options = e.currentTarget.dataset.options;
const activity = e.currentTarget.dataset.activity;
if (this.data.hidePannel) {
this.openPannel();
} else if (this.data.currentActivity.id === activity.id) {
this.closePannel();
}
this.setData({ currentOption: options, currentActivity: activity });
},
selectPannelItem: function(e) {
const option = e.currentTarget.dataset.option;
this.setData({ selectedPannelItem: option });
},
confirm: function(e) {
const evtDetail = this.data;
const selectedItem = this.data.selectedPannelItem;
this.data.source[this.data.currentActivity.id] = {
...this.data.currentActivity,
content: selectedItem
};
this.setData({ source: this.data.source });
this.triggerEvent('onOk', evtDetail);
this.closePannel();
},
openPannel: function() {
this.setData({ hidePannel: false });
},
closePannel: function() {
this.setData({ hidePannel: true });
}
}
})