basicTraining - 副本.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view>
  3. <image class="bg" src="../../static/img/basic-training-bg.png" mode="widthFix"></image>
  4. <view class="tab">
  5. <view class="tab-bg">
  6. <!-- <u-tabs ref="btabs" :list="tabs" :is-scroll="false" :current="tabIndex" @change="tabChange"></u-tabs> -->
  7. <view class="tab-list">
  8. <view class="tab-item" v-for="(item, index) in tabs" :key="index" :class="{'active': tabIndex === index}" @click="tabChange(index)">{{ item.name }}</view>
  9. </view>
  10. <view class="training-data">
  11. <view class="training-data-item" v-if="tabIndex === 0">
  12. <view>已看课程</view>
  13. <view><text>8</text>个</view>
  14. </view>
  15. <view class="training-data-item">
  16. <view>还需观看</view>
  17. <view><text>10</text>个</view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <onlineTraining v-show="tabIndex=='0'" :key="1" :onlineData="onlineData" :rate="rate"></onlineTraining>
  23. <offlineTraining v-show="tabIndex=='1'" :key="2" :offlineId="offlineId"></offlineTraining>
  24. </view>
  25. </template>
  26. <script>
  27. import onlineTraining from './components/online.vue';
  28. import offlineTraining from './components/offline.vue';
  29. export default{
  30. components:{
  31. onlineTraining,
  32. offlineTraining
  33. },
  34. data(){
  35. return{
  36. tabs: [{name: '适应性培训'},{name:'线下培训'}],
  37. tabIndex: 0 ,// tab下标
  38. onlineData:[],
  39. rate:{},
  40. offlineId:'',
  41. analysisParams:{
  42. platform:'1',//平台:1-H5 2-APP 3-小程序 4-PC端
  43. pages:location.href,//页面路径
  44. btnName:'',//按钮名称
  45. btnEvent:'1',//按钮事件: 1-点击 2-长按 3-滑动
  46. ipAddress:'',//IP地址
  47. typeName:'适应性培训',//类型名称 例:学校关注度 、适应性考试等
  48. typeCode:'',//类型编码 例:类型名称首字母缩写(XXGZD)
  49. categoryName:'',//类别名称 例:XX学校,SS考试
  50. }
  51. }
  52. },
  53. onLoad(page){
  54. if(page?.type=='offline'){
  55. this.tabIndex = 1;
  56. if(page.id){
  57. this.offlineId = page.id;
  58. console.log('this.offlineId',this.offlineId)
  59. }
  60. };
  61. },
  62. onShow(){
  63. this.getAdaptTrainOnline();
  64. this.getAdaptTrainOnlineRate();
  65. },
  66. mounted() {
  67. this.postAnalysis();
  68. },
  69. methods:{
  70. getip(){
  71. let that = this;
  72. uni.request({
  73. url:'/apis/cityjson?ie=utf-8',
  74. method:'GET',
  75. success: (res) => {
  76. // console.log('this',this);
  77. const reg = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
  78. let ip = reg.exec(res.data);
  79. // that.analysisParams.ipAddress = ip[0];
  80. console.log('analysisParams',this.analysisParams);
  81. }
  82. });
  83. },
  84. async postAnalysis(){
  85. await this.getip();
  86. this.$u.api.postAnalysis(this.analysisParams).then(res=>{
  87. console.log('res',res);
  88. });
  89. },
  90. // 切换菜单
  91. tabChange(index) {
  92. console.log(index)
  93. this.tabIndex = index;
  94. },
  95. getAdaptTrainOnline(){
  96. this.$u.api.getAdaptTrainOnline().then(res=>{
  97. if(res.code == 200){
  98. this.onlineData = res.data;
  99. }else{
  100. uni.showToast({
  101. icon:'none',
  102. title:res.msg
  103. })
  104. }
  105. console.log('getAdaptTrainOnline',JSON.parse(JSON.stringify(res)));
  106. })
  107. },
  108. getAdaptTrainOnlineRate(){
  109. this.$u.api.getAdaptTrainOnlineRate().then(res=>{
  110. this.rate = res.data;
  111. console.log('getAdaptTrainOnlineRate',JSON.parse(JSON.stringify(res)));
  112. })
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss" scoped>
  118. page{
  119. background-color: #f9f9f9;
  120. padding-bottom: 48rpx;
  121. }
  122. .bg {
  123. width: 100%;
  124. }
  125. .tab {
  126. background-color: #fff;
  127. border-radius: 0 0 18rpx 18rpx;
  128. height: 348rpx;
  129. }
  130. .tab-bg {
  131. background: url(../../static/img/basic-training-tab-bg.png) no-repeat center center;
  132. background-size: 100%;
  133. height: 198rpx;
  134. }
  135. .tab-list {
  136. display: flex;
  137. justify-content: space-between;
  138. text-align: center;
  139. padding: 40rpx 160rpx 30rpx 160rpx;
  140. }
  141. .tab-item {
  142. font-size: 34rpx;
  143. color: #000000;
  144. }
  145. .active {
  146. color: #335CEB;
  147. border-bottom: solid 2px #335CEB;
  148. padding-bottom: 10rpx;
  149. }
  150. .training-data {
  151. width: calc(100% - 60rpx);
  152. margin: 0 auto;
  153. background: #FFFFFF;
  154. box-shadow: 0px 0px 12rpx 0px rgba(0, 0, 0, 0.11);
  155. border-radius: 10rpx;
  156. display: flex;
  157. justify-content: space-between;
  158. &-item {
  159. width: 50%;
  160. text-align: center;
  161. padding: 36rpx 0;
  162. view {
  163. color: #656565;
  164. font-size: 28rpx;
  165. &:last-child {
  166. font-size: 26rpx;
  167. text {
  168. color: #505050;
  169. font-size: 60rpx;
  170. }
  171. }
  172. }
  173. }
  174. }
  175. </style>