edit.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <view class="edit-container">
  3. <scroll-view scroll-y class="scroll-content">
  4. <view class="form-wrapper">
  5. <uv-form :model="form" ref="formRef" labelWidth="100px" labelPosition="top" :borderBottom="false">
  6. <!-- 1. 到款信息 (Readonly) -->
  7. <CommonSection title="到款信息" :isFirst="true">
  8. <view class="info-list">
  9. <CommonInfoRow label="项目名称" @click="openProjectDialog">
  10. <view style="display: flex; align-items: center; justify-content: flex-end;">
  11. <text v-if="form.projectName" :style="{ color: isContinue ? '#666' : '#333', fontSize: '28rpx' }">{{ form.projectName }}</text>
  12. <text v-else style="color: #c0c4cc; font-size: 28rpx;">请选择项目名称</text>
  13. <uv-icon v-if="!isContinue" name="arrow-right" size="16" color="#c0c4cc" style="margin-left: 10rpx;"></uv-icon>
  14. </view>
  15. </CommonInfoRow>
  16. <CommonInfoRow label="项目负责人" v-if="form.projectLeaderName" :value="form.projectLeaderName" />
  17. <CommonInfoRow label="科室" v-if="form.deptName" :value="form.deptName" />
  18. <CommonInfoRow label="到款金额(元)" :value="formatAmount(form.amount)" isAmount />
  19. <CommonInfoRow label="管理费(元)" :value="formatAmount(form.manageAmount)" isAmount />
  20. <CommonInfoRow label="税费(元)" :value="formatAmount(form.taxAmount)" isAmount />
  21. <CommonInfoRow label="待认领金额(元)" :value="formatAmount(form.allotAmount)" isAmount />
  22. <CommonInfoRow label="到款日期" :value="form.date ? formatDate(new Date(form.date), 'YYYY-MM-DD') : '-'" />
  23. <CommonInfoRow label="到款类型" :value="getDictLabel(paymentReceivedTypeOptions, form.type)" />
  24. <CommonInfoRow label="打款单位" :value="form.unit || '-'" />
  25. </view>
  26. </CommonSection>
  27. <!-- 2. 认领经费 -->
  28. <CommonSection title="认领经费">
  29. <view class="edit-form-list">
  30. <template v-if="detail && detail.length > 0">
  31. <CommonInfoRow
  32. v-for="(item, index) in detail"
  33. :key="item.id || index"
  34. :label="item.subjName"
  35. >
  36. <uv-input
  37. v-model="item.amount"
  38. type="digit"
  39. placeholder="请输入金额"
  40. border="none"
  41. inputAlign="right"
  42. color="#ff4d4f"
  43. customStyle="font-weight: 600; font-family: 'DIN-Medium', sans-serif;"
  44. >
  45. <template v-slot:suffix>
  46. <text style="margin-left: 10rpx; font-size: 28rpx; color: #333; font-weight: normal;">元</text>
  47. </template>
  48. </uv-input>
  49. </CommonInfoRow>
  50. </template>
  51. <template v-else>
  52. <view style="padding: 20rpx; color: #999; text-align: center; font-size: 26rpx;">
  53. 暂无费用列表信息
  54. </view>
  55. </template>
  56. </view>
  57. </CommonSection>
  58. </uv-form>
  59. </view>
  60. </scroll-view>
  61. <!-- 提交按钮 -->
  62. <view class="bottom-bar">
  63. <uv-button type="primary" text="提交认领" @click="submitForm" :loading="loading" customStyle="border-radius: 40rpx;"></uv-button>
  64. </view>
  65. <uv-toast ref="toastRef"></uv-toast>
  66. <!-- 选择项目弹窗 -->
  67. <SelectProject ref="selectProjectRef" @select="onProjectSelected" />
  68. </view>
  69. </template>
  70. <script lang="ts" setup>
  71. import { ref, reactive, computed } from 'vue';
  72. import { onLoad } from '@dcloudio/uni-app';
  73. import { useSystemApi } from '@/api/system/index';
  74. import { useFundApi, useClaimApi } from '@/api/fund/index';
  75. import { formatDate } from '@/utils/date';
  76. import { onRouterPush } from '@/utils/router';
  77. import SelectProject from '@/components/SelectProject/index.vue';
  78. import CommonSection from '@/components/ui/CommonSection.vue';
  79. import CommonInfoRow from '@/components/ui/CommonInfoRow.vue';
  80. const systemApi = useSystemApi();
  81. const fundApi = useFundApi();
  82. const claimApi = useClaimApi();
  83. const toastRef = ref();
  84. const selectProjectRef = ref();
  85. const loading = ref(false);
  86. const paymentReceivedTypeOptions = ref<any[]>([]);
  87. const isContinue = ref(false);
  88. const detail = ref<any[]>([]);
  89. const form = reactive({
  90. id: 0,
  91. allotAmount: null,
  92. amount: 0,
  93. manageAmount: 0,
  94. taxAmount: 0,
  95. projectId: 0,
  96. projectName: '',
  97. projectLeaderName: '',
  98. deptName: '',
  99. projectType: '',
  100. startDate: '',
  101. endDate: '',
  102. createdName: '',
  103. createdTime: '',
  104. date: '',
  105. remark: '',
  106. serialNo: '',
  107. type: '',
  108. unit: '',
  109. status: '',
  110. externalAmount: 0,
  111. internalAmount: 0
  112. });
  113. const formatAmount = (cellValue: any) => {
  114. if (cellValue === null || cellValue === undefined || cellValue === '') return '0.00';
  115. const num = Number(cellValue);
  116. return isNaN(num) ? '0.00' : num.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  117. };
  118. const getDictLabel = (options: any[], value: string) => {
  119. const find = options.find((item) => item.dictValue === value);
  120. return find ? find.dictLabel : value || '-';
  121. };
  122. const getDict = async () => {
  123. try {
  124. const resTypes: any = await systemApi.getDictDataByType('PaymentReceivedType');
  125. if (resTypes.code == 200 && resTypes.data) paymentReceivedTypeOptions.value = resTypes.data.values || [];
  126. const parList: any = await fundApi.getAllFirstSubj();
  127. if(parList.code == 200 && parList.data) {
  128. detail.value = parList.data.map((item: any) => ({
  129. ...item,
  130. amount: ''
  131. }));
  132. }
  133. } catch (err) {
  134. console.error(err);
  135. }
  136. };
  137. const getFundDetail = async (id: number) => {
  138. try {
  139. const res: any = await fundApi.getDetails({ id });
  140. if (res.code == 200 && res.data) {
  141. Object.assign(form, res.data);
  142. form.id = res.data.id;
  143. form.amount = res.data.amount || 0;
  144. form.manageAmount = res.data.manageAmount || 0;
  145. form.taxAmount = res.data.taxAmount || 0;
  146. form.allotAmount = res.data.allotAmount || 0;
  147. if (res.data.projectName) {
  148. isContinue.value = true;
  149. }
  150. if (form.status == '20') {
  151. onRouterPush(`/pages/fund/claim/detail?id=${id}`);
  152. }
  153. }
  154. } catch (err) {
  155. console.error(err);
  156. }
  157. };
  158. const openProjectDialog = () => {
  159. if (isContinue.value) return;
  160. selectProjectRef.value?.openDialog();
  161. };
  162. const onProjectSelected = (item: any) => {
  163. form.projectId = Number(item.projectId);
  164. form.projectName = item.projectName;
  165. form.projectLeaderName = item.projectLeaderName;
  166. form.deptName = item.deptName;
  167. form.startDate = item.startDate;
  168. form.endDate = item.endDate;
  169. form.projectType = item.projectType;
  170. };
  171. const submitForm = async () => {
  172. if (!form.projectId) {
  173. toastRef.value?.show({ message: '请选择项目信息', type: 'error' });
  174. return;
  175. }
  176. const totalEntry = detail.value.reduce((total, item) => total + (Number(item.amount) || 0), 0);
  177. const allotAmount = Number(form.allotAmount) || 0;
  178. const tolerance = 0.01;
  179. if (totalEntry === 0) {
  180. toastRef.value?.show({ message: '本次认领金额不能为0', type: 'error' });
  181. return;
  182. }
  183. if (totalEntry - allotAmount > tolerance) {
  184. toastRef.value?.show({ message: '本次认领金额不得大于待认领金额', type: 'error' });
  185. return;
  186. }
  187. const params = JSON.parse(JSON.stringify(form));
  188. params.fundId = form.id;
  189. params.detail = detail.value.map((item: any) => ({
  190. ...item,
  191. amount: Number(item.amount || 0)
  192. }));
  193. params.amount = Number(params.amount || 0);
  194. params.externalAmount = Number(params.externalAmount || 0);
  195. params.internalAmount = Number(params.internalAmount || 0);
  196. uni.showModal({
  197. title: '提示',
  198. content: '确认提交认领?',
  199. success: async (resModal) => {
  200. if (resModal.confirm) {
  201. loading.value = true;
  202. try {
  203. const res: any = await claimApi.create(params);
  204. if (res.code == 200) {
  205. toastRef.value.show({ message: '认领操作成功', type: 'success' });
  206. setTimeout(() => {
  207. onRouterPush('/pages/fund/claim/index');
  208. }, 1000);
  209. } else {
  210. toastRef.value.show({ message: res.msg || '提交失败', type: 'error' });
  211. }
  212. } catch (err) {
  213. console.error(err);
  214. } finally {
  215. loading.value = false;
  216. }
  217. }
  218. }
  219. });
  220. };
  221. onLoad((options: any) => {
  222. const id = options.id ? Number(options.id) : 0;
  223. getDict().then(() => {
  224. if (id) {
  225. getFundDetail(id);
  226. }
  227. });
  228. });
  229. </script>
  230. <style lang="scss" scoped>
  231. .edit-container {
  232. height: calc(100vh - var(--window-top));
  233. display: flex;
  234. flex-direction: column;
  235. background-color: #f5f7fa;
  236. box-sizing: border-box;
  237. }
  238. .scroll-content {
  239. flex: 1;
  240. height: 100%;
  241. }
  242. .form-wrapper {
  243. padding: 40rpx 30rpx calc(140rpx + env(safe-area-inset-bottom));
  244. }
  245. .edit-form-list {
  246. :deep(.uv-form-item) {
  247. padding: 10rpx 0;
  248. border-bottom: 1px solid #f5f5f5;
  249. &:last-child {
  250. border-bottom: none;
  251. }
  252. }
  253. }
  254. .bottom-bar {
  255. position: fixed;
  256. bottom: 0;
  257. left: 0;
  258. right: 0;
  259. background-color: #fff;
  260. padding: 20rpx 30rpx;
  261. box-sizing: border-box;
  262. box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
  263. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  264. z-index: 99;
  265. }
  266. .highlight-number {
  267. flex: 1;
  268. text-align: right;
  269. font-size: 28rpx;
  270. color: #333;
  271. }
  272. .primary-color {
  273. color: #1c9bfd !important;
  274. font-weight: 500;
  275. }
  276. .number-font {
  277. font-family: 'Helvetica Neue', Arial, sans-serif;
  278. }
  279. </style>