Files
danyang-match/miniapp/components/user-card/index.js
T

52 lines
1.6 KiB
JavaScript
Raw Normal View History

2026-09-09 22:05:00 +08:00
/**
* UserCard 用户卡片(列表项 / Discover / 活动互选)
*
* 不携带任何操作按钮,纯展示;操作按钮由调用方 slot 注入。
* 用法:
* <ui-user-card user="{{user}}" bind:tap="onTap">
* <view slot="actions">…自定义按钮…</view>
* </ui-user-card>
*/
const { profileLabelOf } = require('../../constants')
2026-09-09 22:05:00 +08:00
Component({
options: { addGlobalClass: true, multipleSlots: true },
properties: {
user: { type: Object, value: null },
showReasons: { type: Boolean, value: false }, // 是否展示推荐理由
selectable: { type: Boolean, value: false }, // 是否显示选择框
selected: { type: Boolean, value: false },
},
data: {
// 由后端枚举码派生的中文展示值(界面不得出现英文码)
educationLabel: '',
occupationLabel: '',
maritalLabel: '',
},
observers: {
user(u) {
if (!u) {
this.setData({ educationLabel: '', occupationLabel: '', maritalLabel: '' })
return
}
this.setData({
educationLabel: profileLabelOf('educationCode', u.educationCode),
occupationLabel: profileLabelOf('occupationCode', u.occupationCode),
maritalLabel: profileLabelOf('maritalStatus', u.maritalStatus),
})
},
},
2026-09-09 22:05:00 +08:00
methods: {
onTap() {
if (!this.data.user) return;
this.triggerEvent('tap', { userId: this.data.user.userId });
},
onToggleSelect() {
this.triggerEvent('select', {
userId: this.data.user.userId,
selected: !this.data.selected,
});
},
},
});