// share/pages/course/course.js var app = getApp(); var utils = require("../../../utils/http"); var time = 0; Page({ /** * 页面的初始数据 */ data: { top: app.globalData.statusBarHeight, hgt: app.globalData.titleBarHeight, imgUrl: app.globalData.imgUrl, loginFlag: false, phoneFlag: false, dialog: false, uloading: false, employeeflag: false, tid: '', fName: '', fPhone: '', webUrl: '', activeIndex: 1, companyobj: {}, detailobj: {}, courseArr: [] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (!!options.cty) { app.globalData.clientype = options.cty; } if (!!options.uid) { app.globalData.shareuserid = options.uid; } if (!!options.tid) { this.setData({ tid: options.tid }) } wx.showLoading({ title: '加载中...', }) this.login(); }, /** * 分享页授权登录 */ login: function () { var that = this; wx.login({ success: function (data) { if (data.errMsg == 'login:ok') { utils.$post({ url: app.globalData.webUrl + 'api/users/code2sessionmini', data: { code: data.code, share: app.globalData.shareuserid, client_type: app.globalData.clientype, }, success: function (r) { if (r.data.code == '0') { app.globalData.sharepersonobj = r.data.share; app.globalData.token = r.data.token; that.sharecompany(); that.setData({ sharepersonMsg: app.globalData.sharepersonobj, }) app.globalData.companyname = r.data.company; if (!!r.data.user.phone) { that.setData({ loginFlag: false, phoneFlag: false, employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false }) app.globalData.personMsg = r.data.user; app.globalData.use_id = r.data.user.id; if (!!r.data.user.binded && r.data.user.binded.state == '在职') { app.globalData.currentUserId = r.data.user.binded.id; } that.getCourseDetail(); } else { that.getCourseDetail(); that.setData({ loginFlag: false, phoneFlag: true }) } } else { setTimeout(function () { wx.hideLoading() }, 500) } } }) } } }) }, /** * 获取分享的公司信息 */ sharecompany: function () { const that = this; utils.$post({ url: app.globalData.webUrl + 'client/index/content_belong_company', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { client_type: app.globalData.clientype, uid: app.globalData.shareuserid }, success: function (res) { if (res.data.code == '0') { app.globalData.companyobj = res.data.data; app.globalData.sharempid = res.data.data.employee_id; that.setData({ companyobj: res.data.data }) } }, complete(res) { wx.hideLoading() } }) }, /** * 获取课程详情 */ getCourseDetail() { const that = this; utils.$post({ url: app.globalData.webUrl + 'client/train/classDetail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { client_type: app.globalData.clientype, class_id: that.data.tid, from: "0", view: 1, }, success: function (res) { if (res.data.code == '0') { that.setData({ detailobj: res.data.data }) that.getCourseList(); } }, complete(res) { wx.hideLoading() } }) }, /** * 获取课程列表 */ getCourseList() { const that = this; utils.$post({ url: app.globalData.webUrl + 'client/train/trainCourseList', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { client_type: app.globalData.clientype, class_id: that.data.tid, from: "0", view: 1, page: 1 }, success: function (res) { wx.hideLoading(); if (res.data.code == '0') { that.setData({ courseArr: res.data.data }) } }, complete(res) { wx.hideLoading() } }) }, /** * 返回课程列表页面 */ golastap: function () { wx.navigateBack({ delta: 1, success: function (r) { }, fail: function (r) { wx.reLaunch({ url: '/share/pages/courselist/courselist?cty=' + app.globalData.clientype + '&uid=' + app.globalData.shareuserid, }) }, }) }, /** * 返回首页|员工首页 */ goindextap: function () { if (!this.data.employeeflag) { wx.reLaunch({ url: '/pages/index/index', }) } else { wx.reLaunch({ url: '/pages/consoledesk/consoledesk', }) } }, /** * tab切换 */ switchTab(e) { let index = e.currentTarget.dataset.index; this.setData({ activeIndex: index }) }, signUpFun() { this.setData({ dialog: true }) }, dothis() { }, getinputName(e) { this.setData({ fName: e.detail.value }) }, getinputPhone(e) { this.setData({ fPhone: e.detail.value }) }, hideMaskFunc() { this.setData({ dialog: false }) }, //手机号正则验证 isPhoneNum: function (phone) { 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})$/; if (!myreg.test(phone)) { return false; } return true; }, submitFunc() { const that = this; if (!this.isPhoneNum(this.data.fPhone)) { wx.showToast({ title: '手机号格式错误!', icon: "none" }) return false; } this.setData({ uloading: true }) utils.$post({ url: app.globalData.webUrl + 'client/index/signUp', data: { name: that.data.fName, mobile: that.data.fPhone, id: that.data.tid, type: 'TrainClass' }, header: { 'Authorization': 'bearer ' + app.globalData.token }, success: function (r) { that.setData({ uloading: false, dialog: false, }) if (r.data.code == '0') { wx.showToast({ title: '报名成功', icon: "none", duration: 1000 }) } } }) }, /** * 查看课件详情 */ viewCourseFun(e) { let cid = e.currentTarget.dataset.id; wx.navigateTo({ url: '/share/pages/classdetail/classdetail?tid=' + this.data.tid + '&cid=' + cid + '&cty=' + app.globalData.clientype + '&uid=' + app.globalData.shareuserid, }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { time = 0; setInterval(() => { time++; }, 1000); }, /** * 生命周期函数--监听页面隐藏 */ onHide() { this.visitimefun(); }, /** * 生命周期函数--监听页面卸载 */ onUnload() { this.visitimefun(); }, /** * 浏览时长 */ visitimefun() { const that = this; utils.$post({ url: app.globalData.webUrl + 'client/index/visit_due_time', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.tid, pipe_type: 'TrainClass', time: time, }, success: function (res) { } }) }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { setTimeout(() => { wx.stopPullDownRefresh(); }, 1000) wx.showLoading({ title: '加载中...', }) this.getCourseDetail(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { return { title: app.globalData.companyobj.company_name + '~培训课程', imageUrl: '', path: '/share/pages/course/course?cty=' + app.globalData.clientype + '&uid=' + app.globalData.shareuserid + '&tid=' + this.data.tid } } })