index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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" v-if="total>0">
  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. const scrolltolower = () => {
  163. if (total.value > list.value.length) {
  164. uni.showLoading({
  165. title: '加载中',
  166. mask: true
  167. })
  168. page.value = page.value + 1;
  169. skip.value = page.value * limit.value;
  170. search();
  171. uni.hideLoading();
  172. } else is_bottom.value = true
  173. };
  174. // 清空列表
  175. const clearPage = () => {
  176. list.value = []
  177. skip.value = 0
  178. limit.value = 6
  179. page.value = 0
  180. };
  181. </script>
  182. <style lang="scss" scoped>
  183. .content {
  184. background-color: var(--f1Color);
  185. .one {
  186. display: flex;
  187. justify-content: center;
  188. align-items: center;
  189. padding: 2vw;
  190. background-color: var(--mainColor);
  191. .one_1 {
  192. padding: 0 2vw;
  193. width: 75vw;
  194. input {
  195. padding: 2vw;
  196. background-color: var(--f1Color);
  197. font-size: var(--font14Size);
  198. border-radius: 5px;
  199. }
  200. }
  201. .one_2 {
  202. .button {
  203. background-color: var(--3c9Color);
  204. color: var(--mainColor);
  205. }
  206. }
  207. }
  208. .two {
  209. height: 90vh;
  210. display: flex;
  211. flex-direction: row;
  212. margin: 2vw 0 0 0;
  213. .two_1 {
  214. position: relative;
  215. width: 25vw;
  216. background-color: #fafafa;
  217. display: flex;
  218. flex-direction: column;
  219. .list {
  220. text-align: center;
  221. padding: 3.1vw 0;
  222. border-bottom: 1px solid var(--f1Color);
  223. text {
  224. font-size: var(--font14Size);
  225. }
  226. }
  227. .listActive {
  228. background-color: var(--3c9Color);
  229. color: var(--mainColor);
  230. }
  231. }
  232. .two_2 {
  233. width: 75vw;
  234. flex-grow: 1;
  235. position: relative;
  236. display: flex;
  237. flex-direction: column;
  238. .two_2_1 {
  239. background-color: var(--mainColor);
  240. }
  241. .two_2_2 {
  242. flex-grow: 1;
  243. position: relative;
  244. display: flex;
  245. flex-direction: column;
  246. margin: 2vw 2vw 0 2vw;
  247. .list {
  248. display: flex;
  249. padding: 2vw;
  250. border-radius: 5px;
  251. background-color: var(--mainColor);
  252. }
  253. }
  254. .is_bottom {
  255. width: 100%;
  256. text-align: center;
  257. text {
  258. padding: 2vw 0;
  259. display: inline-block;
  260. color: var(--f85Color);
  261. font-size: var(--font12Size);
  262. }
  263. }
  264. }
  265. }
  266. .scroll-view {
  267. position: absolute;
  268. top: 0;
  269. left: 0;
  270. right: 0;
  271. bottom: 0;
  272. .list-scroll-view {
  273. display: flex;
  274. flex-direction: column;
  275. }
  276. }
  277. }
  278. </style>