daofu-applet/components/pop-sheet/index.js

73 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-01-29 17:42:38 +08:00
// components/pop-sheet/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
show: Boolean,
multiple: {
type: Boolean,
value: false
},
title: String,
proName: String,
single: String,
outSide: Array,
list: Array
},
/**
* 组件的初始数据
*/
data: {
item: {}
},
/**
* 组件的方法列表
*/
methods: {
/**
* 关闭弹窗
*/
close: function () {
this.triggerEvent('close', {
item: this.data.multiple ? this.data.list.filter(item => {
return item.checked
}) : this.data.item,
single: this.data.single
})
},
/**
* 选中列表
*/
filterFun: function (params) {
const item = params.currentTarget.dataset.item;
const index = params.currentTarget.dataset.index;
item.checked = !item.checked;
this.data.outSide?.forEach(el => {
if (item[this.data.proName] == el) {
this.data.list.forEach(ele => {
ele.checked = false;
})
} else {
this.data.list.filter(els => {
if (els[this.data.proName] == el) els.checked = false
})
}
})
this.data.item = item;
this.data.list[index] = item;
this.setData(this.data)
if (!this.data.multiple) this.close();
},
/**
* 确定/取消
*/
submit: function (params) {
this.close();
},
}
})