honorTeacherDetail.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <view class="page_body">
  3. <!-- 头部 -->
  4. <nav-bar height="312" :title="state.teacherName" :tabList="state.tabList" :tabBtns="state.tabBtns" :onlyTitle="false" :showHeadSearchInput="false" :showFilterPicker="false" :showTabs="true" :showTabBtns="true" rightWidth="0rpx" @CommonFilterData="CommonFilterData" @GoBack="GoBack"></nav-bar>
  5. <view class="page_content">
  6. <scroll-view
  7. class="scroll_view_y"
  8. :scroll-top="state.scrollTop"
  9. scroll-y="true"
  10. :refresher-enabled="false"
  11. :enable-back-to-top="true"
  12. :show-scrollbar="false"
  13. :scroll-with-animation="true"
  14. refresher-default-style="none"
  15. refresher-background="#F8F9FD"
  16. :refresher-triggered="state.isRefreshing"
  17. @scrolltolower="OnLoadMore"
  18. @refresherrefresh="OnRefresh"
  19. @scroll="OnScroll">
  20. <view class="refresh_loading" v-if="state.isRefreshing"><uni-load-more status="loading" /></view>
  21. <view class="page_list">
  22. <view class="list_item" v-for="item in state.pageList" :key="item.id" @click="PreviewHonorDetail(item.id,item.honorName)">
  23. <view class="item_honor_type">
  24. <view class="honor_type_item">{{item.awardDatetime}}</view>
  25. <view class="honor_type_item">{{item.honorTypeName}}</view>
  26. </view>
  27. <view class="honor_content">
  28. <image class="honor_pic" :src="item.certPicUrl"></image>
  29. <view class="honor_info">
  30. <view class="honor_info_top">
  31. <view class="honor_name">{{item.honorName}}</view>
  32. <view class="teacher_name">获奖人:{{item.teacherName}}</view>
  33. </view>
  34. <view class="created_at">上传时间:{{item.createdAt}}</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="no_data" v-if="!state.isLoading && state.pageList.length == 0">
  40. <image class="no_data_img" src="@/static/image/bg/no_data.png"></image>
  41. <text class="no_data_text">暂无数据</text>
  42. </view>
  43. <uni-load-more v-if="state.pageList.length > 0" :status="state.loadStatus" />
  44. </scroll-view>
  45. </view>
  46. </view>
  47. </template>
  48. <script setup>
  49. import navBar from '@/components/navBar.vue';
  50. import {queryHonorTypeList,queryHonorTeacherListDetail} from '@/reqApi/teacherHonor.js';
  51. import {
  52. reactive,
  53. nextTick
  54. } from 'vue';
  55. import { onLoad } from '@dcloudio/uni-app';
  56. const state = reactive({
  57. tabList:[],
  58. tabBtns:[{
  59. label:'全部',
  60. value:'',
  61. },{
  62. label:'最近3月',
  63. value:'3',
  64. },{
  65. label:'最近半年',
  66. value:'6',
  67. },{
  68. label:'最近1年',
  69. value:'12',
  70. }],
  71. pageLists:[],//全部数据
  72. pageList:[],//列表数据
  73. honorTypeId:'',//荣誉类型
  74. teacherId: '',//教师id
  75. teacherName:'',//教师名称
  76. dateType:'',//获奖时间
  77. pageSize: 30,
  78. pageNum: 1,
  79. pages:0,
  80. scrollTop:0,
  81. oldScrollTop:0,
  82. isRefreshing:false,//设置当前下拉刷新状态,true 表示下拉刷新已经被触发,false 表示下拉刷新未被触发
  83. isLoading:true,//加载中
  84. noMoreData:false,//没有更多数据了
  85. loadStatus:'more',//loading状态
  86. })
  87. onLoad((option) => {
  88. state.teacherId = option.teacherId;
  89. state.teacherName = option.teacherName;
  90. GetHonorTypeList();
  91. OnLoadData(true);
  92. });
  93. //查询荣誉类型列表
  94. const GetHonorTypeList = () => {
  95. queryHonorTypeList().then(res=>{
  96. if(res.code == 200){
  97. const list = res?.data || [];
  98. const tabList = list.map(item=>({
  99. ...item,
  100. label:item.honorTypeName,
  101. value:item.id
  102. }))
  103. state.tabList = [{label:'全部',value:''},...tabList];
  104. }
  105. })
  106. }
  107. //切换条件选择器
  108. const CommonFilterData = (filterOptions,type) => {
  109. const { tabsSelected,tabBtnSelected } = filterOptions;
  110. state.honorTypeId = tabsSelected;
  111. state.dateType = tabBtnSelected;
  112. OnLoadData(true)
  113. }
  114. /*
  115. *获取数据
  116. * initPage:初始分页 从第一开始
  117. */
  118. const OnLoadData = (initPage) => {
  119. state.isLoading = true;
  120. state.loadStatus = 'loading';
  121. if (initPage) {
  122. // uni.showLoading({
  123. // title: '加载中'
  124. // });
  125. state.pageNum = 1;//如果是下拉刷新、重新查询 默认加载第一页
  126. queryHonorTeacherListDetail({
  127. honorTypeId:state.honorTypeId,//荣誉类型id
  128. teacherId:state.teacherId,
  129. dateType:state.dateType,
  130. startDatetime:'',
  131. endDatetime:''
  132. }).then(res=>{
  133. if(res.code == 200){
  134. const tableData = res?.data?.tableData || [];
  135. state.pageLists = tableData;//全部数据
  136. const total = tableData?.length || 0;//总数
  137. state.pages = Math.ceil(total / state.pageSize);//总页数
  138. //默认加载
  139. state.pageList = state.pageLists.slice(0, state.pageSize);
  140. //没有更多了
  141. state.noMoreData = state.pageNum == state.pages;
  142. //分页+1
  143. state.pageNum++;
  144. state.isLoading = false;
  145. state.isRefreshing = false;//下拉刷新未被触发
  146. state.loadStatus = state.noMoreData?'no-more':'more';
  147. }
  148. }).finally(()=>{
  149. // uni.hideLoading();
  150. //返回到页面顶部
  151. if(initPage){
  152. GoTop();
  153. }
  154. })
  155. }else{
  156. const start = (state.pageNum - 1) * state.pageSize;
  157. const end = start + state.pageSize;
  158. const list = state.pageLists.slice(start, end);
  159. state.pageList = [...state.pageList, ...list];
  160. state.noMoreData = state.pageNum == state.pages;
  161. state.pageNum++;
  162. setTimeout(() => {
  163. state.isLoading = false;
  164. state.isRefreshing = false; //下拉刷新未被触发
  165. state.loadStatus = state.noMoreData?'no-more':'more';
  166. }, 0)
  167. }
  168. }
  169. // 自定义下拉刷新被触发 下拉刷新
  170. const OnRefresh = () =>{
  171. state.isRefreshing = true;//下拉刷新已经被触发
  172. OnLoadData(true);
  173. }
  174. //滚动到底部/右边 触发上拉刷新
  175. const OnLoadMore = () => {
  176. if (state.isLoading || state.noMoreData) return;
  177. OnLoadData(false);
  178. }
  179. // 滚动时触发
  180. const OnScroll = (e) => {
  181. state.oldScrollTop = e.detail.scrollTop;
  182. }
  183. //返回到顶部
  184. const GoTop = () => {
  185. // 解决view层不同步的问题
  186. state.scrollTop = state.oldScrollTop;
  187. nextTick(() => {
  188. state.scrollTop = 0
  189. });
  190. }
  191. //返回
  192. const GoBack = () => {
  193. uni.navigateBack({
  194. delta: 1
  195. });
  196. }
  197. const PreviewHonorDetail = (id,honorName) => {
  198. uni.navigateTo({
  199. url: `/pages/teacherHonor/honorTeacher/honorDetail?id=${id}&honorName=${encodeURIComponent(honorName)}`
  200. });
  201. }
  202. </script>
  203. <style lang="scss" scoped>
  204. .page_body{
  205. height: 100%;
  206. min-height: auto;
  207. .page_content{
  208. height: calc(100% - 312rpx);
  209. .scroll_view_y{
  210. height: 100%;
  211. .refresh_loading{
  212. padding: 10rpx 0;
  213. }
  214. }
  215. .page_list{
  216. display: flex;
  217. width: 100%;
  218. flex-direction: column;
  219. .list_item{
  220. display: flex;
  221. width: 100%;
  222. flex-direction: column;
  223. margin-top: 32rpx;
  224. &:nth-child(1){
  225. margin-top: 0;
  226. }
  227. .item_honor_type{
  228. display: flex;
  229. width: 100%;
  230. align-items: center;
  231. .honor_type_item{
  232. font-weight: 400;
  233. font-size: 32rpx;
  234. color: #333333;
  235. &:nth-child(1){
  236. font-weight: 500;
  237. margin-right: 24rpx;
  238. }
  239. }
  240. }
  241. .honor_content{
  242. margin-top: 16rpx;
  243. display: flex;
  244. width: 100%;
  245. padding: 16rpx;
  246. box-sizing: border-box;
  247. background-color: #F8FAFE;
  248. border-radius: 15rpx;
  249. border: 2rpx solid #EBEEF5;
  250. .honor_pic{
  251. width: 320rpx;
  252. height: 200rpx;
  253. border-radius: 8rpx;
  254. margin-right: 16rpx;
  255. flex-shrink: 0;
  256. }
  257. .honor_info{
  258. flex:1;
  259. display: flex;
  260. justify-content: space-between;
  261. flex-direction: column;
  262. overflow: hidden;
  263. .honor_info_top{
  264. display: flex;
  265. width: 100%;
  266. flex-direction: column;
  267. .honor_name{
  268. font-weight: 500;
  269. font-size: 32rpx;
  270. color: #333333;
  271. width: 100%;
  272. white-space: nowrap;
  273. overflow: hidden;
  274. text-overflow: ellipsis;
  275. }
  276. .teacher_name{
  277. margin-top: 16rpx;
  278. font-weight: 400;
  279. font-size: 28rpx;
  280. color: #333333;
  281. width: 100%;
  282. white-space: nowrap;
  283. overflow: hidden;
  284. text-overflow: ellipsis;
  285. }
  286. }
  287. .created_at{
  288. width: 100%;
  289. line-height: 1.4;
  290. white-space: nowrap;
  291. overflow: hidden;
  292. text-overflow: ellipsis;
  293. font-weight: 400;
  294. font-size: 28rpx;
  295. color: #999999;
  296. }
  297. }
  298. }
  299. }
  300. }
  301. }
  302. }
  303. </style>