brokerindex.js 16 KB

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