index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="content">
  3. <view class="one"
  4. :class="[courseInfo.type==='0'?'one0':courseInfo.type==='1'?'one1':courseInfo.type==='2'?'one2':courseInfo.type==='3'?'one3':'']">
  5. <view class="left">
  6. <view class="one_1 textOver">{{courseInfo.name||'暂无'}}</view>
  7. <view class="one_2">
  8. {{getDict(courseInfo.type,'type')}} {{getDict(courseInfo.grade,'grade')}}
  9. {{getDict(courseInfo.subject,'subject')}}
  10. </view>
  11. </view>
  12. <view class="right">
  13. <up-icon v-if="courseInfo.is_follow" name="star-fill" color="#FFA500" size="30"></up-icon>
  14. <up-icon v-else name="star" color="#FFA500" size="30"></up-icon>
  15. </view>
  16. </view>
  17. <view class="two">
  18. <view class="two_1">
  19. <span> 开始时间:{{courseInfo.start_time||'暂无'}}</span>
  20. <span> 结束时间:{{courseInfo.end_time||'暂无'}}</span>
  21. </view>
  22. <view class="two_2">¥{{courseInfo.money||'免费'}}</view>
  23. </view>
  24. </view>
  25. </template>
  26. <script setup lang="ts">
  27. import { inject, computed, ref } from 'vue';
  28. //该依赖已内置不需要单独安装
  29. import { onLoad } from "@dcloudio/uni-app";
  30. // 请求接口
  31. const $api = inject('$api');
  32. const id = ref('');
  33. // 基本信息
  34. const config = ref({ logo: [], file: [] });
  35. const courseInfo = ref({});
  36. const teacherInfo = ref({});
  37. // 字典表
  38. const subjectList = ref([]);
  39. const educationList = ref([]);
  40. const typeList = ref([]);
  41. const gradeList = ref([]);
  42. const genderList = ref([])
  43. const learnStatusList = ref([])
  44. // user
  45. const user = computed(() => {
  46. return uni.getStorageSync('user');
  47. })
  48. onLoad(async (options) => {
  49. id.value = options && options.id
  50. await searchConfig();
  51. await searchOther();
  52. await search();
  53. });
  54. // config信息
  55. const searchConfig = async () => {
  56. config.value = uni.getStorageSync('config');
  57. };
  58. // 其他查询信息
  59. const searchOther = async () => {
  60. let res;
  61. // 学科
  62. res = await $api(`dictData`, 'GET', { code: 'subject', is_use: '0' });
  63. if (res.errcode === 0) subjectList.value = res.data;
  64. // 年级
  65. res = await $api(`dictData`, 'GET', { code: 'grade', is_use: '0' });
  66. if (res.errcode === 0) gradeList.value = res.data;
  67. // 学历
  68. res = await $api(`dictData`, 'GET', { code: 'education', is_use: '0' });
  69. if (res.errcode === 0) educationList.value = res.data;
  70. // 类型
  71. res = await $api(`dictData`, 'GET', { code: 'courseType', is_use: '0' });
  72. if (res.errcode === 0) typeList.value = res.data;
  73. // 性别
  74. res = await $api(`dictData`, 'GET', { code: 'gender', is_use: '0' });
  75. if (res.errcode === 0) genderList.value = res.data;
  76. // 学业状态
  77. res = await $api(`dictData`, 'GET', { code: 'learnStatus', is_use: '0' });
  78. if (res.errcode === 0) learnStatusList.value = res.data;
  79. };
  80. // 查询
  81. const search = async () => {
  82. if (id.value) {
  83. const res = await $api(`course/appHomeDetail/${id.value}`, 'GET', {});
  84. if (res.errcode == '0') {
  85. courseInfo.value = res.data.courseInfo
  86. teacherInfo.value = res.data.teacherInfo
  87. }
  88. }
  89. };
  90. const getDict = (data, model) => {
  91. if (data) {
  92. let res
  93. if (model == 'education') res = educationList.value.find((f) => f.value == data)
  94. else if (model == 'subject') res = subjectList.value.find((f) => f.value == data)
  95. else if (model == 'grade') res = gradeList.value.find((f) => f.value == data)
  96. else if (model == 'type') res = typeList.value.find((f) => f.value == data)
  97. else if (model == 'gender') res = genderList.value.find((f) => f.value == data)
  98. else if (model == 'learnStatus') res = learnStatusList.value.find((f) => f.value == data)
  99. return res.label || '暂无'
  100. }
  101. }
  102. </script>
  103. <style lang="scss" scoped>
  104. .content {
  105. display: flex;
  106. flex-direction: column;
  107. min-height: 100vh;
  108. background-color: var(--f1Color);
  109. .one {
  110. display: flex;
  111. align-items: center;
  112. justify-content: space-between;
  113. margin: 3vw;
  114. padding: 5vw;
  115. border-radius: 2vw;
  116. color: var(--mainColor);
  117. .left {
  118. .one_1 {
  119. font-size: var(--font16Size);
  120. font-weight: bold;
  121. margin: 0 0 2vw 0;
  122. }
  123. }
  124. .right {
  125. background-color: var(--mainColor);
  126. padding: 2vw;
  127. border-radius: 90px;
  128. }
  129. }
  130. .one0 {
  131. background-color: var(--d57Color);
  132. }
  133. .one1 {
  134. background-color: var(--1e9Color);
  135. }
  136. .one2 {
  137. background-color: var(--ff6Color);
  138. }
  139. .one3 {
  140. background-color: var(--40eColor);
  141. }
  142. }
  143. </style>