index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view class="todo-container">
  3. <!-- 顶部搜索 + tab -->
  4. <view class="search-header">
  5. <view class="search-row">
  6. <uv-input
  7. placeholder="请输入审批名称"
  8. v-model="queryParams.instTitle"
  9. prefixIcon="search"
  10. prefixIconStyle="color: #999; font-size: 32rpx;"
  11. clearable
  12. shape="circle"
  13. customStyle="background-color: #f5f7fa; border: none;"
  14. ></uv-input>
  15. </view>
  16. <view class="type-tabs">
  17. <uv-tabs
  18. :list="tabList"
  19. :current="currentTab"
  20. @change="onTabChange"
  21. :activeStyle="{ color: '#1c9bfd', fontWeight: 'bold', transform: 'scale(1.05)' }"
  22. :inactiveStyle="{ color: '#666' }"
  23. lineColor="#1c9bfd"
  24. lineWidth="40"
  25. :itemStyle="{ height: '88rpx', flex: 1 }"
  26. :scrollable="false"
  27. ></uv-tabs>
  28. </view>
  29. </view>
  30. <!-- 列表区域 -->
  31. <view class="list-container">
  32. <scroll-view
  33. scroll-y
  34. class="scroll-list"
  35. :scroll-top="scrollTopValue"
  36. scroll-with-animation
  37. refresher-enabled
  38. :refresher-triggered="isTriggered"
  39. @refresherrefresh="onRefresh"
  40. @scroll="onScroll"
  41. @scrolltolower="loadMore"
  42. :show-scrollbar="false"
  43. >
  44. <uv-empty v-if="!todoStore.list.length && loadStatus !== 'loading'" mode="list"></uv-empty>
  45. <view
  46. class="common-list-card"
  47. v-for="item in todoStore.list"
  48. :key="item.id || item.taskId"
  49. >
  50. <view class="card-header">
  51. <text class="title">{{ item.instTitle || '未命名流程' }}</text>
  52. <text
  53. class="status-tag"
  54. :class="item.isFinish == '10' ? 'status-done' : 'status-undo'"
  55. >
  56. {{ item.isFinish == '10' ? '已完成' : '未完成' }}
  57. </text>
  58. </view>
  59. <view class="card-body" @click="viewDetail(item)">
  60. <view class="info-item">
  61. <text class="label">审批类型:</text>
  62. <text class="value">{{ (item as any).defName || '-' }}</text>
  63. </view>
  64. <view class="info-item">
  65. <text class="label">申请人:</text>
  66. <text class="value">{{ item.startUserName || '-' }}</text>
  67. </view>
  68. <view class="info-item">
  69. <text class="label">创建时间:</text>
  70. <text class="value">{{ formatDate(item.createdTime, 'YYYY-MM-DD HH:mm') }}</text>
  71. </view>
  72. </view>
  73. <view class="card-footer" v-if="currentType === 'approval'">
  74. <uv-button
  75. v-if="item.isFinish == '20'"
  76. type="primary"
  77. text="审批"
  78. size="small"
  79. customStyle="padding: 0 24rpx; height: 60rpx;"
  80. @click="openApprove(item)"
  81. ></uv-button>
  82. </view>
  83. </view>
  84. <uv-load-more
  85. v-if="todoStore.list.length > 0 || loadStatus === 'loading'"
  86. :status="loadStatus"
  87. @loadmore="loadMore"
  88. ></uv-load-more>
  89. </scroll-view>
  90. <uv-back-top
  91. :scrollTop="currentScrollTop"
  92. :bottom="100"
  93. :right="30"
  94. @click="backToTop"
  95. ></uv-back-top>
  96. </view>
  97. </view>
  98. </template>
  99. <script setup lang="ts">
  100. import { ref, computed, nextTick, watch } from 'vue';
  101. import { onLoad, onShow } from '@dcloudio/uni-app';
  102. import { debounce } from 'lodash-es';
  103. import { useTodoStore } from '@/store/modules/todo';
  104. import { onRouterPush } from '@/utils/router';
  105. import { formatDate } from '@/utils/date';
  106. import type { TodoItem } from '@/types/todo';
  107. import { TODO_TAB_LIST } from '@/constants/index';
  108. const todoStore = useTodoStore();
  109. const tabList = ref(TODO_TAB_LIST);
  110. const currentTab = ref(0);
  111. const currentType = computed(() => tabList.value[currentTab.value].type);
  112. const queryParams = ref({
  113. platformId: 100010,
  114. defName: '',
  115. instTitle: '',
  116. pageNum: 1,
  117. pageSize: 20,
  118. orderBy: ''
  119. });
  120. const scrollTopValue = ref(0);
  121. const currentScrollTop = ref(0);
  122. const isTriggered = ref(false);
  123. const loadStatus = ref<'loadmore' | 'loading' | 'nomore'>('loadmore');
  124. /**
  125. * 获取列表数据
  126. */
  127. const fetchListData = async (reset = false) => {
  128. if (todoStore.loading) return;
  129. if (reset) {
  130. queryParams.value.pageNum = 1;
  131. }
  132. loadStatus.value = 'loading';
  133. const res = await todoStore.fetchList(currentType.value, queryParams.value, !reset);
  134. if (res.success) {
  135. if (todoStore.list.length >= todoStore.total) {
  136. loadStatus.value = 'nomore';
  137. } else {
  138. loadStatus.value = 'loadmore';
  139. queryParams.value.pageNum += 1;
  140. }
  141. } else {
  142. loadStatus.value = 'nomore';
  143. }
  144. if (reset) {
  145. isTriggered.value = false;
  146. }
  147. };
  148. const onTabChange = (e: any) => {
  149. currentTab.value = e.index;
  150. fetchListData(true);
  151. };
  152. // 监听查询条件变化
  153. const debouncedFetchList = debounce(() => {
  154. fetchListData(true);
  155. }, 500);
  156. watch(() => queryParams.value.instTitle, () => {
  157. debouncedFetchList();
  158. });
  159. const onRefresh = async () => {
  160. isTriggered.value = true;
  161. await fetchListData(true);
  162. };
  163. const loadMore = async () => {
  164. if (loadStatus.value !== 'loadmore') return;
  165. await fetchListData(false);
  166. };
  167. const onScroll = (e: any) => {
  168. currentScrollTop.value = e.detail.scrollTop;
  169. };
  170. const backToTop = () => {
  171. scrollTopValue.value = currentScrollTop.value;
  172. nextTick(() => {
  173. scrollTopValue.value = 0;
  174. });
  175. };
  176. const viewDetail = (item: TodoItem) => {
  177. onRouterPush(`/pages/todo/detail?mode=view&id=${item.id || ''}&taskId=${item.taskId || ''}&taskCode=${item.businessCode || ''}&defCode=${item.defCode || ''}`);
  178. };
  179. const openApprove = (item: TodoItem) => {
  180. onRouterPush(`/pages/todo/detail?mode=approval&id=${item.id || ''}&taskId=${item.taskId || ''}&taskCode=${item.businessCode || ''}&defCode=${item.defCode || ''}`);
  181. };
  182. onShow(() => {
  183. fetchListData(true);
  184. });
  185. onLoad(() => {
  186. // onLoad 只执行一次基础初始化
  187. });
  188. </script>
  189. <style lang="scss" scoped>
  190. .todo-container {
  191. height: calc(100vh - var(--window-top));
  192. display: flex;
  193. flex-direction: column;
  194. background-color: #f5f7fa;
  195. box-sizing: border-box;
  196. }
  197. .search-header {
  198. background-color: #fff;
  199. padding: 20rpx 30rpx 0;
  200. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.03);
  201. position: sticky;
  202. top: 0;
  203. z-index: 99;
  204. .search-row {
  205. margin-bottom: 24rpx;
  206. }
  207. .type-tabs {
  208. margin-top: 10rpx;
  209. }
  210. }
  211. .list-container {
  212. padding: 30rpx;
  213. flex: 1;
  214. overflow: hidden;
  215. box-sizing: border-box;
  216. }
  217. .scroll-list {
  218. flex: 1;
  219. height: 100%;
  220. }
  221. .common-list-card {
  222. .card-header {
  223. .status-tag {
  224. &.status-done {
  225. color: #52c41a;
  226. background-color: rgba(82, 196, 26, 0.1);
  227. }
  228. &.status-undo {
  229. color: #fa8c16;
  230. background-color: rgba(250, 173, 20, 0.1);
  231. }
  232. }
  233. }
  234. }
  235. /* 审批弹窗样式已移除,审批在详情页中处理 */
  236. </style>