index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <view class="list-page-container">
  3. <view class="search-header">
  4. <view class="search-row">
  5. <uv-input placeholder="请输入项目名称" v-model="queryParams.projectName" prefixIcon="search"
  6. prefixIconStyle="color: #999; font-size: 32rpx;" clearable shape="circle"
  7. customStyle="background-color: #f5f7fa; border: none;" @confirm="onSearch"></uv-input>
  8. </view>
  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" :itemStyle="{ height: '88rpx', flex: 1 }"
  14. :scrollable="false"></uv-tabs>
  15. </view>
  16. <view class="list-container">
  17. <scroll-view scroll-y class="scroll-list" :scroll-top="scrollTopValue" scroll-with-animation refresher-enabled
  18. :refresher-triggered="isTriggered" @refresherrefresh="onRefresh" @scroll="onScroll" @scrolltolower="loadMore"
  19. :show-scrollbar="false">
  20. <uv-empty v-if="!list.length && loadStatus !== 'loading'" mode="list"></uv-empty>
  21. <view class="common-list-card" v-for="item in list" :key="item.id" @click="handleCardClick(item)">
  22. <view class="card-header">
  23. <text class="title">打款单位:{{ item.unit || '-' }}</text>
  24. <text class="status-tag"
  25. :class="item.status == '10' ? 'status-undo' : (item.status == '30' ? 'status-undo' : 'status-done')">
  26. {{ item.status == '10' ? '待认领' : (item.status == '30' ? '认领中' : '已认领') }}
  27. </text>
  28. </view>
  29. <view class="card-body">
  30. <!-- <view class="info-item">
  31. <text class="label">到账日期:</text>
  32. <text class="value">{{ item.date ? formatDate(new Date(item.date), 'YYYY-MM-DD') : '-' }}</text>
  33. </view>
  34. <view class="info-item">
  35. <text class="label">经费类型:</text>
  36. <text class="value">{{ getDictLabel(paymentReceivedTypeOptions, item.type) }}</text>
  37. </view> -->
  38. <view class="info-item">
  39. <text class="label">到款金额(元):</text>
  40. <text class="value number-font">{{ amountUnitFormatter(item.amount) }}{{ item.includeTax ? '(含税)' :
  41. '(不含税)' }}</text>
  42. </view>
  43. <!-- <view class="info-item">
  44. <text class="label">管理费(元):</text>
  45. <text class="value number-font">{{ amountUnitFormatter(item.manageAmount) }}</text>
  46. </view>
  47. <view class="info-item">
  48. <text class="label">税费(元):</text>
  49. <text class="value number-font">{{ amountUnitFormatter(item.taxAmount) }}</text>
  50. </view> -->
  51. <view class="info-item" v-if="item.projectName">
  52. <text class="label">项目名称:</text>
  53. <text class="value text-ellipsis">{{ item.projectName }}</text>
  54. </view>
  55. <view class="info-item" v-if="item.projectLeaderName">
  56. <text class="label">项目负责人:</text>
  57. <text class="value">{{ item.projectLeaderName }}</text>
  58. </view>
  59. <!-- <view class="info-item" v-if="item.projectDeptName">
  60. <text class="label">科室:</text>
  61. <text class="value">{{ item.projectDeptName }}</text>
  62. </view>
  63. <view class="info-item" v-if="item.createdName">
  64. <text class="label">创建人:</text>
  65. <text class="value">{{ item.createdName }}</text>
  66. </view>
  67. <view class="info-item" v-if="item.createdTime">
  68. <text class="label">创建时间:</text>
  69. <text class="value">{{ item.createdTime ? formatDate(new Date(item.createdTime), 'YYYY-MM-DD') : '-'
  70. }}</text>
  71. </view> -->
  72. </view>
  73. <view class="card-actions" @click.stop v-if="isAdmin && (item.status == '10' || item.status == '30')">
  74. <view class="btn-box" v-if="item.status == '10'">
  75. <uv-button text="认领" type="primary" shape="circle" size="small" @click="toClaim(item.id)"></uv-button>
  76. </view>
  77. <view class="btn-box" v-if="item.status == '30'">
  78. <uv-button text="继续认领" type="primary" shape="circle" size="small" @click="toClaim(item.id)"></uv-button>
  79. </view>
  80. </view>
  81. </view>
  82. <uv-load-more v-if="list.length > 0 || loadStatus === 'loading'" :status="loadStatus"
  83. @loadmore="loadMore"></uv-load-more>
  84. </scroll-view>
  85. <uv-back-top :scrollTop="currentScrollTop" :bottom="100" :right="30" @click="backToTop"></uv-back-top>
  86. </view>
  87. </view>
  88. </template>
  89. <script setup lang="ts">
  90. import { ref, nextTick, watch, computed } from 'vue';
  91. import { onLoad } from '@dcloudio/uni-app';
  92. import { debounce } from 'lodash-es';
  93. import { storeToRefs } from 'pinia';
  94. import { useUserStore } from '@/store/modules/user';
  95. import { useFundApi } from '@/api/fund/index';
  96. import { useSystemApi } from '@/api/system/index';
  97. import { onRouterPush } from '@/utils/router';
  98. import { DEFAULT_PAGE_SIZE } from '@/constants/index';
  99. import { formatDate } from '@/utils/date';
  100. const userStore = useUserStore();
  101. const { roles } = storeToRefs(userStore);
  102. const ADMIN_ROLES = ['scientific_research_secretary', 'scientific_research_admin', 'sys_admin', 'admin'];
  103. const isAdmin = computed(() => {
  104. const userRoles = roles.value || [];
  105. return ADMIN_ROLES.some(adminRole =>
  106. userRoles.some((r: any) => r.roleCode === adminRole)
  107. );
  108. });
  109. const allTabs = [{ name: '待认领', type: '10' }, { name: '已认领', type: '20' }, { name: '认领中', type: '30' }];
  110. const tabList = computed(() => {
  111. if (isAdmin.value) {
  112. return allTabs;
  113. }
  114. return [{ name: '已认领', type: '20' }];
  115. });
  116. const fundApi = useFundApi();
  117. const systemApi = useSystemApi();
  118. const currentTab = ref(0);
  119. const queryParams = ref({
  120. status: '10',
  121. projectName: '',
  122. pageNum: 1,
  123. pageSize: DEFAULT_PAGE_SIZE
  124. });
  125. const list = ref<any[]>([]);
  126. const loadStatus = ref<'loadmore' | 'loading' | 'nomore'>('loadmore');
  127. const isTriggered = ref(false);
  128. const scrollTopValue = ref(0);
  129. const currentScrollTop = ref(0);
  130. const paymentReceivedTypeOptions = ref<any[]>([]);
  131. const amountUnitFormatter = (val: any) => {
  132. if (val === null || val === undefined) return '0.00';
  133. const num = Number(val);
  134. return isNaN(num) ? '0.00' : num.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  135. };
  136. const getDictLabel = (options: any[], value: string) => {
  137. const find = options.find((item) => item.dictValue === value);
  138. return find ? find.dictLabel : value || '-';
  139. };
  140. const getDict = async () => {
  141. try {
  142. const res: any = await systemApi.getDictDataByType('PaymentReceivedType');
  143. if (res.code == 200 && res.data) {
  144. paymentReceivedTypeOptions.value = res.data.values || [];
  145. }
  146. } catch (err) {
  147. console.error(err);
  148. }
  149. };
  150. const fetchListData = async (reset = false) => {
  151. if (reset) {
  152. queryParams.value.pageNum = 1;
  153. }
  154. loadStatus.value = 'loading';
  155. try {
  156. const res: any = await fundApi.getList(queryParams.value);
  157. if (res.code == 200) {
  158. const records = res.data?.list || res.list || [];
  159. if (reset) {
  160. list.value = records;
  161. } else {
  162. list.value = [...list.value, ...records];
  163. }
  164. if (records.length < queryParams.value.pageSize) {
  165. loadStatus.value = 'nomore';
  166. } else {
  167. loadStatus.value = 'loadmore';
  168. queryParams.value.pageNum += 1;
  169. }
  170. } else {
  171. loadStatus.value = 'nomore';
  172. }
  173. } catch (error) {
  174. console.error('Fetch error:', error);
  175. loadStatus.value = 'nomore';
  176. } finally {
  177. if (reset) {
  178. isTriggered.value = false;
  179. }
  180. }
  181. };
  182. const onSearch = () => {
  183. fetchListData(true);
  184. };
  185. const debouncedSearch = debounce(() => {
  186. fetchListData(true);
  187. }, 500);
  188. watch(() => queryParams.value.projectName, () => {
  189. debouncedSearch();
  190. });
  191. const onTabChange = (e: any) => {
  192. currentTab.value = e.index;
  193. queryParams.value.status = tabList.value[e.index].type;
  194. fetchListData(true);
  195. };
  196. const onRefresh = async () => {
  197. isTriggered.value = true;
  198. await fetchListData(true);
  199. };
  200. const loadMore = () => {
  201. if (loadStatus.value !== 'loadmore') return;
  202. fetchListData(false);
  203. };
  204. const onScroll = (e: any) => {
  205. currentScrollTop.value = e.detail.scrollTop;
  206. };
  207. const backToTop = () => {
  208. scrollTopValue.value = currentScrollTop.value;
  209. nextTick(() => {
  210. scrollTopValue.value = 0;
  211. });
  212. };
  213. const toViewDetail = (id: number) => {
  214. onRouterPush(`/pages/fund/claim/detail?id=${id}`);
  215. };
  216. const toClaim = (id: number) => {
  217. onRouterPush(`/pages/fund/claim/edit?id=${id}`);
  218. };
  219. const handleCardClick = (item: any) => {
  220. if (isAdmin.value && item.status == '10') {
  221. toClaim(item.id);
  222. } else {
  223. toViewDetail(item.id);
  224. }
  225. };
  226. onLoad(() => {
  227. queryParams.value.status = tabList.value[0]?.type || '20';
  228. getDict();
  229. fetchListData(true);
  230. });
  231. </script>
  232. <style lang="scss" scoped>
  233. .list-page-container {
  234. height: calc(100vh - var(--window-top));
  235. display: flex;
  236. flex-direction: column;
  237. background-color: #f5f7fa;
  238. box-sizing: border-box;
  239. }
  240. .search-header {
  241. background-color: #fff;
  242. padding: 20rpx 30rpx;
  243. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.03);
  244. position: sticky;
  245. top: 0;
  246. z-index: 99;
  247. }
  248. .type-tabs {
  249. background-color: #fff;
  250. padding-bottom: 10rpx;
  251. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.03);
  252. }
  253. .list-container {
  254. padding: 30rpx;
  255. flex: 1;
  256. overflow: hidden;
  257. box-sizing: border-box;
  258. }
  259. .scroll-list {
  260. flex: 1;
  261. height: 100%;
  262. }
  263. .common-list-card {
  264. .card-header {
  265. .status-tag {
  266. &.status-done {
  267. color: #52c41a;
  268. background-color: rgba(82, 196, 26, 0.1);
  269. }
  270. &.status-undo {
  271. color: #fa8c16;
  272. background-color: rgba(250, 173, 20, 0.1);
  273. }
  274. }
  275. }
  276. .card-body {
  277. .info-item {
  278. display: flex;
  279. font-size: 28rpx;
  280. margin-bottom: 12rpx;
  281. line-height: 1.5;
  282. &:last-child {
  283. margin-bottom: 0;
  284. }
  285. .label {
  286. color: #666;
  287. width: 200rpx;
  288. flex-shrink: 0;
  289. }
  290. .value {
  291. color: #333;
  292. flex: 1;
  293. word-break: break-all;
  294. }
  295. }
  296. }
  297. .card-actions {
  298. display: flex;
  299. justify-content: flex-end;
  300. align-items: center;
  301. padding-top: 24rpx;
  302. margin-top: 16rpx;
  303. border-top: 1rpx solid #f0f0f0;
  304. .btn-box {
  305. width: 150rpx;
  306. margin-left: 20rpx;
  307. }
  308. }
  309. }
  310. .number-font {
  311. font-family: 'Helvetica Neue', Arial, sans-serif;
  312. color: #1c9bfd !important;
  313. font-weight: 500;
  314. }
  315. .text-ellipsis {
  316. overflow: hidden;
  317. white-space: nowrap;
  318. text-overflow: ellipsis;
  319. }
  320. </style>