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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <!--
  2. * @Author: ysh
  3. * @Date: 2025-02-20 10:20:22
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2025-05-29 10:15:51
  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. <flow-note :taskForm="taskForm"></flow-note>
  17. <!-- 当前节点 -->
  18. <uni-forms-item label="当前节点" class="form-item" v-if="taskName">
  19. <uni-tag :inverted="true" type="primary" :text="taskName"></uni-tag>
  20. </uni-forms-item>
  21. <!-- 流程发起人 -->
  22. <uni-forms-item label="填报人" class="form-item">
  23. <b style="font-size:30rpx;">{{ applierUserName }}</b>
  24. </uni-forms-item>
  25. <!-- 填报日期 -->
  26. <uni-forms-item label="填报日期" class="form-item">
  27. <text>{{ form.applyDate }}</text>
  28. </uni-forms-item>
  29. <!-- 借款类型 -->
  30. <uni-forms-item label="借款类型" required class="form-item" name="borrowUsage">
  31. <uni-data-checkbox v-model="form.borrowUsage" :localdata="borrowUsageOptions" :disabled="taskName != '借款申请'"
  32. @change="hanldeChangeType"></uni-data-checkbox>
  33. </uni-forms-item>
  34. <!-- 借款事由 -->
  35. <uni-forms-item label="借款事由" required class="form-item" name="applyReason" v-if="form.borrowUsage != 0">
  36. <uv-textarea v-model="form.applyReason" placeholder="请输入借款事由" :disabled="taskName != '借款申请'"></uv-textarea>
  37. </uni-forms-item>
  38. <!-- 选择项目 -->
  39. <uni-forms-item label="选择项目" required class="form-item" v-if="form.borrowUsage == 0" name="projectId">
  40. <u-button type="primary" @click="openProject = true" v-if="taskName == '借款申请'">+ 选择项目</u-button>
  41. <ProjectPicker :visible.sync="openProject" :selected.sync="selectedProject" @confirm="handleConfirm" />
  42. <ProjectInfo :project="projectObj"></ProjectInfo>
  43. </uni-forms-item>
  44. <!-- 借款明细 -->
  45. <uni-forms-item label="借款明细" required class="form-item">
  46. <BorrowDetail :borrowId="form.borrowId" :taskName="taskName" :borrowUsage="form.borrowUsage" @getApplyAmount="setApplyAmount"
  47. @getManagerAmount="setManagerAmount"></BorrowDetail>
  48. </uni-forms-item>
  49. <!-- 最大借款金额限制 -->
  50. <uni-forms-item label="最大借款金额" class="form-item" v-if="form.borrowUsage == '0'">
  51. <view class="amount-text">¥ {{ siteExpenses.toFixed(2) }}</view>
  52. </uni-forms-item>
  53. <uni-forms-item label="已申请借款" class="form-item" v-if="form.borrowUsage == '0'">
  54. <view class="amount-text">¥ {{ hasBorrow.toFixed(2) }}</view>
  55. </uni-forms-item>
  56. <uni-forms-item label="可用借款" class="form-item" v-if="form.borrowUsage == '0'">
  57. <view class="amount-text">¥ {{ (siteExpenses - hasBorrow).toFixed(2) }}</view>
  58. </uni-forms-item>
  59. <uni-forms-item label="申请金额" required class="form-item">
  60. <view class="amount-text">¥ {{ (this.form.applyAmount ? this.form.applyAmount : 0).toFixed(2) }}</view>
  61. <view class="warning-text" v-if="exceed && form.borrowUsage == '0'">
  62. 超过预算金额:¥ {{ getMoreAmount('0') }}
  63. </view>
  64. </uni-forms-item>
  65. <uni-forms-item label="校准金额" required class="form-item"
  66. v-if="taskName != '借款申请' && taskName != '部门审核' && taskName != '党工团审核'">
  67. <view class="amount-text">¥ {{ (this.form.managerAmount ? this.form.managerAmount : 0).toFixed(2) }}</view>
  68. <view class="warning-text" v-if="exceed && form.borrowUsage == '0'">
  69. 超过预算金额:¥ {{ getMoreAmount('1') }}
  70. </view>
  71. </uni-forms-item>
  72. <!-- 申请人说明 -->
  73. <uni-forms-item label="申请人说明" required class="form-item" name="remark">
  74. <uv-textarea v-model="form.remark" placeholder="请输入申请人说明" :disabled="taskName != '借款申请'"></uv-textarea>
  75. </uni-forms-item>
  76. <!-- 附件上传 -->
  77. <uni-forms-item label="附件上传" class="form-item" name="borrowDocument">
  78. <file-upload :fileType="'借款/申请附件'" :showBtn="taskName == '借款申请'" :fileName="form.borrowDocument"
  79. @deleteFile="form.borrowDocument = ''" @success="uploadSuccess"></file-upload>
  80. </uni-forms-item>
  81. <view v-if="form.borrowUsage == '0' || form.borrowUsage == '1'">
  82. <!-- 部门审核 -->
  83. <uni-forms-item label="部门负责人意见" required class="form-item" v-if="taskName != '借款申请'" name="deptComment">
  84. <uv-textarea v-model="form.deptComment" placeholder="请输入部门负责人意见" :disabled="taskName != '部门审核'"></uv-textarea>
  85. <auditor :name="form.deptUser ? form.deptUser.nickName : ''" :time="form.deptTime"></auditor>
  86. </uni-forms-item>
  87. <!-- 分管审核 -->
  88. <uni-forms-item label="分管领导审核意见" required class="form-item" v-if="taskName != '借款申请'" name="managerComment">
  89. <uv-textarea v-model="form.managerComment" placeholder="请输入分管领导审核意见"
  90. :disabled="taskName != '分管审核'"></uv-textarea>
  91. <auditor :name="form.managerUser ? form.managerUser.nickName : ''" :time="form.managerTime"></auditor>
  92. </uni-forms-item>
  93. <!-- 总经理审核 -->
  94. <uni-forms-item label="总经理审核意见" required class="form-item" v-if="taskName != '借款申请'" name="zjlComment">
  95. <uv-textarea v-model="form.zjlComment" placeholder="请输入总经理审核意见" :disabled="taskName != '总经理审核'"></uv-textarea>
  96. <auditor :name="form.zjlUser ? form.zjlUser.nickName : ''" :time="form.zjlTime"></auditor>
  97. </uni-forms-item>
  98. </view>
  99. <!-- 党工团审核 -->
  100. <view v-if="form.borrowUsage != '0' && form.borrowUsage != '1'">
  101. <uni-forms-item :label="dgtLabel" required class="form-item" v-if="taskName != '借款申请'" name="unionComment">
  102. <uv-textarea v-model="form.unionComment" placeholder="请输入审核意见" :disabled="taskName != '党工团审核'"></uv-textarea>
  103. <auditor :name="form.unionUser ? form.unionUser.nickName : ''" :time="form.unionTime"></auditor>
  104. </uni-forms-item>
  105. </view>
  106. <!-- 财务处理 -->
  107. <uni-forms-item label="财务部支付备注" class="form-item" v-if="taskName != '借款申请'" name="cwComment">
  108. <uv-textarea v-model="form.cwComment" placeholder="请输入财务部支付备注" :disabled="taskName != '财务处理'"></uv-textarea>
  109. </uni-forms-item>
  110. <uni-forms-item label="支付时间" required class="form-item" v-if="taskName != '借款申请'" name="lendTime">
  111. <uni-datetime-picker type="date" :clear-icon="false" v-model="form.lendTime" :disabled="taskName != '财务处理'" />
  112. <auditor :name="form.cwUser ? form.cwUser.nickName : ''" :time="form.lendTime"></auditor>
  113. </uni-forms-item>
  114. <!-- 操作栏 -->
  115. <view class="form-button" v-if="taskName">
  116. <u-button type="warning" size="normal" @click="saves" style="margin-right: 10px" v-if="taskName">保存</u-button>
  117. <u-button type="error" size="normal" style="margin-right: 10px" @click="$refs.returnPopup.open()"
  118. v-if="taskName != '借款申请'">退回</u-button>
  119. <u-button type="primary" size="normal" @click="submit">{{ taskName == '借款申请' ? '提交申请' : '提交审核' }}</u-button>
  120. </view>
  121. </uni-forms>
  122. <!-- 退回弹窗 -->
  123. <uni-popup ref="returnPopup" background-color="#fff">
  124. <return-popup @cancel="$refs.returnPopup.close()" :taskForm="taskForm" :comment="commentByRole()"
  125. @goBack="goHome"></return-popup>
  126. </uni-popup>
  127. </view>
  128. </template>
  129. <script>
  130. import { parseTime } from "@/utils/common.js"
  131. import { listBudget } from "@/api/oa/budget/budget";
  132. import ProjectInfo from '@/pages/components/ProjectInfo.vue';
  133. import { complete, getNextFlowNode } from "@/api/flowable/todo";
  134. import ProjectPicker from '@/pages/components/ProjectPicker.vue';
  135. import { listProject, getProject } from "@/api/oa/project/project";
  136. import { listSite, delSite } from "@/api/oa/budget/budgetSite.js";
  137. import { listBorrow, getBorrow, delBorrow, addBorrow, updateBorrow } from "@/api/oa/borrow/borrow";
  138. import { getUserByPost, getUsersDeptLeader, getUsersDeptLeaderByDept, getUsersViceDeptLeaderByDept, getUsersManageLeaderByDept } from '@/api/system/post.js'
  139. import { sendQyMessage } from "@/api/qywx/index"
  140. import { listUser, getUser } from "@/api/system/user";
  141. import BorrowDetail from './borrowDetail.vue';
  142. import FlowNote from '@/pages/components/flowNote.vue';
  143. import ReturnPopup from '@/pages/components/returnPopup.vue';
  144. import FileUpload from '@/pages/components/fileUpload.vue';
  145. import Auditor from "@/pages/components/auditor.vue";
  146. export default {
  147. components: {
  148. ProjectPicker,
  149. ProjectInfo,
  150. BorrowDetail,
  151. FlowNote,
  152. ReturnPopup,
  153. FileUpload,
  154. Auditor
  155. },
  156. props: {
  157. taskForm: Object,
  158. taskName: String, // 当前节点
  159. startUserName: String, // 流程发起人
  160. },
  161. created() {
  162. this.form.borrowId = this.taskForm.formId;
  163. this.deptId = this.$store.getters.deptId;
  164. this.applierUserName = this.startUserName;
  165. this.initForm();
  166. this.getUserList();
  167. this.initRules();
  168. uni.setNavigationBarTitle({
  169. title: '借款审批'
  170. });
  171. },
  172. watch: {
  173. form: {
  174. handler(newVal) {
  175. this.initRules();
  176. },
  177. deep: true // 启用深度监测
  178. }
  179. },
  180. data() {
  181. return {
  182. userList: [],
  183. applierUserName: '',
  184. form: {
  185. submitTime: '',
  186. borrowUsage: '0',
  187. applyAmount: 0,
  188. managerAmount: 0,
  189. remark: '',
  190. applyDate: ''
  191. },
  192. rules: {},
  193. borrowUsageOptions: [{
  194. text: '项目借款',
  195. value: '0',
  196. disable: false
  197. }, {
  198. text: '非项目借款',
  199. value: '1',
  200. disable: false
  201. }, {
  202. text: '工会借款',
  203. value: '2',
  204. disable: false
  205. }, {
  206. text: '党委借款',
  207. value: '3',
  208. disable: false
  209. }, {
  210. text: '团委借款',
  211. value: '4',
  212. disable: false
  213. }
  214. ],
  215. openProject: false,
  216. selectedProject: null, //选中的项目
  217. projectObj: {}, //项目信息的项目
  218. formTotal: 0,
  219. siteExpenses: 0, //预结算额
  220. exceed: false, //是否超预算
  221. need: true, //是否需要分管审批
  222. hasBorrow: 0, //已申请借款
  223. deptId: undefined,
  224. returnBack: false,
  225. dgtLabel: '工会审核意见',
  226. }
  227. },
  228. methods: {
  229. initRules() {
  230. this.rules = {
  231. // 借款类型验证(必填)
  232. borrowUsage: {
  233. rules: [{
  234. required: true,
  235. errorMessage: '请选择借款类型'
  236. }]
  237. },
  238. // 借款事由验证(当 borrowUsage != 0 时必填)
  239. applyReason: {
  240. rules: [{
  241. required: this.form.borrowUsage != '0', // 动态控制必填
  242. errorMessage: '请输入借款事由'
  243. }]
  244. },
  245. // 项目选择验证(当 borrowUsage == 0 时必填)
  246. projectId: {
  247. rules: [{
  248. required: this.form.borrowUsage == '0', // 动态控制必填
  249. errorMessage: '请选择项目'
  250. }]
  251. },
  252. // 申请人说明验证(必填)
  253. remark: {
  254. rules: [{
  255. required: true,
  256. errorMessage: '请输入申请人说明'
  257. }]
  258. },
  259. // 部门意见验证(仅在部门审核步骤必填)
  260. deptComment: {
  261. rules: [{
  262. required: this.taskName === '部门审核',
  263. errorMessage: '请输入部门意见'
  264. }]
  265. },
  266. // 分管意见验证(仅在分管审核步骤必填)
  267. managerComment: {
  268. rules: [{
  269. required: this.taskName === '分管审核',
  270. errorMessage: '请输入分管意见'
  271. }]
  272. },
  273. // 总经理意见验证(仅在总经理审核步骤必填)
  274. zjlComment: {
  275. rules: [{
  276. required: this.taskName === '总经理审核',
  277. errorMessage: '请输入总经理意见'
  278. }]
  279. },
  280. lendTime: {
  281. rules: [{
  282. required: this.taskName === '财务处理',
  283. errorMessage: '请选择支付时间'
  284. }]
  285. }
  286. }
  287. },
  288. async initForm() {
  289. getBorrow(this.taskForm.formId).then(async res => {
  290. if (res.data) {
  291. this.formTotal = 1;
  292. this.form = res.data;
  293. if (this.form.applyDept == 104) //董事长分管的综合事务部,跳过分管审批
  294. this.need = false;
  295. if (!this.applierUserName) {
  296. this.applierUserName = this.form.applierUser.nickName;
  297. }
  298. this.hanldeChangeType();
  299. if (this.form.projectId) {
  300. getProject(this.form.projectId).then(res => {
  301. if (res.data) {
  302. this.selectedProject = res.data;
  303. this.projectObj = res.data;
  304. }
  305. })
  306. await this.getMaxExpense();
  307. }
  308. } else {
  309. this.formTotal = 0;
  310. this.form.applier = this.$store.getters.userId;
  311. this.form.applyDate = parseTime(new Date(), "{y}-{m}-{d}");
  312. }
  313. })
  314. },
  315. // 获取用户列表
  316. getUserList() {
  317. listUser({
  318. pageNum: 1,
  319. pageSize: 9999
  320. }).then(res => {
  321. if (res.code == 200) {
  322. this.userList = res.rows
  323. }
  324. })
  325. },
  326. async getMaxExpense() {
  327. let budgetData = await listBudget({ projectId: this.form.projectId })
  328. if (budgetData.total == 1) {
  329. let budget = budgetData.rows[0];
  330. let siteRes = await listSite({ budgetId: budget.budgetId });
  331. let maxExpense = siteRes.rows.reduce((sum, site) => sum + (Number(site.amount) || 0), 0);
  332. this.siteExpenses = maxExpense
  333. } else {
  334. this.siteExpenses = 0
  335. }
  336. if (this.form.borrowUsage == '0') {
  337. if ((this.siteExpenses - this.form.applyAmount) < 0) {
  338. this.exceed = true;
  339. } else {
  340. this.exceed = false;
  341. }
  342. } else {
  343. this.exceed = false;
  344. }
  345. let borrow = await listBorrow({ projectId: this.form.projectId })
  346. if (borrow.total != 0) {
  347. let borrowList = borrow.rows;
  348. let hasBorrow = 0;
  349. borrowList = borrowList.filter(item => item.borrowId != this.taskForm.formId)
  350. borrowList.forEach(element => {
  351. if (element.managerAmount) {
  352. hasBorrow = hasBorrow + element.managerAmount
  353. }
  354. if (!element.managerAmount && element.applyAmount) {
  355. hasBorrow = hasBorrow + element.applyAmount
  356. }
  357. });
  358. this.hasBorrow = hasBorrow
  359. }
  360. this.getMoreAmount();
  361. },
  362. hanldeChangeType() {
  363. if (this.form.borrowUsage == '2') {
  364. this.dgtLabel = '工会审核意见'
  365. } else if (this.form.borrowUsage == '3') {
  366. this.dgtLabel = '党委审核意见'
  367. } else {
  368. this.dgtLabel = '团委审核意见'
  369. }
  370. },
  371. // 计算超过预算的金额
  372. getMoreAmount(type) {
  373. let result;
  374. if (type == '0') {
  375. result = this.form.applyAmount - (this.siteExpenses - this.hasBorrow);
  376. } else {
  377. result = this.form.managerAmount - (this.siteExpenses - this.hasBorrow);
  378. }
  379. return result.toFixed(2)
  380. },
  381. setApplyAmount(val) {
  382. this.form.applyAmount = val
  383. },
  384. setManagerAmount(val) {
  385. this.form.managerAmount = val
  386. },
  387. handleConfirm(project) {
  388. this.selectedProject = project;
  389. this.projectObj = project;
  390. this.form.projectId = project.projectId;
  391. this.getMaxExpense();
  392. },
  393. // 保存
  394. async saves() {
  395. if (this.formTotal == 0) {
  396. this.form.borrowId = this.taskForm.formId;
  397. await addBorrow(this.form)
  398. this.initForm();
  399. } else {
  400. // 更新借款审批表
  401. await updateBorrow(this.form);
  402. }
  403. this.$modal.msgSuccess('保存成功');
  404. },
  405. submit() {
  406. // 显示确认提交对话框
  407. uni.showModal({
  408. title: '提示',
  409. content: '确认提交吗?',
  410. success: (res) => {
  411. if (!res.confirm) {
  412. return;
  413. }
  414. // 继续执行后续代码
  415. this.handleSubmit();
  416. }
  417. });
  418. },
  419. // 处理提交逻辑
  420. handleSubmit() {
  421. this.$refs.form.validate().then(async res => {
  422. if (this.formTotal != 0) {
  423. // 定义审核节点配置
  424. const auditConfig = {
  425. '部门审核': {
  426. userIdField: 'deptUserId',
  427. timeField: 'deptTime'
  428. },
  429. '分管审核': {
  430. userIdField: 'managerUserId',
  431. timeField: 'managerTime'
  432. },
  433. '总经理审核': {
  434. userIdField: 'zjlUserId',
  435. timeField: 'zjlTime'
  436. },
  437. '董事长批准': {
  438. userIdField: 'dszUserId',
  439. timeField: 'dszTime'
  440. },
  441. '党工团审核': {
  442. userIdField: 'unionUserId',
  443. timeField: 'unionTime'
  444. },
  445. '财务处理': {
  446. userIdField: 'cwUserId',
  447. timeField: 'lendTime'
  448. }
  449. }
  450. // 根据当前节点更新审核信息
  451. const currentConfig = auditConfig[this.taskName]
  452. if (currentConfig) {
  453. const currentUserId = this.$store.getters.userId
  454. const currentTime = parseTime(new Date(), '{y}-{m}-{d}')
  455. // 设置审核人和审核时间
  456. this.form[currentConfig.userIdField] = currentUserId
  457. this.form[currentConfig.timeField] = currentTime
  458. }
  459. // 更新借款申请
  460. await updateBorrow(this.form);
  461. const params = { taskId: this.taskForm.taskId };
  462. getNextFlowNode(params).then(async res => {
  463. // 处理不同的流程节点
  464. if (this.taskName == '借款申请') {
  465. // 处理借款申请节点
  466. let userId = await this.borrowApprovalFun();
  467. let userIds = [];
  468. if (userId) {
  469. userIds.push(userId);
  470. }
  471. await this.sendQyMessage(userIds);
  472. } else if (this.taskName == '部门审核') {
  473. this.taskForm.variables.need = this.need;
  474. let userIds = [];
  475. if (this.need) {
  476. // 得到分管领导根据部门
  477. const res = await getUsersManageLeaderByDept({ deptId: this.form.applyDept });
  478. if (res.data) {
  479. res.data.forEach(item => {
  480. userIds.push(item.userId)
  481. })
  482. }
  483. this.taskForm.variables.approvalList = userIds;
  484. this.handleComplete(this.taskForm);
  485. }
  486. else {
  487. const res = await getUsersManageLeaderByDept({ deptId: this.form.applyDept });
  488. if (res.data) {
  489. res.data.forEach(item => {
  490. userIds.push(item.userId)
  491. })
  492. }
  493. this.taskForm.variables.approvalList = userIds;
  494. const response = await getUserByPost({ postName: '总经理' });
  495. this.taskForm.variables.approval = response.data[0].userId;
  496. userIds = [response.data[0].userId];
  497. this.handleComplete(this.taskForm);
  498. }
  499. await this.sendQyMessage(userIds);
  500. } else if (this.taskName == '分管审核') {
  501. // 得到总经理
  502. const res = await getUserByPost({ postName: '总经理' });
  503. this.taskForm.variables.approval = res.data[0].userId;
  504. this.handleComplete(this.taskForm);
  505. await this.sendQyMessage([res.data[0].userId]);
  506. } else if (this.taskName == '总经理审核') {
  507. this.exceed = false;
  508. this.taskForm.variables.exceed = this.exceed;
  509. let userIds = [];
  510. if (!this.exceed) {
  511. userIds = await this.submitFD(); // 提交给财务部门
  512. } else {
  513. const res = await getUserByPost({ postName: '董事长' });
  514. this.taskForm.variables.approval = res.data[0].userId;
  515. this.handleComplete(this.taskForm);
  516. userIds = [res.data[0].userId];
  517. }
  518. await this.sendQyMessage(userIds);
  519. } else if (this.taskName == '董事长批准' || this.taskName == '党工团审核') {
  520. let userIds = await this.submitFD(); // 提交给财务部门
  521. await this.sendQyMessage(userIds);
  522. } else if (this.taskName == '财务处理') {
  523. uni.showModal({
  524. title: '提示',
  525. content: '最后一个节点,提交将结束流程,是否提交?',
  526. success: (res) => {
  527. if (res.confirm) {
  528. this.handleComplete(this.taskForm);
  529. }
  530. }
  531. });
  532. }
  533. })
  534. }
  535. }).catch(err => {
  536. console.log('表单错误信息:', err);
  537. })
  538. },
  539. // 处理任务完成
  540. handleComplete(taskForm) {
  541. complete(taskForm).then(response => {
  542. this.$modal.msgSuccess(response.msg);
  543. this.goHome();
  544. })
  545. },
  546. // 借款申请提交方法
  547. async borrowApprovalFun() {
  548. let userId;
  549. if (this.form.borrowUsage == '2' || this.form.borrowUsage == '3' || this.form.borrowUsage == '4') {
  550. this.deptId = 0;
  551. }
  552. // 如果是党工团申请 deptId == 0 为党工团申请
  553. if (this.deptId === 0) {
  554. // 2为工会、3为党委
  555. if (this.form.borrowUsage == 2 || this.form.borrowUsage == 3) {
  556. const res = await getUserByPost({ postName: '党总支书记' });
  557. userId = res.data[0].userId;
  558. } else {
  559. const res = await getUserByPost({ postName: '团支部书记' });
  560. userId = res.data[0].userId;
  561. }
  562. this.taskForm.variables.dept = this.deptId;
  563. this.taskForm.variables.approval = userId;
  564. this.handleComplete(this.taskForm);
  565. }
  566. else if (this.deptId == 102) { //如果是经营管理层申请,走总经理审批
  567. this.form.managerAmount = this.form.applyAmount;
  568. await updateBorrow(this.form);
  569. const res = await getUserByPost({ postName: '总经理' });
  570. userId = res.data[0].userId;
  571. this.taskForm.variables.dept = this.deptId;
  572. this.taskForm.variables.approval = userId;
  573. this.handleComplete(this.taskForm);
  574. } else if (this.deptId == 101) { //如果是董事会申请,走董事长批准
  575. const res = await getUserByPost({ postName: '董事长' });
  576. userId = res.data[0].userId;
  577. this.taskForm.variables.dept = this.deptId;
  578. this.taskForm.variables.approval = userId;
  579. this.taskForm.variables.exceed = true;
  580. this.handleComplete(this.taskForm);
  581. } else { //普通员工申请项目借款
  582. const res = await getUsersDeptLeader({ userId: this.$store.getters.userId });
  583. userId = res.data.userId;
  584. this.taskForm.variables.approval = userId;
  585. this.taskForm.variables.dept = this.deptId;
  586. this.handleComplete(this.taskForm);
  587. }
  588. return userId;
  589. },
  590. // 提交给财务部审核
  591. async submitFD() {
  592. let approvalList = [];
  593. const res = await getUsersDeptLeaderByDept({ deptId: 106 });
  594. approvalList.push(res.data.userId);
  595. const res1 = await getUsersViceDeptLeaderByDept({ deptId: 106 });
  596. approvalList.push(res1.data.userId);
  597. this.taskForm.variables.approvalList = approvalList;
  598. this.handleComplete(this.taskForm);
  599. return approvalList;
  600. },
  601. commentByRole() {
  602. if (this.taskName == '部门审核') {
  603. return this.form.deptComment
  604. } else if (this.taskName == '分管审核') {
  605. return this.form.managerComment
  606. } else if (this.taskName == '总经理审核') {
  607. return this.form.zjlComment
  608. } else if (this.taskName == '董事长批准') {
  609. return this.form.dszComment
  610. } else if (this.taskName == '党工团审核') {
  611. return this.form.unionComment
  612. } else if (this.taskName == '财务处理') {
  613. return this.form.cwComment
  614. }
  615. },
  616. goHome() {
  617. uni.switchTab({
  618. url: '/pages/message/index'
  619. })
  620. },
  621. uploadSuccess(fileName) {
  622. this.form.borrowDocument = fileName
  623. updateBorrow(this.form)
  624. },
  625. // 发送企业微信消息
  626. async sendQyMessage(userIds) {
  627. if (userIds && userIds.length > 0) {
  628. let formData = new FormData();
  629. let message = "您有一条新的借款申请: \n>" +
  630. "申请人:<font color='info'>" + this.getUserName(this.form.applier) + "</font> \n>" +
  631. "借款金额:<font color='warning'>" + this.form.applyAmount + "</font> 元 \n>" +
  632. "借款说明:" + (this.form.applyReason ? this.form.applyReason : this.form.remark) + " \n>" +
  633. "\n>" +
  634. "已办流程:<font color='comment'>" + this.taskName + "</font> \n>";
  635. formData.append('message', message);
  636. let userString = [];
  637. for (let u of userIds) {
  638. let { data } = await getUser(u);
  639. if (data && data.pinyin) {
  640. userString.push(data.pinyin);
  641. }
  642. }
  643. formData.append('userString', userString.join('|') + '|YuSiHan|WangRongHua')
  644. await sendQyMessage(formData);
  645. }
  646. },
  647. // 获取用户名称
  648. getUserName(userId) {
  649. if (!userId || !this.userList) return '';
  650. let user = this.userList.find(u => u.userId == userId);
  651. return user ? user.nickName : '';
  652. },
  653. },
  654. }
  655. </script>
  656. <style lang="scss" scoped>
  657. .amount-text {
  658. font-size: 16px;
  659. font-weight: bold;
  660. color: #333;
  661. text-align: right;
  662. }
  663. .warning-text {
  664. font-size: 14px;
  665. color: #ff0000;
  666. margin-top: 5px;
  667. text-align: right;
  668. }
  669. .form-button {
  670. display: flex;
  671. }
  672. .example-body {
  673. padding: 10px;
  674. background-color: #fff;
  675. }
  676. </style>