articleshare.js 22 KB

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