1
0

articleshare.js 22 KB

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