综合办公系统
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 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <!--
  2. * @Author: ysh
  3. * @Date: 2025-02-20 10:20:22
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2025-03-03 17:23:02
  6. -->
  7. <!--
  8. * @Author: ysh
  9. * @Date: 2025-02-20 10:20:22
  10. * @LastEditors: Please set LastEditors
  11. * @LastEditTime: 2025-03-03 17:19:59
  12. -->
  13. <template>
  14. <view class="form-container">
  15. <!-- 表单标题 -->
  16. <view class="form-title">
  17. <text class="title-text">借款审批</text>
  18. <view class="title-line"></view>
  19. </view>
  20. <!-- 表单内容 -->
  21. <uni-forms ref="form" :modelValue="form" :rules="rules" label-position="top" label-width="150" class="custom-form">
  22. <!-- 当前节点 -->
  23. <uni-forms-item label="当前节点" class="form-item">
  24. <uni-tag :inverted="true" type="primary" :text="taskName"></uni-tag>
  25. </uni-forms-item>
  26. <!-- 流程发起人 -->
  27. <uni-forms-item label="填报人" class="form-item">
  28. <uni-tag :inverted="true" type="primary" :text="startUserName"></uni-tag>
  29. </uni-forms-item>
  30. <!-- 填报日期 -->
  31. <uni-forms-item label="填报日期" class="form-item">
  32. <text>{{ form.applyDate }}</text>
  33. </uni-forms-item>
  34. <!-- 借款类型 -->
  35. <uni-forms-item label="借款类型" required class="form-item" name="borrowUsage">
  36. <uni-data-checkbox v-model="form.borrowUsage" :localdata="borrowUsageOptions"
  37. :disabled="taskName != '借款申请'"></uni-data-checkbox>
  38. </uni-forms-item>
  39. <!-- 借款事由 -->
  40. <uni-forms-item label="借款事由" required class="form-item" name="applyReason" v-if="form.borrowUsage != 0">
  41. <uv-textarea v-model="form.applyReason" placeholder="请输入借款事由"></uv-textarea>
  42. </uni-forms-item>
  43. <!-- 选择项目 -->
  44. <uni-forms-item label="选择项目" required class="form-item" v-if="form.borrowUsage == 0" name="projectId">
  45. <u-button type="primary" @click="openProject = true" v-if="taskName == '借款申请'">+ 选择项目</u-button>
  46. <ProjectPicker :visible.sync="openProject" :selected.sync="selectedProject" @confirm="handleConfirm" />
  47. <ProjectInfo :project="projectObj"></ProjectInfo>
  48. </uni-forms-item>
  49. <!-- 借款明细 -->
  50. <uni-forms-item label="借款明细" required class="form-item">
  51. <BorrowDetail :borrowId="form.borrowId" :taskName="taskName" @getApplyAmount="setApplyAmount"></BorrowDetail>
  52. </uni-forms-item>
  53. <uni-forms-item label="申请金额" required class="form-item">
  54. <view class="amount-text">¥ {{ (this.form.applyAmount).toFixed(2) }}</view>
  55. <view class="warning-text" v-if="exceed && form.borrowUsage == '0'">
  56. 超过预算金额:¥ {{ getMoreAmount('0') }}
  57. </view>
  58. </uni-forms-item>
  59. <uni-forms-item label="最大借款金额" class="form-item">
  60. <view class="amount-text">¥ {{ totalBudget.toFixed(2) }}</view>
  61. </uni-forms-item>
  62. <uni-forms-item label="已申请借款" class="form-item">
  63. <view class="amount-text">¥ {{ hasBorrow.toFixed(2) }}</view>
  64. </uni-forms-item>
  65. <uni-forms-item label="可用借款" class="form-item">
  66. <view class="amount-text">¥ {{ (totalBudget - hasBorrow).toFixed(2) }}</view>
  67. </uni-forms-item>
  68. <uni-forms-item label="申请人说明" required class="form-item">
  69. <uv-textarea v-model="form.remark" placeholder="请输入申请人说明" :disabled="taskName != '借款申请'"></uv-textarea>
  70. </uni-forms-item>
  71. <uni-forms-item label="部门负责人意见" required class="form-item" v-if="taskName != '借款申请'">
  72. <uv-textarea v-model="form.deptComment" placeholder="请输入部门负责人意见"></uv-textarea>
  73. </uni-forms-item>
  74. <view class="form-button">
  75. <u-button type="warning" size="normal" @click="saves" style="margin-right: 10px"
  76. v-if="taskName == '借款申请'">保存</u-button>
  77. <u-button type="primary" size="normal" @click="submit">{{ taskName == '借款申请' ? '提交申请' : '提交审核' }}</u-button>
  78. </view>
  79. </uni-forms>
  80. </view>
  81. </template>
  82. <script>
  83. import ProjectPicker from '@/pages/components/ProjectPicker.vue';
  84. import ProjectInfo from '@/pages/components/ProjectInfo.vue';
  85. import { parseTime } from "@/utils/common.js"
  86. import { listBorrow, getBorrow, delBorrow, addBorrow, updateBorrow } from "@/api/oa/borrow/borrow";
  87. import { listProject, getProject } from "@/api/oa/project/project";
  88. import { listBudget } from "@/api/oa/budget/budget";
  89. import { getUserByPost, getUsersDeptLeader, getUsersDeptLeaderByDept, getUsersViceDeptLeaderByDept, getUsersManageLeaderByDept } from '@/api/system/post.js'
  90. import { complete, getNextFlowNode } from "@/api/flowable/todo";
  91. import config from '@/config'
  92. import BorrowDetail from './borrowDetail.vue';
  93. export default {
  94. components: {
  95. ProjectPicker,
  96. ProjectInfo,
  97. BorrowDetail
  98. },
  99. props: {
  100. taskForm: Object,
  101. taskName: String, // 当前节点
  102. startUserName: String, // 流程发起人
  103. },
  104. created() {
  105. this.form.borrowId = this.taskForm.formId;
  106. this.deptId = this.$store.getters.deptId;
  107. this.initForm();
  108. uni.setNavigationBarTitle({
  109. title: '借款审批'
  110. });
  111. },
  112. data() {
  113. return {
  114. form: {
  115. submitTime: '',
  116. borrowUsage: '0',
  117. applyAmount: 0,
  118. remark: '',
  119. },
  120. rules: {},
  121. borrowUsageOptions: [{
  122. text: '项目借款',
  123. value: '0',
  124. disable: false
  125. }, {
  126. text: '非项目借款',
  127. value: '1',
  128. disable: false
  129. }, {
  130. text: '工会借款',
  131. value: '2',
  132. disable: false
  133. }, {
  134. text: '党委借款',
  135. value: '3',
  136. disable: false
  137. }, {
  138. text: '团委借款',
  139. value: '4',
  140. disable: false
  141. }
  142. ],
  143. openProject: false,
  144. selectedProject: null, //选中的项目
  145. projectObj: {}, //项目信息的项目
  146. formTotal: 0,
  147. totalBudget: 0, //预结算额
  148. exceed: false, //是否超预算
  149. hasBorrow: 0, //已申请借款
  150. deptId: undefined,
  151. }
  152. },
  153. methods: {
  154. async initForm() {
  155. getBorrow(this.taskForm.formId).then(async res => {
  156. if (res.data) {
  157. this.formTotal = 1;
  158. this.form = res.data;
  159. console.log(this.form);
  160. if (this.form.projectId) {
  161. getProject(this.form.projectId).then(res => {
  162. if (res.data) {
  163. this.selectedProject = res.data;
  164. this.projectObj = res.data;
  165. }
  166. })
  167. let budgetData = await listBudget({ projectId: this.form.projectId })
  168. if (budgetData.total == 1) {
  169. let budget = budgetData.rows[0];
  170. this.totalBudget = budget.settleExpense
  171. } else if (budgetData.total == 0) {
  172. this.totalBudget = 0
  173. }
  174. if (this.form.borrowUsage == '0') {
  175. if ((this.totalBudget - this.form.applyAmount) < 0) {
  176. this.exceed = true;
  177. } else {
  178. this.exceed = false;
  179. }
  180. } else {
  181. this.exceed = false;
  182. }
  183. let borrow = await listBorrow({ projectId: this.form.projectId })
  184. if (borrow.total != 0) {
  185. let borrowList = borrow.rows;
  186. let hasBorrow = 0;
  187. borrowList = borrowList.filter(item => item.borrowId != this.taskForm.formId)
  188. borrowList.forEach(element => {
  189. if (element.managerAmount) {
  190. hasBorrow = hasBorrow + element.managerAmount
  191. }
  192. if (!element.managerAmount && element.applyAmount) {
  193. hasBorrow = hasBorrow + element.applyAmount
  194. }
  195. });
  196. this.hasBorrow = hasBorrow
  197. }
  198. }
  199. } else {
  200. this.formTotal = 0;
  201. this.form.applier = this.$store.getters.userId;
  202. this.form.applyDate = parseTime(new Date(), "{y}-{m}-{d}");
  203. }
  204. })
  205. },
  206. // 计算超过预算的金额
  207. getMoreAmount(type) {
  208. let result;
  209. if (type == '0') {
  210. result = this.form.applyAmount - (this.totalBudget - this.hasBorrow);
  211. } else {
  212. result = this.form.managerAmount - (this.totalBudget - this.hasBorrow);
  213. }
  214. return result.toFixed(2)
  215. },
  216. setApplyAmount(val) {
  217. this.form.applyAmount = val
  218. },
  219. handleConfirm(project) {
  220. console.log('选中的项目:', project);
  221. this.selectedProject = project;
  222. this.projectObj = project;
  223. this.form.projectId = project.projectId;
  224. },
  225. // 保存
  226. async saves() {
  227. if (this.formTotal == 0) {
  228. this.form.borrowId = this.taskForm.formId;
  229. await addBorrow(this.form)
  230. this.initForm();
  231. } else {
  232. // 更新借款审批表
  233. await updateBorrow(this.form);
  234. }
  235. this.$modal.msgSuccess('保存成功');
  236. },
  237. submit() {
  238. // 显示确认提交对话框
  239. uni.showModal({
  240. title: '提示',
  241. content: '确认提交吗?',
  242. success: (res) => {
  243. if (!res.confirm) {
  244. return;
  245. }
  246. // 继续执行后续代码
  247. this.handleSubmit();
  248. }
  249. });
  250. },
  251. // 处理提交逻辑
  252. handleSubmit() {
  253. this.$refs.form.validate().then(async res => {
  254. if (this.form.borrowUsage == '0' && !this.form.projectId) {
  255. this.$modal.msgError('请选择项目!')
  256. return
  257. }
  258. if (this.formTotal != 0) {
  259. // 定义审核节点配置
  260. const auditConfig = {
  261. '部门审核': {
  262. userIdField: 'deptUserId',
  263. timeField: 'deptTime'
  264. },
  265. '分管审核': {
  266. userIdField: 'managerUserId',
  267. timeField: 'managerTime'
  268. },
  269. '总经理审核': {
  270. userIdField: 'zjlUserId',
  271. timeField: 'zjlTime'
  272. },
  273. '董事长批准': {
  274. userIdField: 'dszUserId',
  275. timeField: 'dszTime'
  276. },
  277. '党工团审核': {
  278. userIdField: 'unionUserId',
  279. timeField: 'unionTime'
  280. },
  281. '财务处理': {
  282. userIdField: 'cwUserId',
  283. timeField: 'lendTime'
  284. }
  285. }
  286. // 根据当前节点更新审核信息
  287. const currentConfig = auditConfig[this.taskName]
  288. if (currentConfig) {
  289. const currentUserId = this.$store.getters.userId
  290. const currentTime = parseTime(new Date(), '{y}-{m}-{d}')
  291. // 设置审核人和审核时间
  292. this.form[currentConfig.userIdField] = currentUserId
  293. this.form[currentConfig.timeField] = currentTime
  294. }
  295. // 更新借款申请
  296. await updateBorrow(this.form);
  297. const params = { taskId: this.taskForm.taskId };
  298. console.log('params', params);
  299. getNextFlowNode(params).then(async res => {
  300. // 处理不同的流程节点
  301. if (this.taskName == '借款申请') {
  302. // 处理借款申请节点
  303. await this.borrowApprovalFun();
  304. } else if (this.taskName == '部门审核') {
  305. // 得到分管领导根据部门
  306. const res = await getUsersManageLeaderByDept({ deptId: this.form.applyDept });
  307. let userIds = [];
  308. if (res.data) {
  309. res.data.forEach(item => {
  310. userIds.push(item.userId)
  311. })
  312. }
  313. this.taskForm.variables.approvalList = userIds;
  314. this.handleComplete(this.taskForm);
  315. } else if (this.taskName == '分管审核') {
  316. // 得到总经理
  317. const res = await getUserByPost({ postName: '总经理' });
  318. this.taskForm.variables.approval = res.data[0].userId;
  319. this.handleComplete(this.taskForm);
  320. } else if (this.taskName == '总经理审核') {
  321. this.exceed = false;
  322. this.taskForm.variables.exceed = this.exceed;
  323. if (!this.exceed) {
  324. this.submitFD(); // 提交给财务部门
  325. } else {
  326. const res = await getUserByPost({ postName: '董事长' });
  327. this.taskForm.variables.approval = res.data[0].userId;
  328. this.handleComplete(this.taskForm);
  329. }
  330. } else if (this.taskName == '董事长批准' || this.taskName == '党工团审核') {
  331. this.submitFD(); // 提交给财务部门
  332. } else if (this.taskName == '财务处理') {
  333. uni.showModal({
  334. title: '提示',
  335. content: '最后一个节点,提交将结束流程,是否提交?',
  336. success: (res) => {
  337. if (res.confirm) {
  338. this.handleComplete(this.taskForm);
  339. }
  340. }
  341. });
  342. }
  343. })
  344. }
  345. }).catch(err => {
  346. console.log('表单错误信息:', err);
  347. })
  348. },
  349. // 处理任务完成
  350. handleComplete(taskForm) {
  351. complete(taskForm).then(response => {
  352. this.$modal.msgSuccess(response.msg);
  353. this.$emit('goBack');
  354. })
  355. },
  356. // 借款申请提交方法
  357. async borrowApprovalFun() {
  358. let userId;
  359. // 如果是党工团申请 deptId == 0 为党工团申请
  360. if (this.deptId === 0) {
  361. // 2为工会、3为党委
  362. if (this.form.borrowUsage == 2 || this.form.borrowUsage == 3) {
  363. userId = this.publicData.partySecretary;
  364. } else {
  365. userId = this.publicData.leagueSecretary;
  366. }
  367. this.taskForm.variables.dept = this.deptId;
  368. this.taskForm.variables.approval = userId;
  369. this.handleComplete(this.taskForm);
  370. } else if (this.deptId == 102) { //如果是经营管理层申请,走总经理审批
  371. this.form.managerAmount = this.form.applyAmount;
  372. await updateBorrow(this.form);
  373. const res = await getUserByPost({ postName: '总经理' });
  374. this.taskForm.variables.dept = this.deptId;
  375. this.taskForm.variables.approval = res.data[0].userId;
  376. this.handleComplete(this.taskForm);
  377. } else if (this.deptId == 101) { //如果是董事会申请,走董事长批准
  378. const res = await getUserByPost({ postName: '董事长' });
  379. this.taskForm.variables.dept = this.deptId;
  380. this.taskForm.variables.approval = res.data[0].userId;
  381. this.handleComplete(this.taskForm);
  382. } else { //普通员工申请项目借款
  383. const res = await getUsersDeptLeader({ userId: this.$store.getters.userId });
  384. let userId = res.data.userId;
  385. this.taskForm.variables.approval = userId;
  386. this.taskForm.variables.dept = this.deptId;
  387. this.handleComplete(this.taskForm);
  388. }
  389. },
  390. // 提交给财务部审核
  391. async submitFD() {
  392. let approvalList = [];
  393. const res = await getUsersDeptLeaderByDept({ deptId: 106 });
  394. approvalList.push(res.data.userId);
  395. const res1 = await getUsersViceDeptLeaderByDept({ deptId: 106 });
  396. approvalList.push(res1.data.userId);
  397. this.taskForm.variables.approvalList = approvalList;
  398. this.handleComplete(this.taskForm);
  399. },
  400. },
  401. }
  402. </script>
  403. <style lang="scss" scoped>
  404. .amount-text {
  405. font-size: 16px;
  406. font-weight: bold;
  407. color: #333;
  408. }
  409. .warning-text {
  410. font-size: 14px;
  411. color: #ff0000;
  412. margin-top: 5px;
  413. }
  414. .form-button {
  415. display: flex;
  416. }
  417. .example-body {
  418. padding: 10px;
  419. background-color: #fff;
  420. }
  421. </style>