import { models, db } from '../../utils/cloudbase.js' Page({ data: { phone: '', gardenList: [], // 这里替换为实际园所名称数组 gardenIndex: null, contactsname: '', selected: {} }, // 监听手机号输入框 onPhoneInput(e) { this.setData({ phone: e.detail.value }); }, // 监听姓名输入框 onContactsInput(e) { this.setData({ contactsname: e.detail.value }); }, onLoad(options) { this.onScholl(); this.setData({ phone: options.phone || '' }); }, // 获取学校数据 async onScholl() { try { let allRecords = []; let pageNumber = 1; const pageSize = 100; // 每次查询 100 条 while (true) { const { data } = await models.wx_school.list({ filter: { where: {} }, pageSize: pageSize, pageNumber: pageNumber, getCount: true, envType: "prod", }); if (data.records.length === 0) { break; // 没有更多数据,退出循环 } allRecords = allRecords.concat(data.records); // 将当前页数据添加到全部数据中 pageNumber++; // 查询下一页 } this.setData({ gardenList: allRecords // 按实际字段替换 }); console.log(this.data.gardenList, 'gardenList'); } catch (error) { console.error('获取数据失败:', error); wx.showToast({ title: '获取数据失败,请稍后再试', icon: 'none' }); } }, // 选择学校下拉框 async onGardenChange(e) { const index = parseInt(e.detail.value); this.setData({ gardenIndex: index }); const selected = this.data.gardenList[index]; this.setData({ selected: selected }) }, // 确定 async bindingevents() { const { phone, contactsname, selected } = this.data; if (!phone || !contactsname || !selected) { wx.showToast({ title: '请填写完整信息', icon: 'none' }); return; } try { // 查询校验 const { data } = await models.wx_teacher_user.get({ filter: { where: { phone: phone, school_id: selected._id, name: contactsname } }, envType: "prod", }); if (data && Object.keys(data).length > 0) { const user = Array.isArray(data) ? data[0] : data; // 更新 await models.wx_teacher_user.update({ filter: { where: { $and: [ { _id: { $eq: user._id, // 推荐传入_id数据标识进行操作 }, }, ] } }, data: { bound: 1 }, envType: "prod" }); // 登录成功,保存用户信息 wx.setStorageSync('userInfo', user); wx.showToast({ title: '绑定成功', icon: 'success', duration: 1500 }); setTimeout(() => { wx.reLaunch({ url: '/pages/index/index' }); }, 1500); } else { wx.showToast({ title: '绑定失败,请确认信息是否正确', icon: 'none' }); } } catch (error) { console.error('绑定失败:', error); wx.showToast({ title: '请求失败,请稍后再试', icon: 'none' }); } } })