index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <up-search v-model="nick_name" @custom="searchInfo"></up-search>
  5. </view>
  6. <view class="two">
  7. <up-tabs :list="subjectList" keyName="label" @click="toTab"></up-tabs>
  8. </view>
  9. <view class="thr" v-if="total>0">
  10. <up-list @scrolltolower="scrolltolower">
  11. <up-list-item v-for="(item, index) in list" :key="index">
  12. <view class="list">
  13. <view class="left">
  14. <image v-if="item.icon&&item.icon.length>0&&item.icon" class="image"
  15. :src="item.icon[0].url">
  16. </image>
  17. <image v-else class="image" :src="config.icon[0].url"></image>
  18. </view>
  19. <view class="right">
  20. <view class="right_1">
  21. <view class="leftR">
  22. {{item.nick_name||'暂无昵称'}}
  23. </view>
  24. <view class="rightR">
  25. <view class="text">
  26. <span class="text_1">最近可约:</span>
  27. <span class="text_2">{{item.time||'休息中'}}</span>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="right_2">
  32. <view class="text"> 所在院校: </view>
  33. <view class="value"> {{item.college||'暂无'}} </view>
  34. </view>
  35. <view class="right_2">
  36. <view class="text"> 学历: </view>
  37. <view class="value">{{getDict(item.education,'education')}}</view>
  38. </view>
  39. <view class="right_3">
  40. <view class="money">¥{{item.money||'免费'}} </view>
  41. <view class="button">
  42. <button type="warn" size="mini" @click="toBuy(item)">预约</button>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </up-list-item>
  48. </up-list>
  49. </view>
  50. <up-empty v-else mode="list" icon="/static/list.png">
  51. </up-empty>
  52. <view class="is_bottom" v-if="is_bottom">
  53. <text>{{config.bottom_title||'没有更多了!'}}</text>
  54. </view>
  55. <up-overlay :show="show">
  56. <login @showChange='showChange'></login>
  57. </up-overlay>
  58. </view>
  59. </template>
  60. <script setup lang="ts">
  61. import login from "@/components/login.vue"
  62. import { inject, computed, ref } from 'vue';
  63. //该依赖已内置不需要单独安装
  64. import { onShow, onPullDownRefresh } from "@dcloudio/uni-app";
  65. // 请求接口
  66. const $api = inject('$api');
  67. // 基本信息
  68. const config = ref({ logo: [], file: [] });
  69. // 列表
  70. const list = ref([]);
  71. const total = ref(0);
  72. const skip = ref(0);
  73. const limit = ref(5);
  74. const page = ref(0);
  75. // 数据是否触底
  76. const is_bottom = ref(false);
  77. // 遮罩层
  78. const show = ref(false);
  79. // 字典表
  80. const subjectList = ref([]);
  81. const educationList = ref([]);
  82. const nick_name = ref('');
  83. // user
  84. const user = computed(() => {
  85. return uni.getStorageSync('user');
  86. })
  87. onShow(async () => {
  88. await searchConfig();
  89. await searchOther();
  90. await clearPage();
  91. await search();
  92. if (!user.value) show.value = true
  93. })
  94. onPullDownRefresh(async () => {
  95. await clearPage();
  96. await search();
  97. uni.stopPullDownRefresh();
  98. })
  99. // config信息
  100. const searchConfig = async () => {
  101. config.value = uni.getStorageSync('config');
  102. };
  103. // 其他查询信息
  104. const searchOther = async () => {
  105. let res;
  106. // 学科
  107. res = await $api(`dictData`, 'GET', { code: 'subject', is_use: '0' });
  108. if (res.errcode === 0) subjectList.value = res.data;
  109. subjectList.value.unshift({ label: '全部', value: '-1', is_show: true })
  110. // 学历
  111. res = await $api(`dictData`, 'GET', { code: 'education', is_use: '0' });
  112. if (res.errcode === 0) educationList.value = res.data;
  113. };
  114. // 名称搜索
  115. const searchInfo = async () => {
  116. if (nick_name.value) {
  117. await clearPage();
  118. await search();
  119. }
  120. };
  121. // 查询
  122. const search = async () => {
  123. const info : any = {
  124. skip: skip.value,
  125. limit: limit.value,
  126. status: '1',
  127. is_show: '0'
  128. }
  129. if (nick_name.value) info.nick_name = nick_name.value
  130. const res = await $api('teacher', 'GET', info);
  131. if (res.errcode === 0) {
  132. list.value = list.value.concat(res.data)
  133. total.value = res.total
  134. } else {
  135. uni.showToast({
  136. title: res.errmsg || '',
  137. icon: 'error',
  138. });
  139. }
  140. };
  141. // 改变标签
  142. const toTab = async (data) => {
  143. console.log(data);
  144. };
  145. const showChange = () => {
  146. show.value = false
  147. }
  148. const getDict = (data, model) => {
  149. let res
  150. if (model == 'education') res = educationList.value.find((f) => f.value == data)
  151. return res.label || '暂无'
  152. }
  153. const scrolltolower = () => {
  154. if (total.value > list.value.length) {
  155. uni.showLoading({
  156. title: '加载中',
  157. mask: true
  158. })
  159. page.value = page.value + 1;
  160. skip.value = page.value * limit.value;
  161. search();
  162. uni.hideLoading();
  163. } else is_bottom.value = true
  164. };
  165. // 清空列表
  166. const clearPage = () => {
  167. list.value = []
  168. skip.value = 0
  169. limit.value = 6
  170. page.value = 0
  171. };
  172. </script>
  173. <style lang="scss" scoped>
  174. .content {
  175. display: flex;
  176. flex-direction: column;
  177. min-height: 100vh;
  178. background-color: var(--f1Color);
  179. .one {
  180. padding: 2vw;
  181. background-color: var(--mainColor);
  182. }
  183. .two {
  184. margin: 2vw;
  185. border-radius: 5px;
  186. background-color: var(--mainColor);
  187. }
  188. .thr {
  189. margin: 0 2vw;
  190. .list {
  191. display: flex;
  192. margin: 2vw 0 0 0;
  193. padding: 2vw;
  194. border-radius: 5px;
  195. background-color: var(--mainColor);
  196. .left {
  197. width: 28%;
  198. margin: 0 2vw 0 0;
  199. .image {
  200. width: 25vw;
  201. height: 25vw;
  202. border-radius: 25vw;
  203. }
  204. }
  205. .right {
  206. width: 70%;
  207. .right_1 {
  208. display: flex;
  209. align-items: center;
  210. justify-content: space-between;
  211. .leftR {
  212. width: 40%;
  213. font-size: var(--font16Size);
  214. font-weight: bold;
  215. }
  216. .rightR {
  217. width: 60%;
  218. text-align: right;
  219. font-size: var(--font12Size);
  220. .text {
  221. text-align: center;
  222. border: 1px solid var(--3c9Color);
  223. border-radius: 4px;
  224. padding: 1vw;
  225. background: linear-gradient(to right, #ffffff, #3c9cff59);
  226. .text_1 {
  227. color: var(--3c9Color);
  228. font-weight: bold;
  229. }
  230. .text_2 {
  231. color: var(--ff0Color);
  232. }
  233. }
  234. }
  235. }
  236. .right_2 {
  237. display: flex;
  238. align-items: center;
  239. margin: 1vw 0 0 0;
  240. .text {
  241. font-size: var(--font14Size);
  242. margin: 0 1vw 0 0;
  243. }
  244. .value {
  245. text-align: right;
  246. color: var(--f85Color);
  247. font-size: var(--font12Size);
  248. }
  249. }
  250. .right_3 {
  251. display: flex;
  252. align-items: center;
  253. justify-content: space-between;
  254. .money {
  255. width: 50%;
  256. font-size: var(--font14Size);
  257. color: var(--ff0Color);
  258. }
  259. .button {
  260. width: 50%;
  261. text-align: right;
  262. button {
  263. color: var(--mainColor);
  264. background: linear-gradient(to right, #1e3fdc, #3c9cff);
  265. font-size: var(--font12Size);
  266. border-radius: 5vw;
  267. }
  268. }
  269. }
  270. }
  271. }
  272. }
  273. }
  274. </style>