123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- // 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
- }
- }
- })
|