course.js 11 KB

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