brokerindex.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. // customer/pages/brokerindex/brokerindex.js
  2. var App = getApp();
  3. var utils = require("../../../utils/http");
  4. var page = 1;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. imgUrl: App.globalData.imgUrl,
  11. agentName: App.globalData.agentName,
  12. loading: false,
  13. shareArticleNew: false,
  14. name: '',
  15. phone: '',
  16. community_name: '',
  17. type: '',
  18. mobile: "",
  19. brokerRanklist: [],
  20. swiperData: [],
  21. employee_id: '',
  22. brokerType: '',
  23. brokeflag: false,
  24. loadimg: false
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad(options) {
  30. page = 1;
  31. if (!!options.scene) {
  32. options = unescape(options.scene);
  33. let arr = options.split('&');
  34. let obj = {};
  35. for (let i = 0; i < arr.length; i++) {
  36. let arr1 = arr[i].split('=');
  37. obj[arr1[0]] = arr1[1];
  38. }
  39. App.globalData.clientype = obj.cli;
  40. App.globalData.brokerType = obj.type;
  41. App.globalData.brokerEmployeeId = obj.id;
  42. this.setData({
  43. employee_id: obj.id,
  44. brokerType: obj.type
  45. })
  46. this.login();
  47. } else {
  48. if (!!options.id) {
  49. this.setData({
  50. employee_id: options.id
  51. })
  52. }
  53. if (!!options.cli) {
  54. App.globalData.clientype = options.cli;
  55. }
  56. if (!!options.uid) {
  57. App.globalData.shareuserid = options.uid;
  58. this.login();
  59. }
  60. this.checkSignUp();
  61. this.getBrokerRank();
  62. this.inviteShow();
  63. }
  64. if (!!options.type) {
  65. this.setData({
  66. type: options.type
  67. })
  68. }
  69. wx.hideHomeButton();
  70. },
  71. agreePrivacy() {},
  72. /**
  73. * 登录
  74. */
  75. login: function () {
  76. wx.showLoading({
  77. title: "加载中..."
  78. })
  79. var that = this;
  80. wx.login({
  81. success: function (data) {
  82. if (data.errMsg == 'login:ok') {
  83. utils.$post({
  84. url: App.globalData.webUrl + 'api/users/code2session',
  85. data: {
  86. code: data.code,
  87. share: App.globalData.shareuserid,
  88. client_type: App.globalData.clientype
  89. },
  90. success: function (r) {
  91. if (r.data.code == '0') {
  92. App.globalData.sharepersonobj = r.data.share;
  93. App.globalData.token = r.data.token;
  94. App.globalData.companyobj = r.data.company_data;
  95. App.globalData.personMsg = r.data.user;
  96. App.globalData.companyname = r.data.company;
  97. App.globalData.official_openid = r.data.official_openid;
  98. if (!r.data.agent_employee_id) {
  99. that.getEmployeeUid();
  100. } else {
  101. App.globalData.agentEmployeEid = r.data.agent_employee_id;
  102. }
  103. if (r.data.isagent) {
  104. App.globalData.brokeruserId = r.data.isagent;
  105. that.getBrokerRank();
  106. }
  107. if (!!r.data.user.phone) {
  108. that.setData({
  109. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false,
  110. })
  111. if (!!r.data.user.binded && r.data.user.binded.state == '在职') {
  112. App.globalData.currentUserId = r.data.user.binded.id;
  113. }
  114. App.globalData.personMsg = r.data.user;
  115. App.globalData.userflag = false; //有个人信息
  116. App.globalData.phone = false; //没有手机号
  117. }
  118. that.sharecompany();
  119. that.getCurAgentName();
  120. setTimeout(function () {
  121. wx.hideLoading();
  122. that.checkSignUp();
  123. that.inviteShow();
  124. }, 500)
  125. }
  126. }
  127. })
  128. }
  129. }
  130. })
  131. },
  132. /**
  133. * 所属公司
  134. */
  135. sharecompany: function () {
  136. const that = this;
  137. utils.$post({
  138. url: App.globalData.webUrl + 'client/index/content_belong_company',
  139. header: {
  140. 'Authorization': 'bearer ' + App.globalData.token
  141. },
  142. data: {
  143. client_type: App.globalData.clientype,
  144. uid: App.globalData.shareuserid
  145. },
  146. success: function (res) {
  147. if (res.data.code == '0') {
  148. App.globalData.companyobj = res.data.data;
  149. }
  150. },
  151. complete(res) {
  152. wx.hideLoading()
  153. }
  154. })
  155. },
  156. /**
  157. * 根据员工ID获取其UID
  158. */
  159. getEmployeeUid() {
  160. const that = this;
  161. utils.$get({
  162. url: App.globalData.webUrl + 'api/agents/get_empuid',
  163. header: {
  164. 'Authorization': 'bearer ' + App.globalData.token
  165. },
  166. data: {
  167. employee_id: that.data.employee_id
  168. },
  169. success: function (res) {
  170. if (res.data.code == '0') {
  171. App.globalData.agentEmployeEid = res.data.data;
  172. }
  173. }
  174. })
  175. },
  176. /**
  177. * 获取自定义推荐官名称
  178. */
  179. getCurAgentName: function () {
  180. const that = this;
  181. utils.$get({
  182. url: App.globalData.webUrl + 'api/agents/get_agent_name',
  183. header: {
  184. 'Authorization': 'bearer ' + App.globalData.token
  185. },
  186. data: {},
  187. success: function (res) {
  188. if (res.data.code == '0') {
  189. App.globalData.agentName = res.data.name;
  190. that.setData({
  191. agentName: res.data.name,
  192. })
  193. }
  194. }
  195. })
  196. },
  197. /**
  198. * 查询是否已经报名
  199. */
  200. checkSignUp() {
  201. let that = this;
  202. utils.$post({
  203. url: App.globalData.webUrl + 'api/agents/sel_sign_up',
  204. header: {
  205. 'Authorization': 'bearer ' + App.globalData.token
  206. },
  207. data: {
  208. alertshow: '123'
  209. },
  210. success: function (res) {
  211. // code 1待审核,2存在,0不存在
  212. if (res.data.code == '2' || res.data.code == '1') {
  213. that.setData({
  214. brokeflag: true
  215. })
  216. } else {
  217. that.setData({
  218. brokeflag: false
  219. })
  220. }
  221. }
  222. })
  223. },
  224. getPhoneNumberTap: function (res) {
  225. var that = this;
  226. if (res.detail.errMsg == 'getPhoneNumber:ok') {
  227. that.setData({
  228. loading: true,
  229. })
  230. utils.$post({
  231. url: App.globalData.webUrl + 'api/users/setUserMobile',
  232. data: {
  233. encryptedData: res.detail.encryptedData,
  234. iv: res.detail.iv
  235. },
  236. header: {
  237. 'Authorization': 'bearer ' + App.globalData.token
  238. },
  239. success: function (r) {
  240. if (r.data.code == '0') {
  241. that.setData({
  242. mobile: r.data.mobile
  243. })
  244. that.submitMsg();
  245. }
  246. }
  247. })
  248. }
  249. },
  250. /**
  251. * 提交注册数据
  252. */
  253. submitMsg() {
  254. var that = this;
  255. utils.$post({
  256. url: App.globalData.webUrl + 'api/agents/add_agents',
  257. header: {
  258. 'Authorization': 'bearer ' + App.globalData.token
  259. },
  260. data: {
  261. name: '',
  262. phone: that.data.mobile,
  263. employee_id: that.data.employee_id,
  264. wechat: '',
  265. type: that.data.brokerType
  266. },
  267. success: function (res) {
  268. if (res.data.code == '0') {
  269. App.globalData.brokeruserId = res.data.data;
  270. that.setData({
  271. brokeflag: true
  272. })
  273. that.addCustomer();
  274. that.getBrokerRank();
  275. }
  276. }
  277. })
  278. },
  279. /**
  280. * 邀请函弹窗
  281. */
  282. inviteShow() {
  283. let that = this;
  284. utils.$post({
  285. url: App.globalData.webUrl + 'api/agents/inviteShow',
  286. header: {
  287. 'Authorization': 'bearer ' + App.globalData.token
  288. },
  289. data: {},
  290. success: function (res) {
  291. if (res.data.code == 0) {
  292. that.setData({
  293. loadimg: true,
  294. agentBackgroundImg: res.data.content.agentBackgroundImg
  295. })
  296. }
  297. }
  298. })
  299. },
  300. jumpMinePage: function (e) {
  301. if (!App.globalData.brokeruserId) {
  302. wx.showToast({
  303. title: `请先成为${App.globalData.agentName||'装修推荐官'}`,
  304. icon: "none"
  305. })
  306. return false;
  307. }
  308. wx.reLaunch({
  309. url: '/customer/pages/broker/broker',
  310. })
  311. },
  312. jumpSharePage: function () {
  313. wx.reLaunch({
  314. url: '/customer/pages/brokershare/brokershare',
  315. })
  316. },
  317. jumpscreenshot: function () {
  318. if (!App.globalData.brokeruserId) {
  319. wx.showToast({
  320. title: `请先成为${App.globalData.agentName||'装修推荐官'}`,
  321. icon: "none"
  322. })
  323. return false;
  324. }
  325. wx.reLaunch({
  326. url: '/customer/pages/screenshot/screenshot',
  327. })
  328. },
  329. nameInput(e) {
  330. console.log(e)
  331. this.setData({
  332. name: e.detail.value
  333. })
  334. },
  335. phoneInput(e) {
  336. this.setData({
  337. phone: e.detail.value
  338. })
  339. },
  340. communityNameInput(e) {
  341. this.setData({
  342. community_name: e.detail.value
  343. })
  344. },
  345. //手机号正则验证
  346. isPhoneNum: function (phone) {
  347. 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})$/;
  348. if (!myreg.test(phone)) {
  349. return false;
  350. }
  351. return true;
  352. },
  353. getNewShareArticleNum() {
  354. let that = this;
  355. utils.$post({
  356. url: App.globalData.webUrl + 'api/agentsWork/newShareArticle',
  357. header: {
  358. 'Authorization': 'bearer ' + App.globalData.token
  359. },
  360. data: {},
  361. success: function (res) {
  362. if (res.data.code == '0') {
  363. that.setData({
  364. shareArticleNew: res.data.new
  365. })
  366. }
  367. }
  368. })
  369. },
  370. /**
  371. * 添加客户
  372. */
  373. addCustomer: function () {
  374. var that = this;
  375. if (!that.data.phone) {
  376. wx.showToast({
  377. title: '请填写手机号',
  378. icon: 'none',
  379. });
  380. return false;
  381. }
  382. if (!this.isPhoneNum(that.data.phone)) {
  383. wx.showToast({
  384. title: '手机号格式错误',
  385. icon: 'none',
  386. });
  387. return false;
  388. }
  389. wx.showLoading({
  390. title: '提交中...'
  391. });
  392. that.setData({
  393. loading: true,
  394. })
  395. utils.$post({
  396. url: App.globalData.webUrl + 'api/agents_work/add_customer',
  397. header: {
  398. 'Authorization': 'bearer ' + App.globalData.token
  399. },
  400. data: {
  401. name: that.data.name,
  402. phone: that.data.phone,
  403. community_name: that.data.community_name
  404. },
  405. success: function (res) {
  406. wx.hideLoading();
  407. if (res.data.code == '0') {
  408. wx.showToast({
  409. title: '添加成功',
  410. icon: 'none',
  411. duration: 1500
  412. })
  413. that.setData({
  414. loading: false,
  415. name: '',
  416. phone: '',
  417. community_name: ''
  418. })
  419. page = 1;
  420. that.getBrokerRank();
  421. } else {
  422. that.setData({
  423. loading: false,
  424. })
  425. wx.showToast({
  426. title: res.data.msg,
  427. icon: 'none',
  428. duration: 1500
  429. })
  430. }
  431. }
  432. })
  433. },
  434. /**
  435. * 装修推荐官排名列表
  436. */
  437. getBrokerRank() {
  438. if (!App.globalData.brokeruserId) {
  439. return false;
  440. }
  441. let that = this;
  442. utils.$post({
  443. url: App.globalData.webUrl + 'api/agents_work/agent_rank_list',
  444. header: {
  445. 'Authorization': 'bearer ' + App.globalData.token
  446. },
  447. data: {
  448. page: page,
  449. limit: 10,
  450. },
  451. success: function (res) {
  452. if (res.data.code == '0') {
  453. res.data.data = res.data.data.map(v => {
  454. v.type_name = v.type ? v.type.substring(0, 1) : '';
  455. return v;
  456. })
  457. that.setData({
  458. datashow: true,
  459. brokerRanklist: res.data.data
  460. })
  461. if (that.data.brokerRanklist.length) {
  462. if (that.data.brokerRanklist.length > 6) {
  463. that.setData({
  464. swiperData: that.data.brokerRanklist.slice(0, 6)
  465. })
  466. } else {
  467. that.setData({
  468. swiperData: that.data.brokerRanklist
  469. })
  470. }
  471. }
  472. if (that.data.type == 'rank') {
  473. wx.pageScrollTo({ scrollTop: 750 })
  474. }
  475. }
  476. }
  477. })
  478. },
  479. /**
  480. * 生命周期函数--监听页面初次渲染完成
  481. */
  482. onReady() {
  483. },
  484. /**
  485. * 生命周期函数--监听页面显示
  486. */
  487. onShow() {
  488. },
  489. /**
  490. * 生命周期函数--监听页面隐藏
  491. */
  492. onHide() {
  493. },
  494. /**
  495. * 生命周期函数--监听页面卸载
  496. */
  497. onUnload() {
  498. },
  499. /**
  500. * 页面相关事件处理函数--监听用户下拉动作
  501. */
  502. onPullDownRefresh() {
  503. setTimeout(() => {
  504. wx.stopPullDownRefresh();
  505. }, 800)
  506. page = 1;
  507. this.getBrokerRank();
  508. },
  509. /**
  510. * 页面上拉触底事件的处理函数
  511. */
  512. onReachBottom() {
  513. if (this.data.type == 'rank') {
  514. page++;
  515. let that = this;
  516. utils.$post({
  517. url: App.globalData.webUrl + 'api/agents_work/agent_rank_list',
  518. header: {
  519. 'Authorization': 'bearer ' + App.globalData.token
  520. },
  521. data: {
  522. page: page,
  523. limit: 10,
  524. },
  525. success: function (res) {
  526. if (res.data.code == '0') {
  527. res.data.data = res.data.data.map(v => {
  528. v.type_name = v.type ? v.type.substring(0, 1) : '';
  529. return v;
  530. })
  531. let arr = that.data.brokerRanklist.concat(res.data.data);
  532. that.setData({
  533. datashow: true,
  534. brokerRanklist: arr
  535. })
  536. }
  537. }
  538. })
  539. }
  540. },
  541. })