edit.vue 10 KB

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