// customer/pages/brokerindex/brokerindex.js var App = getApp(); var utils = require("../../../utils/http"); var page = 1; Page({ /** * 页面的初始数据 */ data: { loading: false, name: '', phone: '', community_name: '', type: '', brokerRanklist: [], swiperData: [] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { page = 1; if (!!options.type) { this.setData({ type: options.type }) } this.getBrokerRank(); wx.hideHomeButton(); }, jumpMinePage:function(e) { wx.reLaunch({ url: '/customer/pages/broker/broker', }) }, nameInput(e) { console.log(e) this.setData({ name: e.detail.value }) }, phoneInput(e) { this.setData({ phone: e.detail.value }) }, communityNameInput(e) { this.setData({ community_name: e.detail.value }) }, //手机号正则验证 isPhoneNum: function (phone) { var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\d{8})$/; if (!myreg.test(phone)) { return false; } return true; }, /** * 添加客户 */ addCustomer: function () { var that = this; if (!that.data.phone) { wx.showToast({ title: '请填写手机号', icon: 'none', }); return false; } if (!this.isPhoneNum(that.data.phone)) { wx.showToast({ title: '手机号格式错误', icon: 'none', }); return false; } wx.showLoading({ title: '提交中...' }); that.setData({ loading: true, }) utils.$post({ url: App.globalData.webUrl + 'api/agents_work/add_customer', header: { 'Authorization': 'bearer ' + App.globalData.token }, data: { name: that.data.name, phone: that.data.phone, community_name: that.data.community_name }, success: function (res) { wx.hideLoading(); if (res.data.code == '0') { wx.showToast({ title: '添加成功', icon: 'none', duration: 1500 }) that.setData({ loading: false, name: '', phone: '', community_name: '' }) } else { wx.showToast({ title: res.data.msg, icon: 'none', duration: 1500 }) } } }) }, /** * 经纪人排名列表 */ getBrokerRank() { let that = this; utils.$post({ url: App.globalData.webUrl + 'api/agents_work/agent_rank_list', header: { 'Authorization': 'bearer ' + App.globalData.token }, data: { page: page, limit: 10, }, success: function (res) { if (res.data.code == '0') { that.setData({ datashow: true, brokerRanklist: res.data.data }) if (that.data.brokerRanklist.length) { if (that.data.brokerRanklist.length > 6) { that.setData({ swiperData: that.data.brokerRanklist.slice(0,6) }) } else { that.setData({ swiperData: that.data.brokerRanklist }) } } if (that.data.type == 'rank') { wx.pageScrollTo({scrollTop: 750}) } } } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { if (this.data.type == 'rank') { page++; let that = this; utils.$post({ url: App.globalData.webUrl + 'api/agents_work/agent_rank_list', header: { 'Authorization': 'bearer ' + App.globalData.token }, data: { page: page, limit: 10, }, success: function (res) { if (res.data.code == '0') { let arr = that.data.brokerRanklist.concat(res.data.data); that.setData({ datashow: true, brokerRanklist: arr }) } } }) } }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })