praiselist.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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(3);
  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. } else {
  126. that.setData({
  127. loginFlag: false,
  128. phoneFlag: true
  129. })
  130. wx.hideLoading();
  131. }
  132. that.evidencelistfun();
  133. } else {
  134. setTimeout(function () {
  135. wx.hideLoading()
  136. }, 500)
  137. }
  138. }
  139. })
  140. }
  141. }
  142. })
  143. },
  144. prelooktap() {
  145. if (!app.globalData.sharepersonobj.qrcode) {
  146. wx.showToast({
  147. title: "当前专属客服的二维码为空!",
  148. icon: 'none',
  149. duration: 2000
  150. })
  151. return false;
  152. }
  153. wx.previewImage({
  154. current: app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode, // 当前显示图片的http链接
  155. urls: [app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode]// 需要预览的图片http链接列表
  156. })
  157. },
  158. callphonetap: function () {
  159. console.log()
  160. wx.makePhoneCall({
  161. phoneNumber: app.globalData.sharepersonobj.phone //仅为示例,并非真实的电话号码
  162. })
  163. },
  164. praisetit: function () {
  165. var that = this;
  166. utils.$get({
  167. url: app.globalData.webUrl + 'api/evidencecate',
  168. header: {
  169. 'Authorization': 'bearer ' + app.globalData.token
  170. },
  171. data: {},
  172. success: function (res) {
  173. that.setData({
  174. evidencetype: res.data.data
  175. })
  176. }
  177. })
  178. },
  179. firsttap: function (e) {
  180. this.setData({
  181. nowtype: e.currentTarget.dataset.text
  182. })
  183. this.evidencelistfun();
  184. },
  185. evidencelistfun: function (e) {
  186. var that = this;
  187. page = 1;
  188. wx.showLoading({
  189. title: '加载中...',
  190. })
  191. utils.$get({
  192. url: app.globalData.webUrl + 'client/material/evidencelist',
  193. header: {
  194. 'Authorization': 'bearer ' + app.globalData.token
  195. },
  196. data: {
  197. uid: app.globalData.personMsg.id,
  198. page: 1,
  199. cate: that.data.nowtype,
  200. keyword: ''
  201. },
  202. success: function (res) {
  203. setTimeout(function () {
  204. wx.hideLoading()
  205. }, 1000)
  206. if (res.data.code == '0') {
  207. that.setData({
  208. evidencelist: res.data.data,
  209. leftevidencelist: [],
  210. rightevidencelist: [],
  211. datashow: true
  212. })
  213. that.imgload();
  214. }
  215. },
  216. fail() {
  217. wx.hideLoading()
  218. }
  219. })
  220. },
  221. imgload: function () {
  222. var that = this;
  223. var leftlist = that.data.leftevidencelist;
  224. var rightlist = that.data.rightevidencelist;
  225. var indexlist = that.data.evidencelist;
  226. if (indexlist.length == 0) {
  227. return false;
  228. }
  229. if (leftlist.length == 0) {
  230. leftlist.push(indexlist[0]);
  231. indexlist.shift();
  232. that.setData({
  233. evidencelist: indexlist,
  234. leftevidencelist: leftlist,
  235. rightevidencelist: rightlist
  236. })
  237. } else {
  238. var leftheight, rightheight;
  239. const query = wx.createSelectorQuery()
  240. query.select('.leftpublicpraisebox').boundingClientRect();
  241. query.exec(function (res) {
  242. if (res[0]) {
  243. leftheight = res[0].height;
  244. const queryright = wx.createSelectorQuery()
  245. queryright.select('.rightpublicpraisebox').boundingClientRect();
  246. queryright.exec(function (rs) {
  247. leftlist = that.data.leftevidencelist;
  248. rightlist = that.data.rightevidencelist;
  249. indexlist = that.data.evidencelist;
  250. rightheight = rs[0].height;
  251. if (leftheight <= rightheight) {
  252. leftlist.push(indexlist[0]);
  253. indexlist.shift();
  254. } else {
  255. rightlist.push(indexlist[0]);
  256. indexlist.shift();
  257. }
  258. that.setData({
  259. evidencelist: indexlist,
  260. leftevidencelist: leftlist,
  261. rightevidencelist: rightlist
  262. })
  263. })
  264. }
  265. })
  266. }
  267. },
  268. publictap: function (e) {
  269. wx.navigateTo({
  270. url: '/share/pages/publicpraisemsg/publicpraisemsg?type=3&eid=' + e.currentTarget.dataset.eid + "&uid=" + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype
  271. })
  272. },
  273. /**
  274. * 生命周期函数--监听页面初次渲染完成
  275. */
  276. onReady: function () {
  277. },
  278. golastap: function () {
  279. wx.navigateBack({
  280. delta: 1,
  281. success:function(r){
  282. },
  283. fail:function(r){
  284. wx.reLaunch({
  285. url: '/pages/index/index?state=1',
  286. })
  287. },
  288. })
  289. },
  290. goindextap: function () {
  291. if(!this.data.employeeflag){
  292. wx.reLaunch({
  293. url: '/pages/index/index?state=1',
  294. })
  295. }else{
  296. wx.reLaunch({
  297. url: '/pages/consoledesk/consoledesk',
  298. })
  299. }
  300. },
  301. /**
  302. * 生命周期函数--监听页面显示
  303. */
  304. onShow: function () {
  305. this.setData({
  306. top: app.globalData.statusBarHeight,
  307. hgt: app.globalData.titleBarHeight,
  308. })
  309. if (!showflag) {
  310. this.imgload();
  311. }
  312. showflag = true;
  313. timer = setInterval(function () {
  314. time = time * 1 + 1;
  315. }, 1000)
  316. },
  317. setimetap() {
  318. if (!this.data.isAgree) {
  319. return false;
  320. }
  321. const that = this;
  322. utils.$post({
  323. url: app.globalData.webUrl + 'client/index/visit_due_time',
  324. header: {
  325. 'Authorization': 'bearer ' + app.globalData.token
  326. },
  327. data: {
  328. id: that.data.companyobj.employee_id,
  329. pipe_type: 'toolAll',
  330. time: time,
  331. },
  332. success: function (res) {
  333. }
  334. })
  335. },
  336. /**
  337. * 生命周期函数--监听页面隐藏
  338. */
  339. onHide: function () {
  340. showflag = false;
  341. if (timer) {
  342. clearInterval(timer)
  343. }
  344. this.setimetap();
  345. },
  346. /**
  347. * 生命周期函数--监听页面卸载
  348. */
  349. onUnload: function () {
  350. this.setimetap();
  351. },
  352. /**
  353. * 页面相关事件处理函数--监听用户下拉动作
  354. */
  355. onPullDownRefresh: function () {
  356. var that = this;
  357. page = 1;
  358. wx.showLoading({
  359. title: '加载中...',
  360. })
  361. utils.$get({
  362. url: app.globalData.webUrl + 'client/material/evidencelist',
  363. header: {
  364. 'Authorization': 'bearer ' + app.globalData.token
  365. },
  366. data: {
  367. uid: app.globalData.personMsg.id,
  368. page: 1,
  369. cate: that.data.nowtype,
  370. keyword: ''
  371. },
  372. success: function (res) {
  373. wx.hideLoading();
  374. wx.stopPullDownRefresh();
  375. if (res.data.code == '0') {
  376. that.setData({
  377. evidencelist: res.data.data,
  378. leftevidencelist: [],
  379. rightevidencelist: [],
  380. datashow: true
  381. })
  382. that.imgload();
  383. }
  384. }
  385. })
  386. },
  387. /**
  388. * 页面上拉触底事件的处理函数
  389. */
  390. onReachBottom: function () {
  391. var that = this;
  392. page = page * 1 + 1;
  393. wx.showLoading({
  394. title: '加载中...',
  395. })
  396. utils.$get({
  397. url: app.globalData.webUrl + 'client/material/evidencelist',
  398. header: {
  399. 'Authorization': 'bearer ' + app.globalData.token
  400. },
  401. data: {
  402. uid: app.globalData.personMsg.id,
  403. page: page,
  404. cate: that.data.nowtype,
  405. keyword: ''
  406. },
  407. success: function (res) {
  408. wx.hideLoading();
  409. wx.stopPullDownRefresh();
  410. if (res.data.code == '0') {
  411. let evidencelist = that.data.evidencelist;
  412. var arrflag = false
  413. if (evidencelist.length != 0) {
  414. arrflag = true;
  415. }
  416. for (let i = 0; i < res.data.data.length; i++) {
  417. evidencelist.push(res.data.data[i])
  418. }
  419. that.setData({
  420. evidencelist: evidencelist
  421. })
  422. if (!arrflag) {
  423. that.imgload();
  424. }
  425. }
  426. }
  427. })
  428. },
  429. addsharetap: function (type) {
  430. let that = this;
  431. utils.$post({
  432. url: app.globalData.webUrl + 'api/share/addlog',
  433. header: {
  434. 'Authorization': 'bearer ' + app.globalData.token
  435. },
  436. data: {
  437. id: '0',
  438. type: type,
  439. },
  440. success: function (r) { }
  441. })
  442. },
  443. /**
  444. * 用户点击右上角分享
  445. */
  446. onShareAppMessage: function () {
  447. let that = this;
  448. that.addsharetap('toolAll');
  449. return {
  450. title: "客户好评-" + this.data.companyobj.company_name,
  451. imageUrl: app.globalData.imgUrl + "xcx/praiseimg.jpg",
  452. path: '/share/pages/praiselist/praiselist?uid=' + app.globalData.shareuserid + '&cate=' + this.data.nowtype + '&ctp=' + app.globalData.clientype
  453. }
  454. }
  455. })