companystrength.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. const app = getApp();
  2. var utils = require("../../../utils/http"), page = 1;
  3. const util = require("../../../utils/util");
  4. let time = 0, timer = null, showflag = true;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. evidencetype: [],
  11. nowtype: '',
  12. evidencelist: [],
  13. leftevidencelist: [],
  14. rightevidencelist: [],
  15. datashow: false,
  16. imgUrl: app.globalData.imgUrl,
  17. loginFlag: false,
  18. phoneFlag: false,
  19. isAgree: false,
  20. canIUseGetUserProfile: false,
  21. shareobj: {},
  22. employeeflag: false,//false是用户,true是员工
  23. top: app.globalData.statusBarHeight,
  24. hgt: app.globalData.titleBarHeight,
  25. companyobj: {},
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. time = 0;
  32. this.setData({
  33. top: app.globalData.statusBarHeight,
  34. hgt: app.globalData.titleBarHeight,
  35. })
  36. if (wx.getUserProfile) {
  37. this.setData({
  38. canIUseGetUserProfile: true
  39. })
  40. }
  41. if (!!options.scene) {
  42. options = unescape(options.scene);
  43. let arr = options.split('&');
  44. let obj = {};
  45. for (let i = 0; i < arr.length; i++) {
  46. let arr1 = arr[i].split('=');
  47. obj[arr1[0]] = arr1[1];
  48. }
  49. app.globalData.shareuserid = obj.uid;
  50. app.globalData.clientype = obj.ctp;
  51. } else {
  52. app.globalData.clientype = options.ctp;
  53. app.globalData.shareuserid = options.uid;
  54. }
  55. },
  56. //用户同意隐私协议
  57. agreePrivacy() {
  58. this.setData({
  59. isAgree: true
  60. })
  61. wx.showLoading({
  62. title: '加载中...',
  63. })
  64. this.login();
  65. },
  66. sharecompany: function () {
  67. const that = this;
  68. utils.$post({
  69. url: app.globalData.webUrl + 'client/index/content_belong_company',
  70. header: {
  71. 'Authorization': 'bearer ' + app.globalData.token
  72. },
  73. data: {
  74. client_type: app.globalData.clientype,
  75. uid: app.globalData.shareuserid
  76. },
  77. success: function (res) {
  78. if (res.data.code == '0') {
  79. app.globalData.companyobj = res.data.data;
  80. that.setData({
  81. companyobj: res.data.data
  82. })
  83. }
  84. },
  85. complete(res) {
  86. wx.hideLoading()
  87. }
  88. })
  89. },
  90. login: function () {
  91. var that = this;
  92. wx.login({
  93. success: function (data) {
  94. if (data.errMsg == 'login:ok') {
  95. utils.$post({
  96. url: app.globalData.webUrl + 'api/users/code2session',
  97. data: {
  98. code: data.code,
  99. share: app.globalData.shareuserid,
  100. client_type: app.globalData.clientype
  101. },
  102. success: function (r) {
  103. if (r.data.code == '0') {
  104. app.globalData.sharepersonobj = r.data.share;
  105. app.globalData.token = r.data.token;
  106. that.setData({
  107. shareobj: app.globalData.sharepersonobj,
  108. })
  109. util.toolfun(7);
  110. that.sharecompany();
  111. that.praisetit();
  112. app.globalData.companyname = r.data.company;
  113. app.globalData.official_openid = r.data.official_openid;
  114. app.globalData.agentEmployeEid = r.data.agent_employee_id;
  115. if (!!r.data.user.phone) {
  116. that.setData({
  117. loginFlag: false,
  118. phoneFlag: false,
  119. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  120. })
  121. if (!!r.data.user.binded && r.data.user.binded.state == '在职') {
  122. app.globalData.currentUserId = r.data.user.binded.id;
  123. }
  124. app.globalData.personMsg = r.data.user;
  125. app.globalData.userflag = false; //有个人信息
  126. var nickname = r.data.user.nickname;
  127. var phone = r.data.user.phone;
  128. app.globalData.phone = false; //没有手机号
  129. that.evidencelistfun();
  130. } else {
  131. that.evidencelistfun();
  132. wx.hideLoading();
  133. that.setData({
  134. loginFlag: false,
  135. phoneFlag: true
  136. })
  137. }
  138. } else {
  139. setTimeout(function () {
  140. wx.hideLoading()
  141. }, 500)
  142. }
  143. }
  144. })
  145. }
  146. }
  147. })
  148. },
  149. prelooktap() {
  150. if (!app.globalData.sharepersonobj.qrcode) {
  151. wx.showToast({
  152. title: "当前专属客服的二维码为空!",
  153. icon: 'none',
  154. duration: 2000
  155. })
  156. return false;
  157. }
  158. wx.previewImage({
  159. current: app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode, // 当前显示图片的http链接
  160. urls: [app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode]// 需要预览的图片http链接列表
  161. })
  162. },
  163. callphonetap: function () {
  164. console.log()
  165. wx.makePhoneCall({
  166. phoneNumber: app.globalData.sharepersonobj.phone //仅为示例,并非真实的电话号码
  167. })
  168. },
  169. praisetit: function () {
  170. var that = this;
  171. utils.$get({
  172. url: app.globalData.webUrl + 'api/company_strength/get_cate',
  173. header: {
  174. 'Authorization': 'bearer ' + app.globalData.token
  175. },
  176. data: {},
  177. success: function (res) {
  178. that.setData({
  179. evidencetype: res.data.data
  180. })
  181. }
  182. })
  183. },
  184. firsttap: function (e) {
  185. this.setData({
  186. nowtype: e.currentTarget.dataset.text
  187. })
  188. this.evidencelistfun();
  189. },
  190. evidencelistfun: function (e) {
  191. var that = this;
  192. page = 1;
  193. wx.showLoading({
  194. title: '加载中...',
  195. })
  196. utils.$get({
  197. url: app.globalData.webUrl + 'client/company_strength/index',
  198. header: {
  199. 'Authorization': 'bearer ' + app.globalData.token
  200. },
  201. data: {
  202. uid: app.globalData.personMsg.id,
  203. page: 1,
  204. cate: that.data.nowtype,
  205. keyword: ''
  206. },
  207. success: function (res) {
  208. setTimeout(function () {
  209. wx.hideLoading()
  210. }, 1000)
  211. if (res.data.code == '0') {
  212. that.setData({
  213. evidencelist: res.data.data,
  214. leftevidencelist: [],
  215. rightevidencelist: [],
  216. datashow: true
  217. })
  218. that.imgload();
  219. }
  220. },
  221. fail() {
  222. wx.hideLoading()
  223. }
  224. })
  225. },
  226. imgload: function () {
  227. var that = this;
  228. var leftlist = that.data.leftevidencelist;
  229. var rightlist = that.data.rightevidencelist;
  230. var indexlist = that.data.evidencelist;
  231. if (indexlist.length == 0) {
  232. return false;
  233. }
  234. if (leftlist.length == 0) {
  235. leftlist.push(indexlist[0]);
  236. indexlist.shift();
  237. that.setData({
  238. evidencelist: indexlist,
  239. leftevidencelist: leftlist,
  240. rightevidencelist: rightlist
  241. })
  242. } else {
  243. var leftheight, rightheight;
  244. const query = wx.createSelectorQuery()
  245. query.select('.leftpublicpraisebox').boundingClientRect();
  246. query.exec(function (res) {
  247. if (res[0]) {
  248. leftheight = res[0].height;
  249. const queryright = wx.createSelectorQuery()
  250. queryright.select('.rightpublicpraisebox').boundingClientRect();
  251. queryright.exec(function (rs) {
  252. leftlist = that.data.leftevidencelist;
  253. rightlist = that.data.rightevidencelist;
  254. indexlist = that.data.evidencelist;
  255. rightheight = rs[0].height;
  256. if (leftheight <= rightheight) {
  257. leftlist.push(indexlist[0]);
  258. indexlist.shift();
  259. } else {
  260. rightlist.push(indexlist[0]);
  261. indexlist.shift();
  262. }
  263. that.setData({
  264. evidencelist: indexlist,
  265. leftevidencelist: leftlist,
  266. rightevidencelist: rightlist
  267. })
  268. })
  269. }
  270. })
  271. }
  272. },
  273. publictap: function (e) {
  274. wx.navigateTo({
  275. url: '/share/pages/companystrengthmsg/companystrengthmsg?type=3&eid=' + e.currentTarget.dataset.eid + "&uid=" + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype
  276. })
  277. },
  278. /**
  279. * 生命周期函数--监听页面初次渲染完成
  280. */
  281. onReady: function () {
  282. },
  283. golastap: function () {
  284. wx.navigateBack({
  285. delta: 1,
  286. success:function(r){
  287. },
  288. fail:function(r){
  289. wx.reLaunch({
  290. url: '/pages/index/index?state=1',
  291. })
  292. },
  293. })
  294. },
  295. goindextap: function () {
  296. if(!this.data.employeeflag){
  297. wx.reLaunch({
  298. url: '/pages/index/index?state=1',
  299. })
  300. }else{
  301. wx.reLaunch({
  302. url: '/pages/consoledesk/consoledesk',
  303. })
  304. }
  305. },
  306. /**
  307. * 生命周期函数--监听页面显示
  308. */
  309. onShow: function () {
  310. this.setData({
  311. top: app.globalData.statusBarHeight,
  312. hgt: app.globalData.titleBarHeight,
  313. })
  314. if (!showflag) {
  315. this.imgload();
  316. }
  317. showflag = true;
  318. timer = setInterval(function () {
  319. time = time * 1 + 1;
  320. }, 1000)
  321. },
  322. /**
  323. * 生命周期函数--监听页面隐藏
  324. */
  325. onHide: function () {
  326. if (timer) {
  327. clearInterval(timer)
  328. }
  329. this.setimetap();
  330. showflag = false;
  331. },
  332. setimetap() {
  333. if (!this.data.isAgree) {
  334. return false;
  335. }
  336. const that = this;
  337. utils.$post({
  338. url: app.globalData.webUrl + 'client/index/visit_due_time',
  339. header: {
  340. 'Authorization': 'bearer ' + app.globalData.token
  341. },
  342. data: {
  343. id: that.data.companyobj.employee_id,
  344. pipe_type: 'toolAll',
  345. time: time,
  346. },
  347. success: function (res) {
  348. }
  349. })
  350. },
  351. /**
  352. * 生命周期函数--监听页面卸载
  353. */
  354. onUnload: function () {
  355. this.setimetap();
  356. },
  357. /**
  358. * 页面相关事件处理函数--监听用户下拉动作
  359. */
  360. onPullDownRefresh: function () {
  361. var that = this;
  362. page = 1;
  363. wx.showLoading({
  364. title: '加载中...',
  365. })
  366. utils.$get({
  367. url: app.globalData.webUrl + 'client/company_strength/index',
  368. header: {
  369. 'Authorization': 'bearer ' + app.globalData.token
  370. },
  371. data: {
  372. uid: app.globalData.personMsg.id,
  373. page: 1,
  374. cate: that.data.nowtype,
  375. keyword: ''
  376. },
  377. success: function (res) {
  378. wx.hideLoading();
  379. wx.stopPullDownRefresh();
  380. if (res.data.code == '0') {
  381. that.setData({
  382. evidencelist: res.data.data,
  383. leftevidencelist: [],
  384. rightevidencelist: [],
  385. datashow: true
  386. })
  387. that.imgload();
  388. }
  389. }
  390. })
  391. },
  392. /**
  393. * 页面上拉触底事件的处理函数
  394. */
  395. onReachBottom: function () {
  396. var that = this;
  397. page = page * 1 + 1;
  398. wx.showLoading({
  399. title: '加载中...',
  400. })
  401. utils.$get({
  402. url: app.globalData.webUrl + 'client/company_strength/index',
  403. header: {
  404. 'Authorization': 'bearer ' + app.globalData.token
  405. },
  406. data: {
  407. uid: app.globalData.personMsg.id,
  408. page: page,
  409. cate: that.data.nowtype,
  410. keyword: ''
  411. },
  412. success: function (res) {
  413. wx.hideLoading();
  414. wx.stopPullDownRefresh();
  415. if (res.data.code == '0') {
  416. let evidencelist = that.data.evidencelist;
  417. var arrflag = false
  418. if (evidencelist.length != 0) {
  419. arrflag = true;
  420. }
  421. for (let i = 0; i < res.data.data.length; i++) {
  422. evidencelist.push(res.data.data[i])
  423. }
  424. that.setData({
  425. evidencelist: evidencelist
  426. })
  427. if (!arrflag) {
  428. that.imgload();
  429. }
  430. }
  431. }
  432. })
  433. },
  434. addsharetap: function (type) {
  435. let that = this;
  436. utils.$post({
  437. url: app.globalData.webUrl + 'api/share/addlog',
  438. header: {
  439. 'Authorization': 'bearer ' + app.globalData.token
  440. },
  441. data: {
  442. id: '0',
  443. type: type,
  444. },
  445. success: function (r) { }
  446. })
  447. },
  448. /**
  449. * 用户点击右上角分享
  450. */
  451. onShareAppMessage: function () {
  452. let that = this;
  453. that.addsharetap('toolAll');
  454. return {
  455. title: "公司实力-" + this.data.companyobj.company_name,
  456. imageUrl: app.globalData.imgUrl + "xcx/strengthcover.png",
  457. path: '/share/pages/companystrength/companystrength?uid=' + app.globalData.shareuserid + '&cate=' + this.data.nowtype + '&ctp=' + app.globalData.clientype
  458. }
  459. }
  460. })