Files
code-bang/frontend/miniapp/components/goods-list/index.js
T
2026-10-15 15:16:17 +08:00

63 lines
1.1 KiB
JavaScript

Component({
externalClasses: ['wr-class'],
properties: {
goodsList: {
type: Array,
value: [],
},
id: {
type: String,
value: '',
observer: (id) => {
this.genIndependentID(id);
},
},
thresholds: {
type: Array,
value: [],
},
// 是否展示卡片上的"购买"引导按钮
showBuy: {
type: Boolean,
value: false,
},
// 是否展示价格(案例展示时关闭)
showPrice: {
type: Boolean,
value: true,
},
},
data: {
independentID: '',
},
lifetimes: {
ready() {
this.init();
},
},
methods: {
onClickGoods(e) {
const { index } = e.currentTarget.dataset;
this.triggerEvent('click', { ...e.detail, index });
},
init() {
this.genIndependentID(this.id || '');
},
genIndependentID(id) {
if (id) {
this.setData({ independentID: id });
} else {
this.setData({
independentID: `goods-list-${~~(Math.random() * 10 ** 8)}`,
});
}
},
},
});