/** * UserCard 用户卡片(列表项 / Discover / 活动互选) * * 不携带任何操作按钮,纯展示;操作按钮由调用方 slot 注入。 * 用法: * * …自定义按钮… * */ const { profileLabelOf } = require('../../constants') 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), }) }, }, 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, }); }, }, });