index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <view class="one_1">
  5. <input type="text" v-model="nick_name" placeholder="请输入想要搜索的内容">
  6. </view>
  7. <view class="one_2">
  8. <button size="mini" class="button" type="primary" @click="searchInfo">搜索</button>
  9. </view>
  10. </view>
  11. <view class="two">
  12. <view class="two_1">
  13. <scroll-view scroll-y="true" class="scroll-view">
  14. <view class="list-scroll-view">
  15. <view class="list" :class="[active==index?'listActive':'']" v-for="(item,index) in subjectList"
  16. :key="index" @tap="toChange(index,item)">
  17. <text>{{item.label}}</text>
  18. </view>
  19. </view>
  20. </scroll-view>
  21. </view>
  22. <view class="two_2">
  23. <view class="two_2_1">
  24. <up-tabs :list="gradeList" keyName="label" @click="toTab"></up-tabs>
  25. </view>
  26. <view class="two_2_2" v-if="total>0">
  27. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  28. <view class="list-scroll-view">
  29. <view class=" one_2_1">
  30. <view class="list" v-for="(item,index) in list" :key="index" @tap="toBuy(tag)">
  31. <view class="left">
  32. <image v-if="item.icon&&item.icon.length>0&&item.icon" class="image"
  33. :src="item.icon[0].url">
  34. </image>
  35. <image v-else class="image" :src="config.icon[0].url"></image>
  36. </view>
  37. <view class="right">
  38. <view class="right_1 textOne">
  39. {{item.name||'暂无'}}
  40. </view>
  41. <view class="right_2">
  42. <view class="text">老师: </view>
  43. <view class="value"> {{item.teacher_name||'暂无'}} </view>
  44. </view>
  45. <view class="right_3">
  46. <view class="text">
  47. <span class="text_1">最近可约:</span>
  48. <span class="text_2">{{item.start_time||'休息中'}}</span>
  49. </view>
  50. </view>
  51. <view class="right_4">
  52. <view class="money">¥{{item.money||'免费'}} </view>
  53. <view class="button">
  54. <button type="warn" size="mini" @click="toBuy(item)">预约</button>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="is_bottom" v-if="is_bottom">
  61. <text>{{config.bottom_title}}</text>
  62. </view>
  63. </view>
  64. </scroll-view>
  65. </view>
  66. <up-empty v-else mode="list" icon="/static/list.png"></up-empty>
  67. </view>
  68. </view>
  69. <up-overlay :show="show">
  70. <login @showChange='showChange'></login>
  71. </up-overlay>
  72. </view>
  73. </template>
  74. <script setup lang="ts">
  75. import login from "@/components/login.vue"
  76. import { inject, computed, ref } from 'vue';
  77. //该依赖已内置不需要单独安装
  78. import { onShow, onLoad, onPullDownRefresh } from "@dcloudio/uni-app";
  79. // 请求接口
  80. const $api = inject('$api');
  81. // 基本信息
  82. const config = ref({ logo: [], file: [] });
  83. const active = ref(0);
  84. const type = ref('');
  85. const subject = ref('-1');
  86. const grade = ref('-1');
  87. // 列表
  88. const list = ref([]);
  89. const total = ref(0);
  90. const skip = ref(0);
  91. const limit = ref(5);
  92. const page = ref(0);
  93. // 数据是否触底
  94. const is_bottom = ref(false);
  95. const scrollTop = ref(0);
  96. // 遮罩层
  97. const show = ref(false);
  98. const nick_name = ref('');
  99. // 字典表
  100. const subjectList = ref([]);
  101. const gradeList = ref([]);
  102. // user
  103. const user = computed(() => {
  104. return uni.getStorageSync('user');
  105. })
  106. onLoad(async (options) => {
  107. type.value = options && options.type
  108. uni.setNavigationBarTitle({
  109. title: options && options.name + '课程' || '课程'
  110. });
  111. });
  112. onShow(async () => {
  113. await searchConfig();
  114. await searchOther();
  115. await clearPage();
  116. await search();
  117. if (!user.value) show.value = true
  118. })
  119. onPullDownRefresh(async () => {
  120. await clearPage();
  121. await search();
  122. uni.stopPullDownRefresh();
  123. })
  124. // config信息
  125. const searchConfig = async () => {
  126. config.value = uni.getStorageSync('config');
  127. };
  128. // 其他查询信息
  129. const searchOther = async () => {
  130. let res;
  131. // 学科
  132. res = await $api(`dictData`, 'GET', { code: 'subject', is_use: '0' });
  133. if (res.errcode === 0) subjectList.value = res.data;
  134. subjectList.value.unshift({ label: '全部', value: '-1' })
  135. // 年级
  136. res = await $api(`dictData`, 'GET', { code: 'grade', is_use: '0' });
  137. if (res.errcode === 0) gradeList.value = res.data;
  138. gradeList.value.unshift({ label: '全部', value: '-1' })
  139. };
  140. // 名称搜索
  141. const searchInfo = async () => {
  142. await clearPage();
  143. await search();
  144. };
  145. // 查询
  146. const search = async () => {
  147. const info : any = {
  148. skip: skip.value,
  149. limit: limit.value,
  150. status: '1',
  151. is_show: '0',
  152. type: type.value
  153. }
  154. if (nick_name.value) info.name = nick_name.value
  155. if (subject.value && subject.value !== '-1') info.subject = subject.value
  156. if (grade.value && grade.value !== '-1') info.grade = grade.value
  157. const res = await $api('course/appHome', 'GET', info);
  158. if (res.errcode === 0) {
  159. list.value = list.value.concat(res.data)
  160. total.value = res.total
  161. } else {
  162. uni.showToast({
  163. title: res.errmsg || '',
  164. icon: 'error',
  165. });
  166. }
  167. };
  168. const showChange = () => {
  169. show.value = false
  170. }
  171. // 左侧一级选择
  172. const toChange = async (index, e) => {
  173. console.log(index, e);
  174. active.value = index
  175. subject.value = e.value
  176. await clearPage();
  177. await search();
  178. }
  179. // 改变标签
  180. const toTab = async (data) => {
  181. grade.value = data.value
  182. await clearPage();
  183. await search();
  184. };
  185. // 分页
  186. const toPage = () => {
  187. if (total.value > list.value.length) {
  188. uni.showLoading({
  189. title: '加载中',
  190. mask: true
  191. })
  192. page.value = page.value + 1;
  193. skip.value = page.value * limit.value;
  194. search();
  195. uni.hideLoading();
  196. } else is_bottom.value = true
  197. };
  198. // 触底
  199. const toScroll = (e) => {
  200. let up = scrollTop.value;
  201. scrollTop.value = e.detail.scrollTop
  202. let num = Math.sign(up - e.detail.scrollTop);
  203. if (num == 1) is_bottom.value = false
  204. }
  205. // 清空列表
  206. const clearPage = () => {
  207. list.value = []
  208. skip.value = 0
  209. limit.value = 6
  210. page.value = 0
  211. };
  212. </script>
  213. <style lang="scss" scoped>
  214. .content {
  215. background-color: var(--f1Color);
  216. .one {
  217. display: flex;
  218. justify-content: center;
  219. align-items: center;
  220. padding: 2vw;
  221. background-color: var(--mainColor);
  222. .one_1 {
  223. padding: 0 2vw;
  224. width: 75vw;
  225. input {
  226. padding: 2vw;
  227. background-color: var(--f1Color);
  228. font-size: var(--font14Size);
  229. border-radius: 5px;
  230. }
  231. }
  232. .one_2 {
  233. .button {
  234. background-color: var(--3c9Color);
  235. color: var(--mainColor);
  236. }
  237. }
  238. }
  239. .two {
  240. height: 90vh;
  241. display: flex;
  242. flex-direction: row;
  243. margin: 2vw 0 0 0;
  244. .two_1 {
  245. position: relative;
  246. width: 20vw;
  247. background-color: #fafafa;
  248. display: flex;
  249. flex-direction: column;
  250. .list {
  251. text-align: center;
  252. padding: 3.1vw 0;
  253. border-bottom: 1px solid var(--f1Color);
  254. text {
  255. font-size: var(--font14Size);
  256. }
  257. }
  258. .listActive {
  259. background-color: var(--3c9Color);
  260. color: var(--mainColor);
  261. }
  262. }
  263. .two_2 {
  264. width: 75vw;
  265. flex-grow: 1;
  266. position: relative;
  267. display: flex;
  268. flex-direction: column;
  269. .two_2_1 {
  270. background-color: var(--mainColor);
  271. }
  272. .two_2_2 {
  273. flex-grow: 1;
  274. position: relative;
  275. display: flex;
  276. flex-direction: column;
  277. margin: 2vw 2vw 0 2vw;
  278. .list {
  279. display: flex;
  280. margin: 2vw 0 0 0;
  281. padding: 2vw;
  282. border-radius: 5px;
  283. background-color: var(--mainColor);
  284. .left {
  285. width: 28%;
  286. margin: 0 2vw 0 0;
  287. .image {
  288. width: 20vw;
  289. height: 20vw;
  290. border-radius: 2vw;
  291. }
  292. }
  293. .right {
  294. width: 70%;
  295. .right_1 {
  296. font-size: var(--font16Size);
  297. font-weight: bold;
  298. }
  299. .right_2 {
  300. display: flex;
  301. align-items: center;
  302. margin: 1vw 0 0 0;
  303. .text {
  304. font-size: var(--font14Size);
  305. margin: 0 1vw 0 0;
  306. }
  307. .value {
  308. text-align: right;
  309. color: var(--f85Color);
  310. font-size: var(--font12Size);
  311. }
  312. }
  313. .right_3 {
  314. margin: 1vw 0;
  315. .text {
  316. font-size: var(--font12Size);
  317. text-align: center;
  318. border: 1px solid var(--3c9Color);
  319. border-radius: 4px;
  320. padding: 1vw;
  321. background: linear-gradient(to right, #ffffff, #3c9cff59);
  322. .text_1 {
  323. color: var(--3c9Color);
  324. font-weight: bold;
  325. }
  326. .text_2 {
  327. color: var(--ff0Color);
  328. }
  329. }
  330. }
  331. .right_4 {
  332. display: flex;
  333. align-items: center;
  334. justify-content: space-between;
  335. .money {
  336. width: 50%;
  337. font-size: var(--font14Size);
  338. color: var(--ff0Color);
  339. }
  340. .button {
  341. width: 50%;
  342. text-align: right;
  343. button {
  344. color: var(--mainColor);
  345. background: linear-gradient(to right, #1e3fdc, #3c9cff);
  346. font-size: var(--font12Size);
  347. border-radius: 5vw;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. }
  354. .is_bottom {
  355. width: 100%;
  356. text-align: center;
  357. text {
  358. padding: 2vw 0;
  359. display: inline-block;
  360. color: var(--f85Color);
  361. font-size: var(--font12Size);
  362. }
  363. }
  364. }
  365. }
  366. .scroll-view {
  367. position: absolute;
  368. top: 0;
  369. left: 0;
  370. right: 0;
  371. bottom: 0;
  372. .list-scroll-view {
  373. display: flex;
  374. flex-direction: column;
  375. }
  376. }
  377. }
  378. </style>