companystrength.js 15 KB

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