basicTraining.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <view>
  3. <image class="bg" src="../../static/img/basicTraining-bg.png" mode="widthFix"></image>
  4. <u-tabs ref="btabs" :list="tabs" :is-scroll="false" :current="tabIndex" @change="tabChange"></u-tabs>
  5. <onlineTraining v-show="tabIndex=='0'" :key="1" :onlineData="onlineData" :rate="rate"></onlineTraining>
  6. <offlineTraining v-show="tabIndex=='1'" :key="2" :offlineId="offlineId"></offlineTraining>
  7. </view>
  8. </template>
  9. <script>
  10. import onlineTraining from './components/online.vue';
  11. import offlineTraining from './components/offline.vue';
  12. export default{
  13. components:{
  14. onlineTraining,
  15. offlineTraining
  16. },
  17. data(){
  18. return{
  19. tabs: [{name: '培训课程'},{name:'线下培训'}],
  20. tabIndex: 0 ,// tab下标
  21. onlineData:[],
  22. rate:{},
  23. offlineId:'',
  24. analysisParams:{
  25. platform:'1',//平台:1-H5 2-APP 3-小程序 4-PC端
  26. pages:location.href,//页面路径
  27. btnName:'',//按钮名称
  28. btnEvent:'1',//按钮事件: 1-点击 2-长按 3-滑动
  29. ipAddress:'',//IP地址
  30. typeName:'适应性培训',//类型名称 例:学校关注度 、适应性考试等
  31. typeCode:'',//类型编码 例:类型名称首字母缩写(XXGZD)
  32. categoryName:'',//类别名称 例:XX学校,SS考试
  33. }
  34. }
  35. },
  36. onLoad(page){
  37. if(page?.type=='offline'){
  38. this.tabIndex = 1;
  39. if(page.id){
  40. this.offlineId = page.id;
  41. console.log('this.offlineId',this.offlineId)
  42. }
  43. };
  44. },
  45. onShow(){
  46. this.getAdaptTrainOnline();
  47. this.getAdaptTrainOnlineRate();
  48. },
  49. mounted() {
  50. this.postAnalysis();
  51. },
  52. methods:{
  53. getip(){
  54. let that = this;
  55. uni.request({
  56. url:'/apis/cityjson?ie=utf-8',
  57. method:'GET',
  58. success: (res) => {
  59. // console.log('this',this);
  60. const reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
  61. let ip = reg.exec(res.data);
  62. that.analysisParams.ipAddress = ip[0];
  63. console.log('analysisParams',this.analysisParams);
  64. }
  65. });
  66. },
  67. async postAnalysis(){
  68. await this.getip();
  69. this.$u.api.postAnalysis(this.analysisParams).then(res=>{
  70. console.log('res',res);
  71. });
  72. },
  73. // 切换菜单
  74. tabChange(index) {
  75. console.log('tabChange index',index)
  76. this.tabIndex = index;
  77. },
  78. getAdaptTrainOnline(){
  79. this.$u.api.getAdaptTrainOnline().then(res=>{
  80. if(res.code == 200){
  81. this.onlineData = res.data;
  82. }else{
  83. uni.showToast({
  84. icon:'none',
  85. title:res.msg
  86. })
  87. }
  88. console.log('getAdaptTrainOnline',JSON.parse(JSON.stringify(res)));
  89. })
  90. },
  91. getAdaptTrainOnlineRate(){
  92. this.$u.api.getAdaptTrainOnlineRate().then(res=>{
  93. this.rate = res.data;
  94. console.log('getAdaptTrainOnlineRate',JSON.parse(JSON.stringify(res)));
  95. })
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. page{background-color: #f9f9f9;padding-bottom: 48rpx;}
  102. .bg{width: 100%;}
  103. // @import './BasicTraining.scss'
  104. </style>