index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <template>
  2. <!-- 头部 -->
  3. <nav-bar height="328" backPath="workspace" title="材料采集" :filterPickerData="state.filterPickerData" :tabList="state.tabList" :onlyTitle="false" :showFilterPicker="true" :showTabs="true" rightWidth="0rpx" @CommonFilterData="CommonFilterData">
  4. <template #tabs_right_content>
  5. <view class="add_btn" @click="handleAddEdit('add')">
  6. <image class="add_icon" src="@/static/image/icon/plusempty.png"></image>
  7. <text class="add_text">新建</text>
  8. </view>
  9. </template>
  10. </nav-bar>
  11. <view class="page_content">
  12. <scroll-view
  13. class="scroll_view_y"
  14. :scroll-top="state.scrollTop"
  15. scroll-y="true"
  16. :refresher-enabled="false"
  17. :enable-back-to-top="true"
  18. :show-scrollbar="false"
  19. :scroll-with-animation="true"
  20. refresher-default-style="none"
  21. refresher-background="#F8F9FD"
  22. :refresher-triggered="state.isRefreshing"
  23. @scrolltolower="OnLoadMore"
  24. @refresherrefresh="OnRefresh"
  25. @scroll="OnScroll">
  26. <view class="refresh_loading" v-if="state.isRefreshing"><uni-load-more status="loading" /></view>
  27. <view class="notice_list">
  28. <view v-for="item in state.pageList" :key="item.id" class="notice_item">
  29. <!-- 任务内容 -->
  30. <view class="item_content">
  31. <view class="notice_title_row">
  32. <image class="notice_icon" src="@/static/image/materialCollection/docIcon.png" mode="aspectFit"></image>
  33. <text class="notice_title">{{ item.taskName }}</text>
  34. </view>
  35. <view class="notice_meta">
  36. <view class="status_tag" :class="statusClassMap[item.taskStatus] || ''">
  37. <text>{{ taskStatusMap[item.taskStatus] }}</text>
  38. </view>
  39. <view class="need_shenhe" v-if="item.auditMechanism">
  40. <text>审</text>
  41. </view>
  42. <text class="meta_text textLength">{{ truncateText(item.departmentName, 5) }}</text>
  43. <text class="meta_text textLength">{{ truncateText(item.materialCategoryName, 5) }}</text>
  44. <text class="meta_text">{{ truncateText(item.createdBy, 5) }}</text>
  45. </view>
  46. </view>
  47. <!-- 任务底部 -->
  48. <view class="item_bottom">
  49. <view class="notice_stats">
  50. <text class="stats_text" v-if="item.taskStatus === 0">开始时间:{{ item.startTime }}</text>
  51. <text class="stats_text" v-else-if="item.taskStatus === 1">剩余时间:{{ remainingDays(item.endTime) }}天</text>
  52. <text class="stats_text" v-else>结束时间:{{ item.endTime }}</text>
  53. </view>
  54. <view class="notice_actions">
  55. <view class="action_btn delete" :class="{ disable: !!item.submitNum }" @click="handleDelete(item)">
  56. <text>删除</text>
  57. </view>
  58. <view class="action_btn edit" @click="handleAddEdit('edit',item)">
  59. <text>编辑</text>
  60. </view>
  61. <view class="action_btn edit" :class="{ disableLock: item.taskStatus === 0 }" @click="handleDetail(item.taskStatus,item.id)">
  62. <text>查看</text>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <view class="no_data" v-if="!state.isLoading && state.pageList.length == 0">
  69. <image class="no_data_img" src="@/static/image/bg/no_data.png"></image>
  70. <text class="no_data_text">暂无数据</text>
  71. </view>
  72. <uni-load-more v-if="state.pageList.length > 0" :status="state.loadStatus" />
  73. </scroll-view>
  74. </view>
  75. <!-- 删除确认框 -->
  76. <popupDialog ref="popupDelDialogRef" :showFootBorder="true" :content="state.popupDelDialog.content" @DialogConfirm="DialogDelConfirm" />
  77. </template>
  78. <script setup>
  79. import { reactive,ref,nextTick, onMounted,onUnmounted } from 'vue';
  80. import navBar from '@/components/navBar.vue';
  81. import popupDialog from '@/components/popupDialog.vue';
  82. import {findCollectionTask,getSchoolYearList,getCategoryList,deleteCollectionTask} from '@/reqApi/notification.js';
  83. import { truncateText,remainingDays } from '@/common/common.js';
  84. import { onShow } from '@dcloudio/uni-app';
  85. const state = reactive({
  86. filterPickerData: [{
  87. valueIndex:0,//默认值索引
  88. defaultValue:'',//默认值
  89. list:[]
  90. },{
  91. valueIndex:0,//默认值索引
  92. defaultValue:'',//默认值
  93. list:[]
  94. },{
  95. valueIndex:0,//默认值索引
  96. defaultValue:'',//默认值
  97. list:[]
  98. }],
  99. tabList: [{//0-待开始 1-进行中 2-已结束 全部-null
  100. label: '全部',
  101. value: ''
  102. }, {
  103. label: '待开始',
  104. value: 0
  105. }, {
  106. label: '进行中',
  107. value: 1
  108. }, {
  109. label: '已结束',
  110. value: 2
  111. }],
  112. params:{//参数
  113. schoolYearCode: '',//学年
  114. schoolYearId:'',//学年id
  115. departmentId:'',//归属部门
  116. materialCategory:'',//材料类目
  117. taskName:'',//任务名称
  118. taskStatus:null,//任务状态 0-待开始 1-进行中 2-已结束 全部-null
  119. pageSize: 30,
  120. pageNum: 1,
  121. },
  122. pageList:[],//列表数据
  123. scrollTop:0,
  124. oldScrollTop:0,
  125. isRefreshing:false,//设置当前下拉刷新状态,true 表示下拉刷新已经被触发,false 表示下拉刷新未被触发
  126. isLoading:true,//加载中
  127. noMoreData:false,//没有更多数据了
  128. loadStatus:'more',//loading状态
  129. popupDelDialog:{//删除确认框
  130. content:'',
  131. id:''
  132. }
  133. })
  134. const popupDelDialogRef = ref(null);
  135. const statusClassMap = {
  136. 0: 'status_pending',
  137. 1: 'status_published',
  138. 2: 'status_closed'
  139. };
  140. const taskStatusMap = {
  141. 0: '待开始',
  142. 1: '进行中',
  143. 2: '已结束'
  144. };
  145. // 学年学期列表
  146. const fetchSchoolYearList = async () => {
  147. try {
  148. const res = await getSchoolYearList();
  149. if (res.data && Array.isArray(res.data)) {
  150. const resData = res.data;
  151. state.filterPickerData[0].list = resData.map(item=>({
  152. ...item,
  153. label:item.schoolYearName,
  154. value:item.id
  155. }))
  156. const schoolYearId = state.filterPickerData?.[0]?.list?.[0]?.value || '';
  157. const schoolYearCode = state.filterPickerData?.[0]?.list?.[0]?.schoolYearCode || '';
  158. state.filterPickerData[0].defaultValue = schoolYearId;
  159. state.params.schoolYearId = schoolYearId;//默认值学年id
  160. state.params.schoolYearCode = schoolYearCode;//默认值学年code
  161. }
  162. } catch (error) {
  163. console.error('获取学年学期列表失败:', error);
  164. }
  165. };
  166. // 归属分类
  167. const fetchCategoryList = async () => {
  168. try {
  169. const res = await getCategoryList();
  170. if (res.data && Array.isArray(res.data)) {
  171. const categoryData = res.data;
  172. const categoryList = categoryData.map(item=>({
  173. ...item,
  174. label:item.categoryName,
  175. value:item.id
  176. }))
  177. state.filterPickerData[1].list = [{label:'归属分类',value:''}].concat(...categoryList);
  178. }
  179. } catch (error) {
  180. console.error('获取分类列表失败:', error);
  181. }
  182. };
  183. //切换条件选择器
  184. const CommonFilterData = (filterOptions,type) => {
  185. const {searchWord,filterOpts,tabsSelected} = filterOptions;
  186. const {valueIndex, index,filterPickerValue} = filterOpts;
  187. if(type == 'filterPicker'){
  188. state.params.departmentId = filterPickerValue[1];//归属部门
  189. state.params.materialCategory = filterPickerValue[2];//材料类目
  190. state.filterPickerData[index].valueIndex = valueIndex;
  191. if(index == 1){
  192. state.filterPickerData[2].valueIndex = 0;
  193. const parentData = state.filterPickerData[1].list;//分类归属
  194. const childrenData = parentData?.[valueIndex]?.childList || [];//材料类目
  195. const childrenList = childrenData.map(item=>({
  196. ...item,
  197. label:item?.categoryName || '',
  198. value:item?.id ?? ''
  199. }))
  200. if(childrenList.length){
  201. childrenList.unshift({
  202. label:'材料类目',
  203. value:''
  204. })
  205. }
  206. state.filterPickerData[2].list = childrenList;
  207. }else if(index == 0){//学年
  208. state.params.schoolYearId = filterPickerValue[0];//学年id
  209. state.params.schoolYearCode = state.filterPickerData?.[index]?.list?.[valueIndex]?.schoolYearCode || '';//学年code
  210. }
  211. }else if(type == 'search'){
  212. state.params.taskName = searchWord;//任务名称
  213. }else{
  214. state.params.taskStatus = tabsSelected;//任务状态 0-待开始 1-进行中 2-已结束 全部-null
  215. }
  216. OnLoadData(true);
  217. }
  218. /*
  219. *任务列表
  220. * initPage:初始分页 从第一开始
  221. */
  222. const OnLoadData = (initPage) => {
  223. // uni.showLoading({
  224. // title: '加载中'
  225. // });
  226. if (initPage) state.params.pageNum = 1;//如果是下拉刷新、重新查询 默认加载第一页
  227. state.isLoading = true;
  228. state.loadStatus = 'loading';
  229. const params = {
  230. schoolYearCode: state.params.schoolYearCode,
  231. schoolYearId: state.params.schoolYearId,
  232. departmentId: state.params.departmentId,
  233. materialCategory: state.params.materialCategory,
  234. taskName: state.params.taskName,
  235. taskStatus: state.params.taskStatus,
  236. pageNum: state.params.pageNum,
  237. pageSize: state.params.pageSize
  238. };
  239. findCollectionTask(params).then(res=>{
  240. if (res.code == 200) {
  241. const total = Number(res?.data?.total) || 0;//总数
  242. const pages = Math.ceil(total / state.params.pageSize);//总页数
  243. const recordsData = res?.data?.records || []
  244. state.pageList = initPage ? recordsData : [...state.pageList,...recordsData];
  245. state.noMoreData = state.params.pageNum == pages;
  246. state.params.pageNum++;
  247. }
  248. }).finally(()=>{
  249. // uni.hideLoading();
  250. state.isLoading = false;
  251. state.isRefreshing = false;//下拉刷新未被触发
  252. if(state.noMoreData){
  253. state.loadStatus = 'no-more';
  254. }else{
  255. state.loadStatus = 'more';
  256. }
  257. //返回到页面顶部
  258. if(initPage){
  259. GoTop();
  260. }
  261. });
  262. };
  263. // 自定义下拉刷新被触发 下拉刷新
  264. const OnRefresh = () =>{
  265. state.isRefreshing = true;//下拉刷新已经被触发
  266. OnLoadData(true);
  267. }
  268. //滚动到底部/右边 触发上拉刷新
  269. const OnLoadMore = () => {
  270. if (state.isLoading || state.noMoreData) return;
  271. OnLoadData(false);
  272. }
  273. // 滚动时触发
  274. const OnScroll = (e) => {
  275. state.oldScrollTop = e.detail.scrollTop;
  276. }
  277. //返回到顶部
  278. const GoTop = () => {
  279. // 解决view层不同步的问题
  280. state.scrollTop = state.oldScrollTop;
  281. nextTick(() => {
  282. state.scrollTop = 0
  283. });
  284. }
  285. //删除弹框
  286. const handleDelete = (item) => {
  287. if(!!item.submitNum) return false
  288. state.popupDelDialog.content = `确定要删除当前任务吗?`;
  289. state.popupDelDialog.id = item.id;
  290. popupDelDialogRef.value.OpenDialog();
  291. }
  292. //确定删除
  293. const DialogDelConfirm = () => {
  294. deleteCollectionTask(state.popupDelDialog.id).then(res=>{
  295. if(res.code == 200){
  296. uni.showToast({
  297. title: '删除成功!',
  298. icon: 'none'
  299. });
  300. OnLoadData(true);
  301. }else{
  302. uni.showToast({
  303. title: res.msg,
  304. icon: 'none'
  305. });
  306. }
  307. })
  308. }
  309. //新建、编辑
  310. const handleAddEdit = (type,item) => {
  311. uni.navigateTo({
  312. url: `/pages/materialCollection/taskOverview/addEdit?taskId=${item?.id || ''}`
  313. });
  314. };
  315. //查看任务
  316. const handleDetail = (taskStatus,id) => {
  317. if (taskStatus === 0) return;
  318. uni.navigateTo({
  319. url: `/pages/materialCollection/taskOverview/taskDetail?taskId=${id}&taskStatus=${taskStatus}`
  320. });
  321. };
  322. onMounted(async () => {
  323. await fetchSchoolYearList();//学年学期列表
  324. fetchCategoryList();//归属分类
  325. OnLoadData(true);
  326. });
  327. onShow(()=>{
  328. const isLoadCollectTaskOverview = uni.getStorageSync('isLoadCollectTaskOverview');
  329. if(isLoadCollectTaskOverview){
  330. OnLoadData(true);
  331. }
  332. })
  333. onUnmounted(()=>{
  334. uni.setStorageSync('isLoadCollectTaskOverview', false);
  335. })
  336. </script>
  337. <style lang="scss" scoped>
  338. .page_content{
  339. height: calc(100% - 464rpx);
  340. .scroll_view_y{
  341. height: 100%;
  342. .refresh_loading{
  343. padding: 10rpx 0;
  344. }
  345. }
  346. }
  347. .notice_list {
  348. width: 100%;
  349. display: flex;
  350. flex-direction: column;
  351. }
  352. .notice_item {
  353. background-color: #F9FAFF;
  354. border-radius: 20rpx;
  355. margin-top: 24rpx;
  356. border: 2rpx solid #E4E7ED;
  357. &:first-child{
  358. margin-top: 16rpx;
  359. }
  360. .item_content {
  361. padding: 24rpx 16rpx;
  362. .notice_title_row {
  363. display: flex;
  364. align-items: center;
  365. margin-bottom: 16rpx;
  366. .notice_icon {
  367. width: 32rpx;
  368. height: 32rpx;
  369. margin-right: 16rpx;
  370. }
  371. .notice_title {
  372. flex: 1;
  373. font-weight: 500;
  374. font-size: 28rpx;
  375. color: #333333;
  376. overflow: hidden;
  377. text-overflow: ellipsis;
  378. white-space: nowrap;
  379. }
  380. }
  381. .notice_meta {
  382. display: flex;
  383. align-items: center;
  384. flex-wrap: wrap;
  385. gap: 16rpx;
  386. .status_tag {
  387. font-size: 24rpx;
  388. height: 48rpx;
  389. width: 96rpx;
  390. text-align: center;
  391. line-height: 48rpx;
  392. border-radius: 4rpx;
  393. font-weight: 400;
  394. border-radius: 8rpx;
  395. &.status_pending {
  396. background: rgba(46, 100, 250, 0.1);
  397. color: #2E64FA;
  398. }
  399. &.status_published {
  400. background: rgba(82, 196, 26, 0.1);
  401. color: #2BC644;
  402. }
  403. &.status_closed {
  404. background: #6666661a;
  405. color: #666666;
  406. }
  407. }
  408. .need_shenhe {
  409. width: 48rpx;
  410. height: 48rpx;
  411. background: rgba(245,108,108,0.1);
  412. border-radius: 8rpx 8rpx 8rpx 8rpx;
  413. font-size: 24rpx;
  414. color: #F56C6C;
  415. display: inline-flex;
  416. align-items: center;
  417. justify-content: center;
  418. }
  419. .meta_text {
  420. font-size: 24rpx;
  421. color: #999999;
  422. line-height: 48rpx;
  423. }
  424. .textLength {
  425. max-width: 160rpx;
  426. overflow: hidden;
  427. text-overflow: ellipsis;
  428. white-space: nowrap;
  429. }
  430. }
  431. }
  432. .item_bottom {
  433. border-top: 2rpx solid #E4E7ED;
  434. display: flex;
  435. flex-direction: row;
  436. justify-content: space-between;
  437. align-items: center;
  438. padding: 24rpx 16rpx;
  439. .notice_stats {
  440. display: flex;
  441. .stats_text {
  442. font-size: 24rpx;
  443. color: #999999;
  444. &:first-child {
  445. margin-right: 32rpx;
  446. }
  447. }
  448. }
  449. .notice_actions {
  450. display: flex;
  451. justify-content: flex-end;
  452. gap: 16rpx;
  453. flex-shrink: 0;
  454. .action_btn {
  455. font-size: 24rpx;
  456. padding: 12rpx 24rpx;
  457. border-radius: 8rpx;
  458. border: 2rpx solid transparent;
  459. &.delete {
  460. border-color: #F56C6C;
  461. color: #F56C6C;
  462. background-color: #FFFFFF;
  463. &.disabled {
  464. border-color: #C0C4CC;
  465. color: #C0C4CC;
  466. background-color: #FFFFFF;
  467. }
  468. }
  469. &.edit {
  470. border-color: #2E64FA;
  471. color: #2E64FA;
  472. background-color: #FFFFFF;
  473. &.disabled {
  474. border-color: #C0C4CC;
  475. color: #C0C4CC;
  476. background-color: #FFFFFF;
  477. }
  478. }
  479. &.disable {
  480. color: #C0C4CC !important;
  481. cursor: not-allowed;
  482. border-color: #C0C4CC !important;
  483. }
  484. &.disableLock{
  485. color: #C0C4CC !important;
  486. cursor: not-allowed;
  487. background-color: #F3F3F3 !important;
  488. border-color: #F3F3F3 !important;
  489. }
  490. }
  491. }
  492. }
  493. &:last-child {
  494. margin-bottom: 0;
  495. }
  496. }
  497. :deep(.scroll_tabs){
  498. height: 72rpx;
  499. align-items: center;
  500. .scroll_tabs_view{
  501. height: 56rpx;
  502. }
  503. }
  504. :deep(.filter_picker){
  505. gap: 16rpx !important;
  506. .item_filter_picker{
  507. width: calc((100% - 16rpx * 2) / 3) !important;
  508. }
  509. }
  510. .add_btn{
  511. width: 148rpx;
  512. height: 72rpx;
  513. background-color: #2E64FA;
  514. border-radius: 8rpx;
  515. border: 2rpx solid #2E64FA;
  516. display: inline-flex;
  517. align-items: center;
  518. justify-content: center;
  519. .add_icon{
  520. width: 28rpx;
  521. height: 28rpx;
  522. margin-right: 8rpx;
  523. }
  524. .add_text{
  525. font-weight: 500;
  526. font-size: 28rpx;
  527. color: #FFFFFF;
  528. }
  529. }
  530. </style>