index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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="(tag,index) in list" :key="index" @tap="toBuy(tag)">
  31. {{tag.nick_name}}
  32. </view>
  33. </view>
  34. <view class="is_bottom" v-if="is_bottom">
  35. <text>{{config.bottom_title}}</text>
  36. </view>
  37. </view>
  38. </scroll-view>
  39. </view>
  40. <up-empty v-else mode="list" icon="/static/list.png"></up-empty>
  41. </view>
  42. </view>
  43. <up-overlay :show="show">
  44. <login @showChange='showChange'></login>
  45. </up-overlay>
  46. </view>
  47. </template>
  48. <script setup lang="ts">
  49. import login from "@/components/login.vue"
  50. import { inject, computed, ref } from 'vue';
  51. //该依赖已内置不需要单独安装
  52. import { onShow, onLoad, onPullDownRefresh } from "@dcloudio/uni-app";
  53. // 请求接口
  54. const $api = inject('$api');
  55. // 基本信息
  56. const config = ref({ logo: [], file: [] });
  57. const type = ref('');
  58. const subject = ref('-1');
  59. const grade = ref('-1');
  60. // 列表
  61. const list = ref([]);
  62. const total = ref(0);
  63. const skip = ref(0);
  64. const limit = ref(5);
  65. const page = ref(0);
  66. // 数据是否触底
  67. const is_bottom = ref(false);
  68. // 遮罩层
  69. const show = ref(false);
  70. const nick_name = ref('');
  71. // 字典表
  72. const educationList = ref([]);
  73. const active = ref(0);
  74. const subjectList = ref([]);
  75. const gradeList = ref([]);
  76. // user
  77. const user = computed(() => {
  78. return uni.getStorageSync('user');
  79. })
  80. onLoad(async (options) => {
  81. type.value = options && options.type
  82. uni.setNavigationBarTitle({
  83. title: options && options.name + '课程' || '课程'
  84. });
  85. });
  86. onShow(async () => {
  87. await searchConfig();
  88. await searchOther();
  89. await clearPage();
  90. await search();
  91. if (!user.value) show.value = true
  92. })
  93. onPullDownRefresh(async () => {
  94. await clearPage();
  95. await search();
  96. uni.stopPullDownRefresh();
  97. })
  98. // config信息
  99. const searchConfig = async () => {
  100. config.value = uni.getStorageSync('config');
  101. };
  102. // 其他查询信息
  103. const searchOther = async () => {
  104. let res;
  105. // 学历
  106. res = await $api(`dictData`, 'GET', { code: 'education', is_use: '0' });
  107. if (res.errcode === 0) educationList.value = res.data;
  108. // 学科
  109. res = await $api(`dictData`, 'GET', { code: 'subject', is_use: '0' });
  110. if (res.errcode === 0) subjectList.value = res.data;
  111. subjectList.value.unshift({ label: '全部', value: '-1' })
  112. // 年级
  113. res = await $api(`dictData`, 'GET', { code: 'grade', is_use: '0' });
  114. if (res.errcode === 0) gradeList.value = res.data;
  115. gradeList.value.unshift({ label: '全部', value: '-1' })
  116. };
  117. // 名称搜索
  118. const searchInfo = async () => {
  119. await clearPage();
  120. await search();
  121. };
  122. // 查询
  123. const search = async () => {
  124. const info : any = {
  125. skip: skip.value,
  126. limit: limit.value,
  127. status: '1',
  128. is_show: '0'
  129. }
  130. if (nick_name.value) info.nick_name = nick_name.value
  131. const res = await $api('teacher', 'GET', info);
  132. if (res.errcode === 0) {
  133. list.value = list.value.concat(res.data)
  134. total.value = res.total
  135. } else {
  136. uni.showToast({
  137. title: res.errmsg || '',
  138. icon: 'error',
  139. });
  140. }
  141. };
  142. const showChange = () => {
  143. show.value = false
  144. }
  145. const getDict = (data, model) => {
  146. let res
  147. if (model == 'education') res = educationList.value.find((f) => f.value == data)
  148. return res.label || '暂无'
  149. }
  150. // 左侧一级选择
  151. const toChange = (index, e) => {
  152. console.log(index, e);
  153. active.value = index
  154. subject.value = e.value
  155. // that.clearPage();
  156. // that.searchMarket();
  157. }
  158. // 改变标签
  159. const toTab = async (data) => {
  160. console.log(data);
  161. };
  162. // 分页
  163. const toPage = () => {
  164. if (total.value > list.value.length) {
  165. uni.showLoading({
  166. title: '加载中',
  167. mask: true
  168. })
  169. page.value = page.value + 1;
  170. skip.value = page.value * limit.value;
  171. search();
  172. uni.hideLoading();
  173. } else is_bottom.value = true
  174. };
  175. // 清空列表
  176. const clearPage = () => {
  177. list.value = []
  178. skip.value = 0
  179. limit.value = 6
  180. page.value = 0
  181. };
  182. </script>
  183. <style lang="scss" scoped>
  184. .content {
  185. background-color: var(--f1Color);
  186. .one {
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. padding: 2vw;
  191. background-color: var(--mainColor);
  192. .one_1 {
  193. padding: 0 2vw;
  194. width: 75vw;
  195. input {
  196. padding: 2vw;
  197. background-color: var(--f1Color);
  198. font-size: var(--font14Size);
  199. border-radius: 5px;
  200. }
  201. }
  202. .one_2 {
  203. .button {
  204. background-color: var(--3c9Color);
  205. color: var(--mainColor);
  206. }
  207. }
  208. }
  209. .two {
  210. height: 90vh;
  211. display: flex;
  212. flex-direction: row;
  213. margin: 2vw 0 0 0;
  214. .two_1 {
  215. position: relative;
  216. width: 25vw;
  217. background-color: #fafafa;
  218. display: flex;
  219. flex-direction: column;
  220. .list {
  221. text-align: center;
  222. padding: 3.1vw 0;
  223. border-bottom: 1px solid var(--f1Color);
  224. text {
  225. font-size: var(--font14Size);
  226. }
  227. }
  228. .listActive {
  229. background-color: var(--3c9Color);
  230. color: var(--mainColor);
  231. }
  232. }
  233. .two_2 {
  234. width: 75vw;
  235. flex-grow: 1;
  236. position: relative;
  237. display: flex;
  238. flex-direction: column;
  239. .two_2_1 {
  240. background-color: var(--mainColor);
  241. }
  242. .two_2_2 {
  243. flex-grow: 1;
  244. position: relative;
  245. display: flex;
  246. flex-direction: column;
  247. margin: 2vw 2vw 0 2vw;
  248. .list {
  249. display: flex;
  250. padding: 2vw;
  251. border-radius: 5px;
  252. background-color: var(--mainColor);
  253. }
  254. }
  255. .is_bottom {
  256. width: 100%;
  257. text-align: center;
  258. text {
  259. padding: 2vw 0;
  260. display: inline-block;
  261. color: var(--f85Color);
  262. font-size: var(--font12Size);
  263. }
  264. }
  265. }
  266. }
  267. .scroll-view {
  268. position: absolute;
  269. top: 0;
  270. left: 0;
  271. right: 0;
  272. bottom: 0;
  273. .list-scroll-view {
  274. display: flex;
  275. flex-direction: column;
  276. }
  277. }
  278. }
  279. </style>