123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553 |
- // customer/pages/brokerindex/brokerindex.js
- var App = getApp();
- var utils = require("../../../utils/http");
- var page = 1;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- imgUrl: App.globalData.imgUrl,
- agentName: App.globalData.agentName,
- loading: false,
- shareArticleNew: false,
- name: '',
- phone: '',
- community_name: '',
- type: '',
- mobile: "",
- brokerRanklist: [],
- swiperData: [],
- employee_id: '',
- brokerType: '',
- brokeflag: false,
- loadimg: false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- page = 1;
- if (!!options.scene) {
- options = unescape(options.scene);
- let arr = options.split('&');
- let obj = {};
- for (let i = 0; i < arr.length; i++) {
- let arr1 = arr[i].split('=');
- obj[arr1[0]] = arr1[1];
- }
- App.globalData.clientype = obj.cli;
- App.globalData.brokerType = obj.type;
- App.globalData.brokerEmployeeId = obj.id;
- this.setData({
- employee_id: obj.id,
- brokerType: obj.type
- })
- this.login();
- } else {
- if (!!options.id) {
- this.setData({
- employee_id: options.id
- })
- }
- if (!!options.cli) {
- App.globalData.clientype = options.cli;
- }
- if (!!options.uid) {
- App.globalData.shareuserid = options.uid;
- this.login();
- }
- this.checkSignUp();
- this.getBrokerRank();
- this.inviteShow();
- }
- if (!!options.type) {
- this.setData({
- type: options.type
- })
- }
- wx.hideHomeButton();
- },
- agreePrivacy() {},
- /**
- * 登录
- */
- login: function () {
- wx.showLoading({
- title: "加载中..."
- })
- var that = this;
- wx.login({
- success: function (data) {
- if (data.errMsg == 'login:ok') {
- utils.$post({
- url: App.globalData.webUrl + 'api/users/code2session',
- data: {
- code: data.code,
- share: App.globalData.shareuserid,
- client_type: App.globalData.clientype
- },
- success: function (r) {
- if (r.data.code == '0') {
- App.globalData.sharepersonobj = r.data.share;
- App.globalData.token = r.data.token;
- App.globalData.companyobj = r.data.company_data;
- App.globalData.personMsg = r.data.user;
- App.globalData.companyname = r.data.company;
- App.globalData.official_openid = r.data.official_openid;
- if (!r.data.agent_employee_id) {
- that.getEmployeeUid();
- } else {
- App.globalData.agentEmployeEid = r.data.agent_employee_id;
- }
- if (r.data.isagent) {
- App.globalData.brokeruserId = r.data.isagent;
- that.getBrokerRank();
- }
- if (!!r.data.user.phone) {
- that.setData({
- employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false,
- })
- if (!!r.data.user.binded && r.data.user.binded.state == '在职') {
- App.globalData.currentUserId = r.data.user.binded.id;
- }
- App.globalData.personMsg = r.data.user;
- App.globalData.userflag = false; //有个人信息
- App.globalData.phone = false; //没有手机号
- }
- that.sharecompany();
- that.getCurAgentName();
- setTimeout(function () {
- wx.hideLoading();
- that.checkSignUp();
- that.inviteShow();
- }, 500)
- }
- }
- })
- }
- }
- })
- },
- /**
- * 所属公司
- */
- sharecompany: function () {
- const that = this;
- utils.$post({
- url: App.globalData.webUrl + 'client/index/content_belong_company',
- header: {
- 'Authorization': 'bearer ' + App.globalData.token
- },
- data: {
- client_type: App.globalData.clientype,
- uid: App.globalData.shareuserid
- },
- success: function (res) {
- if (res.data.code == '0') {
- App.globalData.companyobj = res.data.data;
- }
- },
- complete(res) {
- wx.hideLoading()
- }
- })
- },
- /**
- * 根据员工ID获取其UID
- */
- getEmployeeUid() {
- const that = this;
- utils.$get({
- url: App.globalData.webUrl + 'api/agents/get_empuid',
- header: {
- 'Authorization': 'bearer ' + App.globalData.token
- },
- data: {
- employee_id: that.data.employee_id
- },
- success: function (res) {
- if (res.data.code == '0') {
- App.globalData.agentEmployeEid = res.data.data;
- }
- }
- })
- },
- /**
- * 获取自定义推荐官名称
- */
- getCurAgentName: function () {
- const that = this;
- utils.$get({
- url: App.globalData.webUrl + 'api/agents/get_agent_name',
- header: {
- 'Authorization': 'bearer ' + App.globalData.token
- },
- data: {},
- success: function (res) {
- if (res.data.code == '0') {
- App.globalData.agentName = res.data.name;
- that.setData({
- agentName: res.data.name,
- })
- }
- }
- })
- },
- /**
- * 查询是否已经报名
- */
- checkSignUp() {
- let that = this;
- utils.$post({
- url: App.globalData.webUrl + 'api/agents/sel_sign_up',
- header: {
- 'Authorization': 'bearer ' + App.globalData.token
- },
- data: {
- alertshow: '123'
- },
- success: function (res) {
- // code 1待审核,2存在,0不存在
- if (res.data.code == '2' || res.data.code == '1') {
- that.setData({
- brokeflag: true
- })
- } else {
- that.setData({
- brokeflag: false
- })
- }
- }
- })
- },
- getPhoneNumberTap: function (res) {
- var that = this;
- if (res.detail.errMsg == 'getPhoneNumber:ok') {
- that.setData({
- loading: true,
- })
- utils.$post({
- url: App.globalData.webUrl + 'api/users/setUserMobile',
- data: {
- encryptedData: res.detail.encryptedData,
- iv: res.detail.iv
- },
- header: {
- 'Authorization': 'bearer ' + App.globalData.token
- },
- success: function (r) {
- if (r.data.code == '0') {
- that.setData({
- mobile: r.data.mobile
- })
- that.submitMsg();
- }
- }
- })
- }
- },
- /**
- * 提交注册数据
- */
- submitMsg() {
- var that = this;
- utils.$post({
- url: App.globalData.webUrl + 'api/agents/add_agents',
- header: {
- 'Authorization': 'bearer ' + App.globalData.token
- },
- data: {
- name: '',
- phone: that.data.mobile,
- employee_id: that.data.employee_id,
- wechat: '',
- type: that.data.brokerType
- },
- success: function (res) {
- if (res.data.code == '0') {
- App.globalData.brokeruserId = res.data.data;
- that.setData({
- brokeflag: true
- })
- that.addCustomer();
- that.getBrokerRank();
- }
- }
- })
- },
- /**
- * 邀请函弹窗
- */
- inviteShow() {
- let that = this;
- utils.$post({
- url: App.globalData.webUrl + 'api/agents/inviteShow',
- header: {
- 'Authorization': 'bearer ' + App.globalData.token
- },
- data: {},
- success: function (res) {
- if (res.data.code == 0) {
- that.setData({
- loadimg: true,
- agentBackgroundImg: res.data.content.agentBackgroundImg
- })
- }
- }
- })
- },
- jumpMinePage: function (e) {
- if (!App.globalData.brokeruserId) {
- wx.showToast({
- title: `请先成为${App.globalData.agentName||'装修推荐官'}`,
- icon: "none"
- })
- return false;
- }
- wx.reLaunch({
- url: '/customer/pages/broker/broker',
- })
- },
- jumpSharePage: function () {
- wx.reLaunch({
- url: '/customer/pages/brokershare/brokershare',
- })
- },
- jumpscreenshot: function () {
- if (!App.globalData.brokeruserId) {
- wx.showToast({
- title: `请先成为${App.globalData.agentName||'装修推荐官'}`,
- icon: "none"
- })
- return false;
- }
- wx.reLaunch({
- url: '/customer/pages/screenshot/screenshot',
- })
- },
- 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;
- },
- getNewShareArticleNum() {
- let that = this;
- utils.$post({
- url: App.globalData.webUrl + 'api/agentsWork/newShareArticle',
- header: {
- 'Authorization': 'bearer ' + App.globalData.token
- },
- data: {},
- success: function (res) {
- if (res.data.code == '0') {
- that.setData({
- shareArticleNew: res.data.new
- })
- }
- }
- })
- },
- /**
- * 添加客户
- */
- 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: ''
- })
- page = 1;
- that.getBrokerRank();
- } else {
- that.setData({
- loading: false,
- })
- wx.showToast({
- title: res.data.msg,
- icon: 'none',
- duration: 1500
- })
- }
- }
- })
- },
- /**
- * 装修推荐官排名列表
- */
- getBrokerRank() {
- if (!App.globalData.brokeruserId) {
- return false;
- }
- 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') {
- res.data.data = res.data.data.map(v => {
- v.type_name = v.type ? v.type.substring(0, 1) : '';
- return v;
- })
- 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() {
- setTimeout(() => {
- wx.stopPullDownRefresh();
- }, 800)
- page = 1;
- this.getBrokerRank();
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- 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') {
- res.data.data = res.data.data.map(v => {
- v.type_name = v.type ? v.type.substring(0, 1) : '';
- return v;
- })
- let arr = that.data.brokerRanklist.concat(res.data.data);
- that.setData({
- datashow: true,
- brokerRanklist: arr
- })
- }
- }
- })
- }
- },
- })
|