index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <view class="todo-container">
  3. <!-- 顶部搜索 + tab -->
  4. <view class="search-header">
  5. <view class="search-row">
  6. <uv-input placeholder="请输入审批名称" v-model="queryParams.instTitle" prefixIcon="search"
  7. prefixIconStyle="color: #999; font-size: 32rpx;" clearable shape="circle"
  8. customStyle="background-color: #f5f7fa; border: none;"></uv-input>
  9. </view>
  10. <view class="type-tabs">
  11. <uv-tabs :list="tabList" :current="currentTab" @change="onTabChange"
  12. :activeStyle="{ color: '#1c9bfd', fontWeight: 'bold', transform: 'scale(1.05)' }"
  13. :inactiveStyle="{ color: '#666' }" lineColor="#1c9bfd" lineWidth="40"
  14. :itemStyle="{ height: '88rpx', flex: 1 }" :scrollable="false"></uv-tabs>
  15. </view>
  16. </view>
  17. <!-- 列表区域 -->
  18. <view class="list-container">
  19. <scroll-view scroll-y class="scroll-list" :scroll-top="scrollTopValue" scroll-with-animation refresher-enabled
  20. :refresher-triggered="isTriggered" @refresherrefresh="onRefresh" @scroll="onScroll" @scrolltolower="loadMore"
  21. :show-scrollbar="false">
  22. <uv-empty v-if="!todoStore.list.length && loadStatus !== 'loading'" mode="list"></uv-empty>
  23. <view
  24. class="common-list-card animate-fade-in"
  25. v-for="(item, index) in todoStore.list"
  26. :key="item.id || item.taskId"
  27. :style="{ animationDelay: `${(index % 10) * 0.05}s` }"
  28. >
  29. <view class="card-header">
  30. <text class="title">{{ item.instTitle || '未命名流程' }}</text>
  31. <text class="status-tag" :class="item.isFinish == '10' ? 'status-done' : 'status-undo'">
  32. {{ item.isFinish == '10' ? '已完成' : '未完成' }}
  33. </text>
  34. </view>
  35. <view class="card-body" @click="viewDetail(item)">
  36. <view class="info-item">
  37. <text class="label">审批类型:</text>
  38. <text class="value">{{ (item as any).defName || '-' }}</text>
  39. </view>
  40. <view class="info-item">
  41. <text class="label">申请人:</text>
  42. <text class="value">{{ item.startUserName || '-' }}</text>
  43. </view>
  44. <view class="info-item">
  45. <text class="label">创建时间:</text>
  46. <text class="value">{{ formatDate(item.createdTime, 'YYYY-MM-DD') }}</text>
  47. </view>
  48. </view>
  49. <view class="card-footer" v-if="currentType === 'approval'">
  50. <uv-button v-if="item.isFinish == '20'" type="primary" text="审批" size="small"
  51. customStyle="padding: 0 24rpx; height: 60rpx;" @click="openApprove(item)"></uv-button>
  52. </view>
  53. </view>
  54. <uv-load-more v-if="todoStore.list.length > 0 || loadStatus === 'loading'" :status="loadStatus"
  55. @loadmore="loadMore"></uv-load-more>
  56. </scroll-view>
  57. <uv-back-top :scrollTop="currentScrollTop" :bottom="100" :right="30" @click="backToTop"></uv-back-top>
  58. </view>
  59. </view>
  60. </template>
  61. <script setup lang="ts">
  62. import { ref, computed, nextTick, watch } from 'vue';
  63. import { onLoad, onShow } from '@dcloudio/uni-app';
  64. import { debounce } from 'lodash-es';
  65. import { useTodoStore } from '@/store/modules/todo';
  66. import { onRouterPush } from '@/utils/router';
  67. import { formatDate } from '@/utils/date';
  68. import type { TodoItem } from '@/types/todo';
  69. import { TODO_TAB_LIST } from '@/constants/index';
  70. import { useExecutionApi } from '@/api/execution';
  71. import { useProjectApi } from '@/api/project';
  72. import to from 'await-to-js';
  73. const todoStore = useTodoStore();
  74. const executionApi = useExecutionApi();
  75. const projectApi = useProjectApi();
  76. const tabList = ref(TODO_TAB_LIST);
  77. const currentTab = ref(0);
  78. const currentType = computed(() => tabList.value[currentTab.value].type);
  79. const queryParams = ref({
  80. platformId: 100010,
  81. defName: '',
  82. instTitle: '',
  83. pageNum: 1,
  84. pageSize: 20,
  85. orderBy: ''
  86. });
  87. const scrollTopValue = ref(0);
  88. const currentScrollTop = ref(0);
  89. const isTriggered = ref(false);
  90. const loadStatus = ref<'loadmore' | 'loading' | 'nomore'>('loadmore');
  91. /**
  92. * 获取列表数据
  93. */
  94. const fetchListData = async (reset = false) => {
  95. if (todoStore.loading) return;
  96. if (reset) {
  97. queryParams.value.pageNum = 1;
  98. }
  99. loadStatus.value = 'loading';
  100. const res = await todoStore.fetchList(currentType.value, queryParams.value, !reset);
  101. if (res.success) {
  102. if (todoStore.list.length >= todoStore.total) {
  103. loadStatus.value = 'nomore';
  104. } else {
  105. loadStatus.value = 'loadmore';
  106. queryParams.value.pageNum += 1;
  107. }
  108. } else {
  109. loadStatus.value = 'nomore';
  110. }
  111. if (reset) {
  112. isTriggered.value = false;
  113. }
  114. };
  115. const onTabChange = (e: any) => {
  116. currentTab.value = e.index;
  117. fetchListData(true);
  118. };
  119. // 监听查询条件变化
  120. const debouncedFetchList = debounce(() => {
  121. fetchListData(true);
  122. }, 500);
  123. watch(() => queryParams.value.instTitle, () => {
  124. debouncedFetchList();
  125. });
  126. const onRefresh = async () => {
  127. isTriggered.value = true;
  128. await fetchListData(true);
  129. };
  130. const loadMore = async () => {
  131. if (loadStatus.value !== 'loadmore') return;
  132. await fetchListData(false);
  133. };
  134. const onScroll = (e: any) => {
  135. currentScrollTop.value = e.detail.scrollTop;
  136. };
  137. const backToTop = () => {
  138. scrollTopValue.value = currentScrollTop.value;
  139. nextTick(() => {
  140. scrollTopValue.value = 0;
  141. });
  142. };
  143. const viewDetail = (item: TodoItem) => {
  144. onRouterPush(`/pages/todo/detail?mode=view&id=${item.id || ''}&taskId=${item.taskId || ''}&taskCode=${item.businessCode || ''}&defCode=${item.defCode || ''}`);
  145. };
  146. const openApprove = async (item: TodoItem) => {
  147. // 审批前增加学术不端行为校验
  148. uni.showLoading({ title: '校验中...', mask: true });
  149. // 1. 获取参与者列表,找出发起人
  150. const [err, res] = await to(executionApi.getParticipantByProcInstID({ id: item.id }));
  151. if (err || !res?.data) {
  152. uni.hideLoading();
  153. // 如果获取失败,出于流程通畅考虑,直接跳转
  154. onRouterPush(`/pages/todo/detail?mode=approval&id=${item.id || ''}&taskId=${item.taskId || ''}&taskCode=${item.businessCode || ''}&defCode=${item.defCode || ''}`);
  155. return;
  156. }
  157. const participants = res.data as any[];
  158. const startUser = participants.find(p => p.type === 'start');
  159. const startUserId = startUser?.userId;
  160. if (!startUserId) {
  161. uni.hideLoading();
  162. onRouterPush(`/pages/todo/detail?mode=approval&id=${item.id || ''}&taskId=${item.taskId || ''}&taskCode=${item.businessCode || ''}&defCode=${item.defCode || ''}`);
  163. return;
  164. }
  165. // 2. 调用学术不端校验接口
  166. const [err2, res2] = await to(projectApi.checkUserViolationStatus({ personId: startUserId }));
  167. uni.hideLoading();
  168. if (!err2 && res2?.data?.hasViolation) {
  169. const { restrictions } = res2.data;
  170. let restrictionList = [];
  171. if (restrictions.limitProjectApply) restrictionList.push('限制项目申报');
  172. if (restrictions.limitFundApply) restrictionList.push('限制申请经费');
  173. if (restrictions.limitRewardApply) restrictionList.push('限制成为奖励对象');
  174. uni.showModal({
  175. title: '学术不端行为提醒',
  176. content: `发起人 [${startUser?.userName || '未知'}] 存在学术不端记录,已被限制:${restrictionList.join('、')}。`,
  177. confirmText: '我知道了',
  178. showCancel: false
  179. });
  180. // 不跳转
  181. } else {
  182. onRouterPush(`/pages/todo/detail?mode=approval&id=${item.id || ''}&taskId=${item.taskId || ''}&taskCode=${item.businessCode || ''}&defCode=${item.defCode || ''}`);
  183. }
  184. };
  185. onShow(() => {
  186. fetchListData(true);
  187. });
  188. onLoad(() => {
  189. // onLoad 只执行一次基础初始化
  190. });
  191. </script>
  192. <style lang="scss" scoped>
  193. .todo-container {
  194. height: calc(100vh - var(--window-top));
  195. display: flex;
  196. flex-direction: column;
  197. background-color: #f5f7fa;
  198. box-sizing: border-box;
  199. }
  200. .search-header {
  201. background-color: #fff;
  202. padding: 20rpx 30rpx 0;
  203. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.03);
  204. position: sticky;
  205. top: 0;
  206. z-index: 99;
  207. .search-row {
  208. margin-bottom: 24rpx;
  209. }
  210. .type-tabs {
  211. margin-top: 10rpx;
  212. }
  213. }
  214. .list-container {
  215. padding: 30rpx;
  216. flex: 1;
  217. overflow: hidden;
  218. box-sizing: border-box;
  219. }
  220. .scroll-list {
  221. flex: 1;
  222. height: 100%;
  223. }
  224. // 移除本地 status-tag 样式,统一使用 global 样式
  225. </style>