1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- Component({
- properties: {
- list: {
- type: Array,
- value: [{
- label: "筛选1",
- index: null,
- showName: "name", //显示字段
- valueKey: "name", //返回Key
- selectKey: "id", //传参 代表选着字段 不传参返回整个选择对象
- value: "", //选中值
- list: [{
- name: "a1",
- id: 0
- }, {
- name: "a2",
- id: 1
- }]
- }]
- },
- handle: Function, //按钮回调函数
- zIndex: {
- type: String,
- value: 99999,
- }
- },
- data: {},
- methods: {
- /* 选择 */
- onSelect(e) {
- const {
- item, //被选项
- index, //列表下标
- i //被选项下标
- } = e.currentTarget.dataset;
- if (this.data.list[index].index == i) {
- this.setData({
- [`list[${index}].value`]: "",
- [`list[${index}].index`]: null
- });
- } else {
- this.setData({
- [`list[${index}].value`]: this.data.list[index].selectKey ? item[this.data.list[index].selectKey] : item,
- [`list[${index}].index`]: i
- });
- }
- let obj = {};
- this.data.list.forEach(v => {
- if (v.type == 'multilevelClass') {
- obj[v.valueKey] = getApp().globalData.temporaryId;
- delete(getApp().globalData.temporaryId);
- } else {
- obj[v.valueKey] = v.value;
- }
- });
- this.triggerEvent("handle", obj);
- },
- }
- })
|