course.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. // share/pages/course/course.js
  2. var app = getApp();
  3. var utils = require("../../../utils/http");
  4. var time = 0;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. top: app.globalData.statusBarHeight,
  11. hgt: app.globalData.titleBarHeight,
  12. imgUrl: app.globalData.imgUrl,
  13. loginFlag: false,
  14. phoneFlag: false,
  15. dialog: false,
  16. uloading: false,
  17. employeeflag: false,
  18. isAgree: false,
  19. tid: '',
  20. fName: '',
  21. fPhone: '',
  22. webUrl: '',
  23. activeIndex: 1,
  24. companyobj: {},
  25. detailobj: {},
  26. courseArr: []
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad(options) {
  32. if (!!options.cty) {
  33. app.globalData.clientype = options.cty;
  34. }
  35. if (!!options.uid) {
  36. app.globalData.shareuserid = options.uid;
  37. }
  38. if (!!options.tid) {
  39. this.setData({
  40. tid: options.tid
  41. })
  42. }
  43. },
  44. //用户同意隐私协议
  45. agreePrivacy() {
  46. this.setData({
  47. isAgree: true
  48. })
  49. wx.showLoading({
  50. title: '加载中...',
  51. })
  52. this.login();
  53. },
  54. /**
  55. * 分享页授权登录
  56. */
  57. login: function () {
  58. var that = this;
  59. wx.login({
  60. success: function (data) {
  61. if (data.errMsg == 'login:ok') {
  62. utils.$post({
  63. url: app.globalData.webUrl + 'api/users/code2session',
  64. data: {
  65. code: data.code,
  66. share: app.globalData.shareuserid,
  67. client_type: app.globalData.clientype,
  68. },
  69. success: function (r) {
  70. if (r.data.code == '0') {
  71. app.globalData.sharepersonobj = r.data.share;
  72. app.globalData.token = r.data.token;
  73. that.sharecompany();
  74. that.setData({
  75. sharepersonMsg: app.globalData.sharepersonobj,
  76. })
  77. app.globalData.companyname = r.data.company;
  78. if (!!r.data.user.phone) {
  79. that.setData({
  80. loginFlag: false,
  81. phoneFlag: false,
  82. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  83. })
  84. app.globalData.personMsg = r.data.user;
  85. app.globalData.use_id = r.data.user.id;
  86. if (!!r.data.user.binded && r.data.user.binded.state == '在职') {
  87. app.globalData.currentUserId = r.data.user.binded.id;
  88. }
  89. that.getCourseDetail();
  90. } else {
  91. that.getCourseDetail();
  92. that.setData({
  93. loginFlag: false,
  94. phoneFlag: true
  95. })
  96. }
  97. } else {
  98. setTimeout(function () {
  99. wx.hideLoading()
  100. }, 500)
  101. }
  102. }
  103. })
  104. }
  105. }
  106. })
  107. },
  108. /**
  109. * 获取分享的公司信息
  110. */
  111. sharecompany: function () {
  112. const that = this;
  113. utils.$post({
  114. url: app.globalData.webUrl + 'client/index/content_belong_company',
  115. header: {
  116. 'Authorization': 'bearer ' + app.globalData.token
  117. },
  118. data: {
  119. client_type: app.globalData.clientype,
  120. uid: app.globalData.shareuserid
  121. },
  122. success: function (res) {
  123. if (res.data.code == '0') {
  124. app.globalData.companyobj = res.data.data;
  125. app.globalData.sharempid = res.data.data.employee_id;
  126. that.setData({
  127. companyobj: res.data.data
  128. })
  129. }
  130. },
  131. complete(res) {
  132. wx.hideLoading()
  133. }
  134. })
  135. },
  136. /**
  137. * 获取课程详情
  138. */
  139. getCourseDetail() {
  140. const that = this;
  141. utils.$post({
  142. url: app.globalData.webUrl + 'client/train/classDetail',
  143. header: {
  144. 'Authorization': 'bearer ' + app.globalData.token
  145. },
  146. data: {
  147. client_type: app.globalData.clientype,
  148. class_id: that.data.tid,
  149. from: "0",
  150. view: 1,
  151. },
  152. success: function (res) {
  153. if (res.data.code == '0') {
  154. that.setData({
  155. detailobj: res.data.data
  156. })
  157. that.getCourseList();
  158. }
  159. },
  160. complete(res) {
  161. wx.hideLoading()
  162. }
  163. })
  164. },
  165. /**
  166. * 获取课程列表
  167. */
  168. getCourseList() {
  169. const that = this;
  170. utils.$post({
  171. url: app.globalData.webUrl + 'client/train/trainCourseList',
  172. header: {
  173. 'Authorization': 'bearer ' + app.globalData.token
  174. },
  175. data: {
  176. client_type: app.globalData.clientype,
  177. class_id: that.data.tid,
  178. from: "0",
  179. view: 1,
  180. page: 1
  181. },
  182. success: function (res) {
  183. wx.hideLoading();
  184. if (res.data.code == '0') {
  185. that.setData({
  186. courseArr: res.data.data
  187. })
  188. }
  189. },
  190. complete(res) {
  191. wx.hideLoading()
  192. }
  193. })
  194. },
  195. /**
  196. * 返回课程列表页面
  197. */
  198. golastap: function () {
  199. wx.navigateBack({
  200. delta: 1,
  201. success: function (r) { },
  202. fail: function (r) {
  203. wx.reLaunch({
  204. url: '/share/pages/courselist/courselist?cty=' + app.globalData.clientype + '&uid=' + app.globalData.shareuserid,
  205. })
  206. },
  207. })
  208. },
  209. /**
  210. * 返回首页|员工首页
  211. */
  212. goindextap: function () {
  213. if (!this.data.employeeflag) {
  214. wx.reLaunch({
  215. url: '/pages/index/index',
  216. })
  217. } else {
  218. wx.reLaunch({
  219. url: '/pages/consoledesk/consoledesk',
  220. })
  221. }
  222. },
  223. /**
  224. * tab切换
  225. */
  226. switchTab(e) {
  227. let index = e.currentTarget.dataset.index;
  228. this.setData({
  229. activeIndex: index
  230. })
  231. },
  232. signUpFun() {
  233. this.setData({
  234. dialog: true
  235. })
  236. },
  237. dothis() { },
  238. getinputName(e) {
  239. this.setData({
  240. fName: e.detail.value
  241. })
  242. },
  243. getinputPhone(e) {
  244. this.setData({
  245. fPhone: e.detail.value
  246. })
  247. },
  248. hideMaskFunc() {
  249. this.setData({
  250. dialog: false
  251. })
  252. },
  253. //手机号正则验证
  254. isPhoneNum: function (phone) {
  255. var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\d{8})$/;
  256. if (!myreg.test(phone)) {
  257. return false;
  258. }
  259. return true;
  260. },
  261. submitFunc() {
  262. const that = this;
  263. if (!this.isPhoneNum(this.data.fPhone)) {
  264. wx.showToast({
  265. title: '手机号格式错误!',
  266. icon: "none"
  267. })
  268. return false;
  269. }
  270. this.setData({
  271. uloading: true
  272. })
  273. utils.$post({
  274. url: app.globalData.webUrl + 'client/index/signUp',
  275. data: {
  276. name: that.data.fName,
  277. mobile: that.data.fPhone,
  278. id: that.data.tid,
  279. type: 'TrainClass'
  280. },
  281. header: {
  282. 'Authorization': 'bearer ' + app.globalData.token
  283. },
  284. success: function (r) {
  285. that.setData({
  286. uloading: false,
  287. dialog: false,
  288. })
  289. if (r.data.code == '0') {
  290. wx.showToast({
  291. title: '报名成功',
  292. icon: "none",
  293. duration: 1000
  294. })
  295. }
  296. }
  297. })
  298. },
  299. /**
  300. * 查看课件详情
  301. */
  302. viewCourseFun(e) {
  303. let cid = e.currentTarget.dataset.id;
  304. wx.navigateTo({
  305. url: '/share/pages/classdetail/classdetail?tid=' + this.data.tid + '&cid=' + cid + '&cty=' + app.globalData.clientype + '&uid=' + app.globalData.shareuserid,
  306. })
  307. },
  308. /**
  309. * 生命周期函数--监听页面初次渲染完成
  310. */
  311. onReady() {
  312. },
  313. /**
  314. * 生命周期函数--监听页面显示
  315. */
  316. onShow() {
  317. time = 0;
  318. setInterval(() => {
  319. time++;
  320. }, 1000);
  321. },
  322. /**
  323. * 生命周期函数--监听页面隐藏
  324. */
  325. onHide() {
  326. this.visitimefun();
  327. },
  328. /**
  329. * 生命周期函数--监听页面卸载
  330. */
  331. onUnload() {
  332. this.visitimefun();
  333. },
  334. /**
  335. * 浏览时长
  336. */
  337. visitimefun() {
  338. if (!this.data.isAgree) {
  339. return false;
  340. }
  341. const that = this;
  342. utils.$post({
  343. url: app.globalData.webUrl + 'client/index/visit_due_time',
  344. header: {
  345. 'Authorization': 'bearer ' + app.globalData.token
  346. },
  347. data: {
  348. id: that.data.tid,
  349. pipe_type: 'TrainClass',
  350. time: time,
  351. },
  352. success: function (res) { }
  353. })
  354. },
  355. /**
  356. * 页面相关事件处理函数--监听用户下拉动作
  357. */
  358. onPullDownRefresh() {
  359. setTimeout(() => {
  360. wx.stopPullDownRefresh();
  361. }, 1000)
  362. wx.showLoading({
  363. title: '加载中...',
  364. })
  365. this.getCourseDetail();
  366. },
  367. /**
  368. * 页面上拉触底事件的处理函数
  369. */
  370. onReachBottom() {
  371. },
  372. /**
  373. * 用户点击右上角分享
  374. */
  375. onShareAppMessage() {
  376. return {
  377. title: app.globalData.companyobj.company_name + '~培训课程',
  378. imageUrl: '',
  379. path: '/share/pages/course/course?cty=' + app.globalData.clientype + '&uid=' + app.globalData.shareuserid + '&tid=' + this.data.tid
  380. }
  381. }
  382. })