edit.vue 9.7 KB

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