// pages/bindCompany/bindCompany.js var app = getApp() Page({ /** * 页面的初始数据 */ data: { sendyzm: "获取验证码", phone: '', yzm: '', name: '', company: '',//公司名 companyId: '',//公司id showModal: false,//公司弹窗 infoName: '',//搜索 dataList: [],//公司列表 }, //提交 btn() { if (this.data.name == '') { wx.showToast({ title: '请输入姓名~', icon: 'none' }) return } if (this.data.phone.length != 11) { wx.showToast({ title: '请输入正确的手机号~', icon: 'none' }) return } if (this.data.yzm == '') { wx.showToast({ title: '请输入验证码~', icon: 'none' }) return } if (this.data.company == '') { wx.showToast({ title: '请选择公司~', icon: 'none' }) return } wx.showLoading({ title: '发送中..', mask: true, }) wx.request({ url: app.globalData.ip + '/wisdommining/api/user/perfectInfo', method: 'PUT', header: { "content-type": "application/x-www-form-urlencoded", }, data: { code: this.data.yzm, companyId: this.data.companyId, phone: this.data.phone, userName: this.data.name, userId: app.globalData.userId, }, success: res => { console.log(res) wx.hideLoading() if (res.data.code == 1) { wx.showToast({ title: '绑定成功~', icon: 'none', success: ss => { setTimeout(() => { wx.navigateBack() }, 1000); } }) } else { wx.showModal({ title: '提示!', content: res.data.message, showCancel: false, }) } }, fail: f => { wx.hideLoading() wx.showToast({ title: '请求异常', icon: "none", }) } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.dataList() }, searchGs() { this.dataList() }, //获取验证码 sendyzm: function (e) { var phone = this.data.phone; if (phone.length != 11) { wx.showToast({ title: '请输入正确的手机号~', icon: 'none' }) return } wx.showLoading({ title: '发送中..', mask: true, }) wx.request({ url: app.globalData.ip + '/wisdommining/api/user/sendSms', method: 'GET', header: { "content-type": "application/x-www-form-urlencoded", }, data: { phone: phone, }, success: res => { console.log(res) wx.hideLoading() if (res.data.code == 1) { wx.showToast({ title: '发送成功~', icon: 'none', }) let time = 60; let codeV = setInterval(t => { this.setData({ sendyzm: '重新获取' + (--time) + 's' }) if (time == -1) { clearInterval(codeV) this.setData({ sendyzm: '获取验证码' }) } }, 1000) } else { wx.showModal({ title: '提示!', content: res.data.message, showCancel: false, }) } }, fail: f => { wx.hideLoading() wx.showToast({ title: '请求异常', icon: "none", }) } }) }, //选择公司 select: function (e) { let index = e.currentTarget.dataset.index; let id = e.currentTarget.dataset.id; let dataList = this.data.dataList; for (let i = 0; i < dataList.length; i++) { dataList[i].select = false; } dataList[index].select = true; this.setData({ dataList: dataList, showModal: false, company: dataList[index].companyName, companyId: id, infoName:'' }) }, confirm() { this.setData({ showModal: false, }) }, //搜索 search(e) { this.setData({ infoName: e.detail.value }) }, del() { this.setData({ infoName: '' }) }, //点击选择公司出现弹框 show() { this.setData({ infoName: '', showModal: true, }) this.dataList() }, //姓名 name: function (e) { this.setData({ name: e.detail.value }) }, //手机号 phone: function (e) { this.setData({ phone: e.detail.value }) }, //验证码 yzm: function (e) { this.setData({ yzm: e.detail.value }) }, dataList: function (options) { wx.showLoading({ title: '加载中..', }) wx.request({ url: app.globalData.ip + '/wisdommining/api/user/getCompany', method: 'GET', header: { "content-type": "application/x-www-form-urlencoded", }, data: { conpanyName: this.data.infoName }, success: res => { wx.hideLoading() console.log(res) if (res.data.code == 1) { this.setData({ dataList: res.data.value }) } else { wx.showModal({ title: '提示!', content: res.data.message, showCancel: false, }) } } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, })