综合办公系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

borrow.vue 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <!--
  2. * @Author: ysh
  3. * @Date: 2025-02-20 10:20:22
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2025-03-03 11:02:06
  6. -->
  7. <template>
  8. <view class="form-container">
  9. <!-- 表单标题 -->
  10. <view class="form-title">
  11. <text class="title-text">借款审批</text>
  12. <view class="title-line"></view>
  13. </view>
  14. <!-- 表单内容 -->
  15. <uni-forms ref="form" :modelValue="form" :rules="rules" label-position="top" label-width="150" class="custom-form">
  16. <!-- 当前节点 -->
  17. <uni-forms-item label="当前节点" class="form-item">
  18. <uni-tag :inverted="true" type="primary" :text="taskName"></uni-tag>
  19. </uni-forms-item>
  20. <!-- 流程发起人 -->
  21. <uni-forms-item label="填报人" class="form-item">
  22. <uni-tag :inverted="true" type="primary" :text="startUserName"></uni-tag>
  23. </uni-forms-item>
  24. <!-- 填报日期 -->
  25. <uni-forms-item label="填报日期" class="form-item">
  26. <text>{{ form.applyDate }}</text>
  27. </uni-forms-item>
  28. <!-- 借款类型 -->
  29. <uni-forms-item label="借款类型" required class="form-item" name="borrowUsage">
  30. <uni-data-checkbox v-model="form.borrowUsage" :localdata="borrowUsageOptions"></uni-data-checkbox>
  31. </uni-forms-item>
  32. <!-- 借款事由 -->
  33. <uni-forms-item label="借款事由" required class="form-item" name="applyReason" v-if="form.borrowUsage != 0">
  34. <uv-textarea v-model="form.applyReason" placeholder="请输入借款事由"></uv-textarea>
  35. </uni-forms-item>
  36. <!-- 选择项目 -->
  37. <uni-forms-item label="选择项目" required class="form-item" v-if="form.borrowUsage == 0" name="projectId">
  38. <u-button type="primary" @click="openProject = true" v-if="taskName == '借款申请'">+ 选择项目</u-button>
  39. <ProjectPicker :visible.sync="openProject" :selected.sync="selectedProject" @confirm="handleConfirm" />
  40. <ProjectInfo :project="projectObj"></ProjectInfo>
  41. </uni-forms-item>
  42. <!-- 借款明细 -->
  43. <uni-forms-item label="借款明细" required class="form-item">
  44. <BorrowDetail :borrowId="form.borrowId" :taskName="taskName" @getApplyAmount="setApplyAmount"></BorrowDetail>
  45. </uni-forms-item>
  46. <uni-forms-item label="申请金额" class="form-item">
  47. <view>{{ (this.form.applyAmount).toFixed(2) }}</view>
  48. <view style="color:#E74C3C" v-if="exceed && form.borrowUsage == '0'">
  49. 超过预算金额:{{ getMoreAmount('0') }}</view>
  50. </uni-forms-item>
  51. <uni-forms-item label="最大借款金额" class="form-item">
  52. {{ totalBudget.toFixed(2) }}
  53. </uni-forms-item>
  54. <uni-forms-item label="已申请借款" class="form-item">
  55. {{ hasBorrow.toFixed(2) }}
  56. </uni-forms-item>
  57. <uni-forms-item label="可用借款" class="form-item">
  58. {{ (totalBudget - hasBorrow).toFixed(2) }}
  59. </uni-forms-item>
  60. <view>
  61. <u-button type="primary" size="normal" @click="submit">提交申请</u-button>
  62. </view>
  63. </uni-forms>
  64. </view>
  65. </template>
  66. <script>
  67. import ProjectPicker from '@/pages/components/ProjectPicker.vue';
  68. import ProjectInfo from '@/pages/components/ProjectInfo.vue';
  69. import { parseTime } from "@/utils/common.js"
  70. import { listBorrow, getBorrow, delBorrow, addBorrow, updateBorrow } from "@/api/oa/borrow/borrow";
  71. import { listProject, getProject } from "@/api/oa/project/project";
  72. import { listBudget } from "@/api/oa/budget/budget";
  73. import BorrowDetail from './borrowDetail.vue';
  74. export default {
  75. components: {
  76. ProjectPicker,
  77. ProjectInfo,
  78. BorrowDetail
  79. },
  80. props: {
  81. taskForm: Object,
  82. taskName: String, // 当前节点
  83. startUserName: String, // 流程发起人
  84. },
  85. created() {
  86. this.initForm();
  87. uni.setNavigationBarTitle({
  88. title: '借款审批'
  89. });
  90. },
  91. data() {
  92. return {
  93. form: {
  94. submitTime: '',
  95. borrowUsage: '0',
  96. applyAmount: 0,
  97. },
  98. rules: {},
  99. borrowUsageOptions: [{
  100. text: '项目借款',
  101. value: '0',
  102. disable: false
  103. }, {
  104. text: '非项目借款',
  105. value: '1',
  106. disable: false
  107. }, {
  108. text: '工会借款',
  109. value: '2',
  110. disable: false
  111. }, {
  112. text: '党委借款',
  113. value: '3',
  114. disable: false
  115. }, {
  116. text: '团委借款',
  117. value: '4',
  118. disable: false
  119. }
  120. ],
  121. openProject: false,
  122. selectedProject: null, //选中的项目
  123. projectObj: {}, //项目信息的项目
  124. fromTotal: 0,
  125. totalBudget: 0, //预结算额
  126. exceed: false, //是否超预算
  127. hasBorrow: 0, //已申请借款
  128. }
  129. },
  130. methods: {
  131. async initForm() {
  132. getBorrow(this.taskForm.formId).then(async res => {
  133. if (res.data) {
  134. this.fromTotal = 1;
  135. this.form = res.data;
  136. console.log(this.form);
  137. if (this.form.projectId) {
  138. getProject(this.form.projectId).then(res => {
  139. if (res.data) {
  140. this.selectedProject = res.data;
  141. this.projectObj = res.data;
  142. }
  143. })
  144. let budgetData = await listBudget({ projectId: this.form.projectId })
  145. if (budgetData.total == 1) {
  146. let budget = budgetData.rows[0];
  147. this.totalBudget = budget.settleExpense
  148. } else if (budgetData.total == 0) {
  149. this.totalBudget = 0
  150. }
  151. if (this.form.borrowUsage == '0') {
  152. if ((this.totalBudget - this.form.applyAmount) < 0) {
  153. this.exceed = true;
  154. } else {
  155. this.exceed = false;
  156. }
  157. } else {
  158. this.exceed = false;
  159. }
  160. let borrow = await listBorrow({ projectId: this.form.projectId })
  161. if (borrow.total != 0) {
  162. let borrowList = borrow.rows;
  163. let hasBorrow = 0;
  164. borrowList = borrowList.filter(item => item.borrowId != this.taskForm.formId)
  165. borrowList.forEach(element => {
  166. if (element.managerAmount) {
  167. hasBorrow = hasBorrow + element.managerAmount
  168. }
  169. if (!element.managerAmount && element.applyAmount) {
  170. hasBorrow = hasBorrow + element.applyAmount
  171. }
  172. });
  173. this.hasBorrow = hasBorrow
  174. }
  175. }
  176. } else {
  177. this.fromTotal = 0;
  178. this.form.applier = this.$store.getters.userId;
  179. this.form.applyDate = parseTime(new Date(), "{y}-{m}-{d}");
  180. }
  181. })
  182. },
  183. // 计算超过预算的金额
  184. getMoreAmount(type) {
  185. let result;
  186. if (type == '0') {
  187. result = this.form.applyAmount - (this.totalBudget - this.hasBorrow);
  188. } else {
  189. result = this.form.managerAmount - (this.totalBudget - this.hasBorrow);
  190. }
  191. return result.toFixed(2)
  192. },
  193. setApplyAmount(val) {
  194. console.log(val);
  195. console.log(this.from);
  196. this.form.applyAmount = val
  197. },
  198. handleConfirm(project) {
  199. console.log('选中的项目:', project);
  200. this.selectedProject = project;
  201. this.projectObj = project;
  202. },
  203. submit() {
  204. this.$refs.form.validate().then(res => {
  205. console.log('表单数据信息:', res);
  206. }).catch(err => {
  207. console.log('表单错误信息:', err);
  208. })
  209. }
  210. },
  211. }
  212. </script>
  213. <style lang="scss" scoped></style>