// 修改 toggleSelect 方法
toggleSelect(e) {
console.log('点击事件触发,模具ID:', e.currentTarget.dataset.id);
const moldId = e.currentTarget.dataset.id + '';
let selectedIds = [...this.data.selectedIds];
const index = selectedIds.indexOf(moldId);
if (index > -1) {
selectedIds.splice(index, 1);
} else {
selectedIds.push(moldId);
}
console.log('更新后的selectedIds', selectedIds);
this.setData({
selectedIds,
});
this.updateSelectedCodesText(selectedIds);
this.updateLastMoveTimeText();
},
<scroll-view class="mold-list" scroll-y="true">
<block wx:for="{{filteredMolds}}" wx:key="_id">
<view
class="mold-item {{selectedIds.indexOf(item._id + '') !== -1 ? 'selected' : ''}}"
bindtap="toggleSelect"
data-id="{{item._id}}">
<view class="mold-info">
<view class="code-time-container">
<text class="code {{selectedIds.indexOf(item._id + '') !== -1 ? 'green-text' : ''}}">{{item.code}}</text>
<text class="last-move-time {{selectedIds.indexOf(item._id + '') !== -1 ? 'green-text' : ''}}">时间: {{item.formattedLastMoveTime}}</text>
</view>
<view class="meta-container">
<view class="meta-left">
<text class="{{selectedIds.indexOf(item._id + '') !== -1 ? 'green-text' : ''}}">区域: {{item.area}}</text>
<text class="{{selectedIds.indexOf(item._id + '') !== -1 ? 'green-text' : ''}}">钳工组: {{item.group}}</text>
</view>
<view class="meta-right">
<text class="{{selectedIds.indexOf(item._id + '') !== -1 ? 'green-text' : ''}}">原位置: {{item.lastMoveArea}}</text>
<text class="{{selectedIds.indexOf(item._id + '') !== -1 ? 'green-text' : ''}}">P: {{item.lastMovePerson}}</text>
</view>
</view>
</view>
</view>
</block>
/* 修改后的 .mold-item 样式 */
.mold-item {
position: relative;
padding: 10px;
background: #fff;
margin-bottom: 10px;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
transition: all 0.2s ease;
border-left: 4px solid transparent;
/* 移除固定宽度设置 */
/* width: 87%; */
/* max-width: 90%; */
/* min-width: 100px; */
}
/* 增强 .mold-item.selected 优先级 */
.mold-item.selected {
background-color: #21dd31 !important; /* 添加 !important */
border-left: 10px solid #4caf50 !important; /* 添加 !important */
transition: all 0.1s;
}

已经被折磨两天了