1
0

classdetail.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // share/pages/classdetail/classdetail.js
  2. var app = getApp();
  3. var utils = require("../../../utils/http");
  4. var time = 0;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. loginFlag: false,
  11. phoneFlag:false,
  12. employeeflag: false,
  13. isAgree: false,
  14. tid: '',
  15. cid: '',
  16. webUrl: '',
  17. companyobj: {}
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad(options) {
  23. wx.hideHomeButton();
  24. if (!!options.cty) {
  25. app.globalData.clientype = options.cty;
  26. }
  27. if (!!options.uid) {
  28. app.globalData.shareuserid = options.uid;
  29. }
  30. if (!!options.tid) {
  31. this.setData({
  32. tid: options.tid
  33. })
  34. }
  35. if (!!options.cid) {
  36. this.setData({
  37. cid: options.cid
  38. })
  39. }
  40. },
  41. //用户同意隐私协议
  42. agreePrivacy() {
  43. this.setData({
  44. isAgree: true
  45. })
  46. wx.showLoading({
  47. title: '加载中...',
  48. })
  49. this.login();
  50. },
  51. /**
  52. * 分享页授权登录
  53. */
  54. login: function () {
  55. var that = this;
  56. wx.login({
  57. success: function (data) {
  58. if (data.errMsg == 'login:ok') {
  59. utils.$post({
  60. url: app.globalData.webUrl + 'api/users/code2session',
  61. data: {
  62. code: data.code,
  63. share: app.globalData.shareuserid,
  64. client_type: app.globalData.clientype,
  65. },
  66. success: function (r) {
  67. if (r.data.code == '0') {
  68. app.globalData.sharepersonobj = r.data.share;
  69. app.globalData.token = r.data.token;
  70. that.sharecompany();
  71. that.setData({
  72. sharepersonMsg: app.globalData.sharepersonobj,
  73. })
  74. app.globalData.companyname=r.data.company;
  75. if (!!r.data.user.phone) {
  76. that.setData({
  77. loginFlag: false,
  78. phoneFlag: false,
  79. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  80. })
  81. app.globalData.personMsg = r.data.user;
  82. app.globalData.use_id = r.data.user.id;
  83. if (!!r.data.user.binded && r.data.user.binded.state == '在职'){
  84. app.globalData.currentUserId = r.data.user.binded.id;
  85. }
  86. wx.hideLoading();
  87. that.setWebViewlink();
  88. } else {
  89. wx.hideLoading();
  90. that.setData({
  91. loginFlag: false,
  92. phoneFlag: true
  93. })
  94. }
  95. } else {
  96. setTimeout(function () {
  97. wx.hideLoading()
  98. }, 500)
  99. }
  100. }
  101. })
  102. }
  103. }
  104. })
  105. },
  106. /**
  107. * 获取分享的公司信息
  108. */
  109. sharecompany: function () {
  110. const that = this;
  111. utils.$post({
  112. url: app.globalData.webUrl + 'client/index/content_belong_company',
  113. header: {
  114. 'Authorization': 'bearer ' + app.globalData.token
  115. },
  116. data: {
  117. client_type: app.globalData.clientype,
  118. uid: app.globalData.shareuserid
  119. },
  120. success: function (res) {
  121. if (res.data.code == '0') {
  122. app.globalData.companyobj=res.data.data;
  123. app.globalData.sharempid = res.data.data.employee_id;
  124. that.setData({
  125. companyobj: res.data.data
  126. })
  127. }
  128. },
  129. complete(res) {
  130. wx.hideLoading()
  131. }
  132. })
  133. },
  134. /**
  135. * 设置webview链接
  136. */
  137. setWebViewlink() {
  138. this.setData({
  139. webUrl: app.globalData.webUrl + 'applet.html#/shareCourse?token=' + app.globalData.token + '&client_type=' + app.globalData.clientype + '&tid='+this.data.tid+'&cid='+this.data.cid + '&btype=1',
  140. })
  141. },
  142. /**
  143. * 生命周期函数--监听页面初次渲染完成
  144. */
  145. onReady() {
  146. },
  147. /**
  148. * 生命周期函数--监听页面显示
  149. */
  150. onShow() {
  151. time = 0;
  152. setInterval(() => {
  153. time++;
  154. }, 1000);
  155. },
  156. /**
  157. * 生命周期函数--监听页面隐藏
  158. */
  159. onHide() {
  160. this.visitimefun();
  161. },
  162. /**
  163. * 生命周期函数--监听页面卸载
  164. */
  165. onUnload() {
  166. this.visitimefun();
  167. },
  168. /**
  169. * 浏览时长
  170. */
  171. visitimefun() {
  172. if (!this.data.isAgree) {
  173. return false;
  174. }
  175. const that = this;
  176. utils.$post({
  177. url: app.globalData.webUrl + 'client/index/visit_due_time',
  178. header: {
  179. 'Authorization': 'bearer ' + app.globalData.token
  180. },
  181. data: {
  182. id: that.data.cid,
  183. pipe_type: 'TrainCourse',
  184. time: time,
  185. },
  186. success: function (res) { }
  187. })
  188. },
  189. /**
  190. * 页面相关事件处理函数--监听用户下拉动作
  191. */
  192. onPullDownRefresh() {
  193. },
  194. /**
  195. * 页面上拉触底事件的处理函数
  196. */
  197. onReachBottom() {
  198. },
  199. /**
  200. * 用户点击右上角分享
  201. */
  202. onShareAppMessage() {
  203. return {
  204. title: app.globalData.companyobj.company_name + '~培训课程',
  205. imageUrl: '',
  206. path: '/share/pages/course/course?cty='+app.globalData.clientype+'&uid='+app.globalData.shareuserid + '&tid=' + this.data.tid
  207. }
  208. }
  209. })