articleshare.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. var app = getApp();
  2. var utils = require("../../../utils/http");
  3. var time = 0;
  4. var timer = null;
  5. var designTimer = null;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. top: app.globalData.statusBarHeight,
  12. hgt: app.globalData.titleBarHeight,
  13. companyName: '',
  14. webUrl: '',
  15. aid: '',
  16. scrollTop: 0,
  17. title: '志远装饰',
  18. showAddress: false,
  19. showAction: false,
  20. loginFlag: false,
  21. phoneFlag: false,
  22. errorflag: false,
  23. errorText: '请求错误!',
  24. oneButton: [{ text: '确定' }],
  25. shareuserid: '',
  26. customerFlag: false,
  27. articleObj: {},
  28. imgUrl: app.globalData.imgUrl,
  29. articlelogin: false,
  30. canIUseGetUserProfile: false,
  31. loadflag: false,
  32. shareobj: {},
  33. employeeflag: false,//false是用户,true是员工
  34. companyobj: {},
  35. priceflag: false,
  36. designPlan: false,
  37. showMask: false,
  38. fPhone: "",
  39. agid: ""
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. var that = this;
  46. time = 0;
  47. if (wx.getUserProfile) {
  48. this.setData({
  49. canIUseGetUserProfile: true
  50. })
  51. }
  52. that.setData({
  53. top: app.globalData.statusBarHeight,
  54. hgt: app.globalData.titleBarHeight,
  55. })
  56. wx.hideHomeButton()
  57. if (!!options.scene) {
  58. options = unescape(options.scene);
  59. let arr = options.split('&');
  60. let obj = {};
  61. for (let i = 0; i < arr.length; i++) {
  62. let arr1 = arr[i].split('=');
  63. obj[arr1[0]] = arr1[1];
  64. }
  65. if (obj.g) {
  66. this.setData({
  67. aid: obj.a,
  68. shareuserid: obj.u,
  69. customerFlag: true,
  70. isBroker: true,
  71. agid: obj.g
  72. })
  73. app.globalData.clientype = obj.c;
  74. app.globalData.shareuserid = obj.u;
  75. app.globalData.brokeruserId = obj.g;
  76. } else {
  77. this.setData({
  78. aid: obj.aid,
  79. shareuserid: obj.userid,
  80. customerFlag: true
  81. })
  82. app.globalData.clientype = obj.ctp;
  83. app.globalData.shareuserid = obj.userid;
  84. }
  85. } else {
  86. this.setData({
  87. aid: options.aid,
  88. shareuserid: options.userid,
  89. customerFlag: true
  90. })
  91. if (!!options.agid) {
  92. this.setData({
  93. isBroker: true,
  94. agid: options.agid
  95. })
  96. app.globalData.brokeruserId = options.agid;
  97. }
  98. app.globalData.clientype = options.ctp;
  99. app.globalData.shareuserid = options.userid;
  100. }
  101. that.login();
  102. },
  103. sharecompany: function () {
  104. const that = this;
  105. utils.$post({
  106. url: app.globalData.webUrl + 'client/index/content_belong_company',
  107. header: {
  108. 'Authorization': 'bearer ' + app.globalData.token
  109. },
  110. data: {
  111. client_type: app.globalData.clientype,
  112. uid: app.globalData.shareuserid
  113. },
  114. success: function (res) {
  115. if (res.data.code == '0') {
  116. app.globalData.currentUserId = res.data.data.employee_id || '';
  117. app.globalData.companyobj=res.data.data;
  118. that.setData({
  119. companyobj: res.data.data
  120. })
  121. }
  122. },
  123. complete(res) {
  124. wx.hideLoading()
  125. }
  126. })
  127. },
  128. login: function () {
  129. var that = this;
  130. wx.login({
  131. success: function (data) {
  132. if (data.errMsg == 'login:ok') {
  133. utils.$post({
  134. url: app.globalData.webUrl + 'api/users/code2sessionmini',
  135. data: {
  136. code: data.code,
  137. share: app.globalData.shareuserid,
  138. client_type:app.globalData.clientype,
  139. share_agent_id: app.globalData.brokeruserId
  140. },
  141. success: function (r) {
  142. if (r.data.code == '0') {
  143. app.globalData.sharepersonobj = r.data.share;
  144. app.globalData.token = r.data.token;
  145. that.sharecompany();
  146. that.setData({
  147. shareobj: app.globalData.sharepersonobj,
  148. companyName: r.data.company
  149. })
  150. app.globalData.personMsg = r.data.user;
  151. app.globalData.companyname=r.data.company;
  152. app.globalData.official_openid = r.data.official_openid;
  153. app.globalData.agentEmployeEid = r.data.agent_employee_id;
  154. if (!!r.data.user.phone) {
  155. that.setData({
  156. fPhone: r.data.user.phone,
  157. loginFlag: false,
  158. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false,
  159. articlelogin: true,
  160. })
  161. if (!!r.data.user.binded && r.data.user.binded.state == '在职'){
  162. app.globalData.currentUserId = r.data.user.binded.id;
  163. }
  164. app.globalData.use_id = r.data.user.id;
  165. app.globalData.phone = true;//有手机号
  166. var obj = {
  167. detail: 1
  168. }
  169. that.artileMsg(obj);
  170. that.setData({
  171. mobileflag: false,
  172. phoneFlag: false,
  173. articlelogin: true
  174. })
  175. } else {
  176. if (app.globalData.clientype != 'IGJFoG') {
  177. that.setData({
  178. mobileflag: true,
  179. phoneFlag: true,
  180. articlelogin: false
  181. })
  182. } else {
  183. that.setData({
  184. articlelogin: true,
  185. loginFlag: false,
  186. })
  187. }
  188. var obj = {
  189. detail: 1
  190. }
  191. that.artileMsg(obj);
  192. }
  193. }
  194. }
  195. })
  196. }
  197. }
  198. })
  199. },
  200. cancelGetPhone() {
  201. designTimer = setTimeout(() => {
  202. this.setData({
  203. designPlan: true
  204. })
  205. },4000)
  206. },
  207. priceshowtap() {
  208. this.setData({
  209. priceflag: true
  210. })
  211. },
  212. closepricetap() {
  213. this.setData({
  214. priceflag: false
  215. })
  216. },
  217. closeDesigntap(e) {
  218. if (designTimer) {
  219. clearTimeout(designTimer);
  220. }
  221. if (e.detail.type == 'success') {
  222. this.setData({
  223. designPlan: false,
  224. articlelogin: true,
  225. phoneFlag: false,
  226. })
  227. } else {
  228. this.setData({
  229. designPlan: false
  230. })
  231. }
  232. },
  233. prelookimgtap() {
  234. if (!app.globalData.sharepersonobj.qrcode) {
  235. wx.showToast({
  236. title: "当前专属客服的二维码为空!",
  237. icon: 'none',
  238. duration: 2000
  239. })
  240. return false;
  241. }
  242. wx.previewImage({
  243. current: app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode, // 当前显示图片的http链接
  244. urls: [app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode]// 需要预览的图片http链接列表
  245. })
  246. },
  247. /**
  248. * 前往个人名片
  249. */
  250. toPageNameCard() {
  251. wx.navigateTo({
  252. url: '/share/pages/shareCard/shareCard?uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.currentUserId + '&ctp=' + app.globalData.clientype + '&ftype=share',
  253. })
  254. },
  255. /**
  256. * 展示地址
  257. */
  258. showAddressName(e) {
  259. let type = e.currentTarget.dataset.type;
  260. if (type == 'hide') {
  261. this.setData({
  262. showAddress: false
  263. })
  264. } else {
  265. this.setData({
  266. showAddress: true
  267. })
  268. }
  269. },
  270. golastap: function () {
  271. // wx.navigateBack()
  272. wx.navigateBack({
  273. delta: 1,
  274. success:function(r){
  275. },
  276. fail:function(r){
  277. wx.reLaunch({
  278. url: '/pages/index/index',
  279. })
  280. },
  281. })
  282. },
  283. goindextap: function () {
  284. if(!this.data.employeeflag){
  285. wx.reLaunch({
  286. url: '/pages/index/index',
  287. })
  288. }else{
  289. wx.reLaunch({
  290. url: '/pages/consoledesk/consoledesk',
  291. })
  292. }
  293. },
  294. /**
  295. * 生命周期函数--监听页面初次渲染完成
  296. */
  297. onReady: function () {
  298. },
  299. artileMsg: function (type) {
  300. var that = this;
  301. wx.showLoading({
  302. title: '加载中...',
  303. })
  304. if (!!type && type.detail == '1') {
  305. that.setData({
  306. articlelogin: true,
  307. phoneFlag: false,
  308. })
  309. }
  310. utils.$post({
  311. url: app.globalData.webUrl + 'client/article/info',
  312. header: {
  313. 'Authorization': 'bearer ' + app.globalData.token
  314. },
  315. data: {
  316. article_id: that.data.aid
  317. },
  318. success: function (res) {
  319. if (res.data.code == '0') {
  320. var article = '';
  321. article = res.data.data.content;
  322. res.data.data.contentmsg = article;
  323. that.setData({
  324. articleObj: res.data.data,
  325. loadflag: true,
  326. title: res.data.data.title
  327. })
  328. }
  329. setTimeout(function () {
  330. wx.hideLoading();
  331. }, 500)
  332. }
  333. })
  334. },
  335. callphonetap: function () {
  336. wx.makePhoneCall({
  337. phoneNumber: app.globalData.sharepersonobj.phone
  338. })
  339. },
  340. lookarticlemsg() {
  341. let articleObj = this.data.articleObj;
  342. articleObj.contentmsg = articleObj.content;
  343. this.setData({
  344. articleObj: articleObj
  345. })
  346. },
  347. loginfun() {
  348. var that = this;
  349. wx.login({
  350. success: function (data) {
  351. if (data.errMsg == 'login:ok') {
  352. utils.$post({
  353. url: app.globalData.webUrl + 'api/users/code2sessionmini',
  354. data: {
  355. code: data.code,
  356. share: app.globalData.shareuserid,
  357. client_type:app.globalData.clientype
  358. },
  359. success: function (r) {
  360. if (r.data.code == '0') {
  361. app.globalData.sharepersonobj = r.data.share;
  362. app.globalData.token = r.data.token;
  363. if (r.data.user != null && (!!r.data.user.headimgurl && r.data.user.headimgurl != "" || !!r.data.user.nickname && r.data.user.nickname != "")) {
  364. that.setData({
  365. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  366. })
  367. app.globalData.personMsg = r.data.user;
  368. app.globalData.use_id = r.data.user.id;
  369. app.globalData.userflag = false;//有个人信息
  370. if (r.data.user.phone == '') {
  371. designTimer = setTimeout(() => {
  372. that.setData({
  373. designPlan: true
  374. })
  375. },4000)
  376. }
  377. }
  378. }
  379. }
  380. })
  381. }
  382. }
  383. })
  384. },
  385. getUserInfoTap: function (res) {
  386. var that = this;
  387. wx.showLoading();
  388. if (res.detail.errMsg == 'getUserInfo:ok') {
  389. utils.$post({
  390. method: "POST",//TESTAPIURL APIURL/users/auth
  391. url: app.globalData.webUrl + 'api/users/setUserInfo',
  392. data: {
  393. encryptedData: res.detail.encryptedData,
  394. iv: res.detail.iv,
  395. rawData: res.detail.rawData,
  396. signature: res.detail.signature,
  397. },
  398. header: {
  399. 'Authorization': 'bearer ' + app.globalData.token
  400. },
  401. success: function (r) {
  402. if (r.data.code == '0') {
  403. that.loginfun();
  404. that.setData({
  405. loginFlag: false,
  406. phoneFlag: false
  407. })
  408. app.globalData.userflag = true;//有个人信息
  409. } else {
  410. if (r.data.code == '403') {
  411. that.login();
  412. return false
  413. }
  414. wx.showToast({
  415. title: r.data.msg,
  416. icon: "none",
  417. duration: 2000
  418. });
  419. }
  420. }
  421. })
  422. }
  423. },
  424. getUserProfile: function () {
  425. var that = this;
  426. wx.getUserProfile({
  427. lang: 'zh_CN',
  428. desc: '为了更好的体验申请获取以下信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  429. success: (res) => {
  430. if (res.errMsg == "getUserProfile:ok") {
  431. wx.showLoading();
  432. utils.$post({
  433. method: "POST",//TESTAPIURL APIURL/users/auth
  434. url: app.globalData.webUrl + 'api/users/setUserInfo',
  435. data: {
  436. encryptedData: res.encryptedData,
  437. iv: res.iv,
  438. rawData: res.rawData,
  439. signature: res.signature,
  440. },
  441. header: {
  442. 'Authorization': 'bearer ' + app.globalData.token
  443. },
  444. success: function (r) {
  445. setTimeout(res => {
  446. wx.hideLoading()
  447. }, 500)
  448. if (r.data.code == '0') {
  449. that.loginfun();
  450. that.setData({
  451. loginFlag: false,
  452. phoneFlag: false
  453. })
  454. app.globalData.userflag = true;//有个人信息
  455. } else {
  456. if (r.data.code == '403') {
  457. that.login();
  458. return false
  459. }
  460. wx.showToast({
  461. title: r.data.msg,
  462. icon: "none",
  463. duration: 2000
  464. });
  465. }
  466. }
  467. })
  468. }
  469. }
  470. })
  471. },
  472. hiddenMaskFunc() {
  473. this.setData({
  474. showMask: false
  475. })
  476. },
  477. getPhoneNumberTap: function (res) {
  478. var that = this;
  479. let type = res.currentTarget.dataset.type;
  480. if (res.detail.errMsg == 'getPhoneNumber:ok') {
  481. if (type != 'broker') {
  482. if (designTimer) {
  483. clearTimeout(designTimer);
  484. }
  485. that.lookarticlemsg();
  486. that.setData({
  487. articlelogin: true,
  488. phoneFlag: false,
  489. designPlan: false
  490. })
  491. }
  492. utils.$post({
  493. url: app.globalData.webUrl + 'api/users/setUserMobile',
  494. data: {
  495. encryptedData: res.detail.encryptedData,
  496. iv: res.detail.iv
  497. },
  498. header: {
  499. 'Authorization': 'bearer ' + app.globalData.token
  500. },
  501. success: function (r) {
  502. if (r.data.code == '0') {
  503. that.setData({
  504. fPhone: r.data.mobile,
  505. })
  506. app.globalData.phone = true;
  507. if (type == 'broker') {
  508. that.setData({
  509. showMask: true
  510. })
  511. return false;
  512. }
  513. that.setData({
  514. mobileflag: false,
  515. phoneFlag: false,
  516. webUrl: app.globalData.webUrl,
  517. articlelogin: true
  518. })
  519. } else {
  520. that.setData({
  521. errorText: r.data.msg,
  522. errorflag: true
  523. })
  524. }
  525. }
  526. })
  527. } else {
  528. this.setData({
  529. showMask: true
  530. })
  531. }
  532. },
  533. tapDialogButton(){
  534. this.setData({
  535. errorflag:false
  536. })
  537. wx.exitMiniProgram()
  538. wx.navigateBack({
  539. delta: 0
  540. })
  541. },
  542. /**
  543. * 生命周期函数--监听页面显示
  544. */
  545. onShow: function () {
  546. this.setData({
  547. top: app.globalData.statusBarHeight,
  548. hgt: app.globalData.titleBarHeight,
  549. })
  550. timer = setInterval(function () {
  551. time = (time * 1) + 1;
  552. }, 1000)
  553. },
  554. /**
  555. * 生命周期函数--监听页面隐藏
  556. */
  557. onHide: function () {
  558. if (timer) {
  559. clearInterval(timer);
  560. }
  561. this.visitimefun();
  562. },
  563. visitimefun() {
  564. const that = this;
  565. utils.$post({
  566. url: app.globalData.webUrl + 'client/index/visit_due_time',
  567. header: {
  568. 'Authorization': 'bearer ' + app.globalData.token
  569. },
  570. data: {
  571. id: that.data.aid,
  572. pipe_type: 'article',
  573. time: time,
  574. },
  575. success: function (res) {
  576. }
  577. })
  578. },
  579. operateBtn() {
  580. this.setData({
  581. showAction: false
  582. })
  583. },
  584. sharelogtap: function () {
  585. var that = this;
  586. utils.$post({
  587. url: app.globalData.webUrl + 'api/share/addlog',
  588. header: {
  589. 'Authorization': 'bearer ' + app.globalData.token
  590. },
  591. data: {
  592. id: that.data.aid,
  593. type: 'article'
  594. },
  595. success: function (r) {}
  596. })
  597. },
  598. /**
  599. * 生命周期函数--监听页面卸载
  600. */
  601. onUnload: function () {
  602. this.visitimefun();
  603. },
  604. /**
  605. * 页面相关事件处理函数--监听用户下拉动作
  606. */
  607. onPullDownRefresh: function () {
  608. },
  609. /**
  610. * 页面上拉触底事件的处理函数
  611. */
  612. onReachBottom: function () {
  613. },
  614. /**
  615. * 用户点击右上角分享
  616. */
  617. onShareAppMessage: function () {
  618. this.sharelogtap();
  619. if (app.globalData.brokeruserId) {
  620. return {
  621. title: this.data.title,
  622. imageUrl: this.data.articleObj.cover_share_img?this.data.articleObj.cover_share_img:this.data.articleObj.cover_img,
  623. path: '/share/pages/articleshare/articleshare?aid=' + this.data.aid + '&userid=' + this.data.shareuserid + '&ctp=' + app.globalData.clientype + '&agid=' + app.globalData.brokeruserId
  624. }
  625. } else {
  626. return {
  627. title: this.data.title,
  628. imageUrl: this.data.articleObj.cover_share_img?this.data.articleObj.cover_share_img:this.data.articleObj.cover_img,
  629. path: '/share/pages/articleshare/articleshare?aid=' + this.data.aid + '&userid=' + this.data.shareuserid + '&ctp=' + app.globalData.clientype
  630. }
  631. }
  632. }
  633. })