微信小程序选择学校

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

<view class="container">  
  <view class="search-bar">  
    <input class="search-input" type="text" placeholder="请输入学校名称" bindinput="handleInput" value="{{searchValue}}" />  
  </view>  
  <view class="school-list" wx:if="{{schools.length > 0}}">  
    <block wx:for="{{schools}}" wx:key="index">  
      <view class="school-card" bindtap="navigateToSchoolDetail" data-schoolid="{{item.schoolid}}" data-schoolcode="{{item.schoolcode}}">
      
        <text class="card-title">{{item.name}}</text>  
        <text class="card-info">{{item.address}}</text>  
      </view>  
    </block>  
  </view>  
  <view class="no-results" wx:else>没有找到相关学校</view>  
</view>
.container {
  display: flex;
  flex-direction: column;
  padding: 10px;
}

.search-input {
  width: 100%;
  height: 40px;
  border: 1px solid #1296db;
  border-radius: 40rpx;
  padding: 0 10rpx;
  font-size: 28rpx;
  line-height: 40rpx;
  color: #333;
  background-color: #fff;
  box-sizing: border-box;
}

.school-card {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  border: 1px solid #1296db;
  background-color: #EDF4FF;
  color: #1296db;
  border-radius: 10px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
  padding: 15px;
}

.card-title,
.card-info {
  text-align: left;
}

.card-title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 10px;
}

.card-info {
  font-size: 14px;
  color: #666;
}

.no-results {
  margin-top: 20px;
  text-align: center;
  font-size: 30rpx;
  color: #080808;
}
Page({    
  data: {    
    searchValue: '',     
    allSchools: [], 
    schools: []   
  },    
    
  onLoad: function() {  
    const mockAllSchools = [  
      { name: '北京大学', address: '北京市海淀区颐和园路5号',schoolid:'100001',schoolcode:'B' },  
      { name: '清华大学', address: '北京市海淀区双清路30号',schoolid:'100002',schoolcode:'B' },  
      { name: '上海交通大学', address: '上海市闵行区东川路800号',schoolid:'100003',schoolcode:'S' },  
    ];  
    this.setData({  
      allSchools: mockAllSchools,  
      schools: mockAllSchools   
    });  
  },  
    
  handleInput: function(e) {    
    const searchValue = e.detail.value.trim();    
    this.setData({    
      searchValue: searchValue    
    });    
    this.filterSchools(searchValue);  
  },    
    
  filterSchools: function(searchValue) {    
    const regex = new RegExp(searchValue, 'i');
    const filteredSchools = this.data.allSchools.filter(school => {    
      return regex.test(school.name);    
    });    
    this.setData({    
      schools: filteredSchools    
    });    
  },
  navigateToSchoolDetail: function(event) {
    const { schoolid, schoolcode } = event.currentTarget.dataset;
    wx.showToast({
      title: '/pages/schoolinfo/schoolinfo?schoolid=' + schoolid + '&schoolcode=' + schoolcode,
      icon:'none'
    })
  }
});
  • 12
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值