praiselist.js 14 KB

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