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

borrowDetail.vue 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <!--
  2. * @Author: ysh
  3. * @Date: 2025-02-27 10:43:04
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2025-06-25 09:53:56
  6. -->
  7. <template>
  8. <view class="container">
  9. <!-- 列表标题 -->
  10. <view class="list-header">
  11. <text class="header-item">开支项目</text>
  12. <text class="header-item amount">申请金额</text>
  13. </view>
  14. <!-- 数据列表 -->
  15. <view class="list-box" v-for="(item, index) in detailList" :key="item.borrowDetailId">
  16. <view class="indexs">
  17. <text>{{ index + 1 }}</text>
  18. </view>
  19. <view class="list-item">
  20. <view class="item-left">
  21. <text class="item-title">{{ item.borrowItem }}</text>
  22. <text class="item-sub">
  23. ¥{{ item.price }} × {{ item.quantity }}{{ item.unit }}
  24. </text>
  25. </view>
  26. <view class="item-right">
  27. <text class="total-amount">¥{{ item.applyAmount }}</text>
  28. </view>
  29. </view>
  30. <uv-divider :dashed="true" v-if="taskName != '借款申请' && taskName != '部门审核' && taskName != '党工团审核'"></uv-divider>
  31. <view class="list-item" v-if="taskName != '借款申请' && taskName != '部门审核' && taskName != '党工团审核'">
  32. <view class="item-left">
  33. <text style="color:#398ade;padding-left: 10rpx;">分管审核金额</text>
  34. </view>
  35. <view class="item-right">
  36. <uni-easyinput type="number" v-model="item.managerAmount" placeholder="请输入审核金额" v-if="taskName == '分管审核'"
  37. @blur="editManagerAmount(detailList)" />
  38. <text class="mg-amount" v-else>¥{{ item.managerAmount }}</text>
  39. </view>
  40. </view>
  41. <view class="box-button" v-if="taskName == '借款申请'">
  42. <u-button size="normal" icon="edit-pen" @click="editItem(item)">修改</u-button>
  43. <u-button size="normal" icon="trash" @click="deleteItem(item)">删除</u-button>
  44. </view>
  45. </view>
  46. <u-button type="primary" @click="showAddPopup = true" v-if="taskName == '借款申请'">+ 新增借款项</u-button>
  47. <!-- 借款弹窗 -->
  48. <view v-if="showAddPopup" class="add-popup">
  49. <view class="popup-content">
  50. <text class="popup-title">新增借款项</text>
  51. <uni-forms ref="form" :modelValue="newItem" :rules="rules" label-position="top" label-width="150">
  52. <uni-forms-item label="开支项目" name="borrowItem" required class="form-item">
  53. <uni-data-select v-model="newItem.borrowItem" :localdata="dictsList" placeholder="请选择开支项目"
  54. @change="handleExpenseChange" v-if="borrowUsage == '0'" />
  55. <uni-easyinput v-model="newItem.borrowItem" placeholder="请输入开支项目" v-else />
  56. </uni-forms-item>
  57. <uni-forms-item label="单位" name="unit" required class="form-item">
  58. <uni-easyinput v-model="newItem.unit" placeholder="请输入单位" />
  59. </uni-forms-item>
  60. <uni-forms-item label="单价" name="price" required class="form-item">
  61. <uni-easyinput type="number" v-model="newItem.price" placeholder="请输入单价" />
  62. </uni-forms-item>
  63. <uni-forms-item label="数量" name="quantity" required class="form-item">
  64. <uni-easyinput type="number" v-model="newItem.quantity" placeholder="请输入数量" />
  65. </uni-forms-item>
  66. <uni-forms-item label="合计">
  67. <text>{{ getTotal() }}</text>
  68. </uni-forms-item>
  69. <view class="popup-buttons">
  70. <u-button style="margin-right: 10px;" @click="cancelAdd">取消</u-button>
  71. <u-button type="primary" class="confirm" @click="confirmAdd" v-if="!isModify">确认添加</u-button>
  72. <u-button type="primary" class="confirm" @click="confirmAdd" v-else>确认修改</u-button>
  73. </view>
  74. </uni-forms>
  75. </view>
  76. </view>
  77. <!-- 新增开支项字典弹窗 -->
  78. <view class="new-expense-popup" v-if="openNewExpense">
  79. <view class="popup-content">
  80. <text class="popup-title">新增开支项</text>
  81. <uni-easyinput v-model="newExpenseName" placeholder="请输入开支名称" />
  82. <view class="popup-buttons">
  83. <u-button style="margin-right: 10px;" @click="openNewExpense = false">取消</u-button>
  84. <u-button type="primary" class="confirm" @click="addNewExpense">确认添加</u-button>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. import { listBorrowDetail, addBorrowDetail, updateBorrowDetail, delBorrowDetail, delBorrowDetailByDetailId } from "@/api/oa/borrow/borrowDetail";
  92. import uButton from '../../../uni_modules/uview-ui/components/u-button/u-button.vue';
  93. import { addData, getDicts } from "@/api/system/dict/data";
  94. export default {
  95. components: { uButton },
  96. props: {
  97. borrowId: String,
  98. taskName: String,
  99. borrowUsage: String,
  100. },
  101. data() {
  102. return {
  103. detailList: [],
  104. showAddPopup: false,
  105. newItem: {
  106. borrowItem: '',
  107. unit: '',
  108. price: '',
  109. quantity: '',
  110. applyAmount: 0
  111. },
  112. rules: {
  113. borrowItem: {
  114. rules: [{
  115. required: true,
  116. errorMessage: '请填写开支项目',
  117. },]
  118. },
  119. unit: {
  120. rules: [{
  121. required: true,
  122. errorMessage: '请填写单位',
  123. },]
  124. },
  125. price: {
  126. rules: [{
  127. required: true,
  128. errorMessage: '请填写单价',
  129. },]
  130. },
  131. quantity: {
  132. rules: [{
  133. required: true,
  134. errorMessage: '请填写数量',
  135. },]
  136. },
  137. },
  138. errorMessage: '',
  139. isModify: false,
  140. dictsList: [], //开支项字典
  141. openNewExpense: false, //新增开支项字典弹窗
  142. newExpenseName: '', //新增开支项名称
  143. }
  144. },
  145. created() {
  146. this.initList();
  147. this.initDict();
  148. },
  149. watch: {
  150. borrowId() {
  151. this.initList();
  152. },
  153. detailList(newval) {
  154. this.getAomunt(newval)
  155. }
  156. },
  157. methods: {
  158. initList() {
  159. listBorrowDetail({ pageSize: 999, borrowId: this.borrowId }).then(res => {
  160. if (res.rows.length != 0) {
  161. this.detailList = res.rows
  162. if (!this.detailList[0].managerAmount) {
  163. this.detailList.forEach(item => {
  164. item.managerAmount = item.applyAmount;
  165. });
  166. this.editManagerAmount(this.detailList);
  167. }
  168. }
  169. });
  170. },
  171. initDict() {
  172. getDicts('cmc_borrow_expense').then(res => {
  173. this.dictsList = res.data.map(item => ({
  174. value: item.dictValue,
  175. text: item.dictLabel
  176. }))
  177. // this.dictsList.push({
  178. // value: 'newExpense',
  179. // text: '+新增更多开支项...'
  180. // })
  181. })
  182. },
  183. handleExpenseChange(value) {
  184. if (value == 'newExpense') {
  185. this.openNewExpense = true;
  186. }
  187. },
  188. addNewExpense() {
  189. if (this.newExpenseName == '') {
  190. this.$modal.msgError('请输入开支名称');
  191. return;
  192. }
  193. let length = this.dictsList.length;
  194. let newExpenseForm = {
  195. dictType: 'cmc_borrow_expense',
  196. dictLabel: this.newExpenseName,
  197. dictValue: this.newExpenseName,
  198. listClass: 'default',
  199. dictSort: length
  200. }
  201. addData(newExpenseForm).then(res => {
  202. this.$modal.msgSuccess('新增成功');
  203. this.openNewExpense = false;
  204. this.newItem.borrowItem = this.newExpenseName;
  205. this.newExpenseName = '';
  206. this.initDict();
  207. })
  208. },
  209. // 确认添加
  210. confirmAdd() {
  211. const borrowId = this.borrowId
  212. this.$refs.form.validate().then(async res => {
  213. this.newItem.applyAmount = this.getTotal();
  214. this.newItem.managerAmount = this.getTotal();
  215. if (this.isModify) {
  216. await updateBorrowDetail(this.newItem);
  217. } else {
  218. this.newItem.borrowId = borrowId;
  219. await addBorrowDetail(this.newItem);
  220. }
  221. this.clearForm()
  222. this.showAddPopup = false
  223. this.initList();
  224. this.$modal.msgSuccess('操作成功');
  225. }).catch(err => {
  226. console.log('表单错误信息:', err);
  227. })
  228. },
  229. // 清空表单
  230. clearForm() {
  231. this.newItem = {
  232. borrowItem: '',
  233. unit: '',
  234. price: '',
  235. quantity: '',
  236. applyAmount: 0
  237. }
  238. },
  239. // 取消添加
  240. cancelAdd() {
  241. this.clearForm()
  242. this.showAddPopup = false
  243. },
  244. getTotal() {
  245. return (Number(this.newItem.price) * Number(this.newItem.quantity)).toFixed(2)
  246. },
  247. deleteItem(item) {
  248. this.$modal.confirm('是否删除开支项目为' + item.borrowItem + '的项?').then(() => {
  249. delBorrowDetailByDetailId(item.borrowDetailId).then(res => {
  250. this.$modal.msgSuccess(res.msg);
  251. this.initList();
  252. })
  253. })
  254. },
  255. editItem(item) {
  256. this.newItem = item;
  257. this.isModify = true;
  258. this.showAddPopup = true;
  259. },
  260. getAomunt(list) {
  261. let sum = list.reduce((sum, item) => sum + Number(item.applyAmount), 0);
  262. let managerSum = list.reduce((sum, item) => sum + Number(item.managerAmount), 0);
  263. this.$emit('getApplyAmount', sum);
  264. this.$emit('getManagerAmount', managerSum);
  265. },
  266. async editManagerAmount(list) {
  267. this.getAomunt(list);
  268. for (let item of list) {
  269. await updateBorrowDetail(item);
  270. }
  271. }
  272. },
  273. }
  274. </script>
  275. <style lang="scss" scoped>
  276. .container {
  277. padding: 20rpx 30rpx;
  278. background-color: #f8f8f8;
  279. }
  280. /* 列表标题样式 */
  281. .list-header {
  282. display: flex;
  283. justify-content: space-between;
  284. padding: 20rpx 0;
  285. font-weight: bold;
  286. border-bottom: 1rpx solid #eee;
  287. }
  288. .list-box {
  289. margin-bottom: 20rpx;
  290. padding: 30rpx 10rpx;
  291. border-bottom: 1rpx solid #eee;
  292. background-color: #fff;
  293. border-radius: 12rpx;
  294. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  295. .indexs {
  296. font-size: 25rpx;
  297. height: 30rpx;
  298. position: relative;
  299. text {
  300. display: block;
  301. position: absolute;
  302. right: 10rpx;
  303. width: 32rpx;
  304. height: 32rpx;
  305. text-align: center;
  306. }
  307. }
  308. .box-button {
  309. display: flex;
  310. padding: 10rpx;
  311. }
  312. }
  313. /* 列表项样式 */
  314. .list-item {
  315. display: flex;
  316. justify-content: space-between;
  317. align-items: center;
  318. }
  319. .item-left {
  320. flex: 1;
  321. }
  322. .item-title {
  323. display: block;
  324. font-size: 32rpx;
  325. font-weight: bold;
  326. color: #333;
  327. margin-bottom: 15rpx;
  328. padding-left: 10rpx;
  329. }
  330. .item-sub {
  331. font-size: 26rpx;
  332. color: #999;
  333. padding-left: 10rpx;
  334. }
  335. .total-amount {
  336. font-size: 30rpx;
  337. color: #f1a532;
  338. font-weight: bold;
  339. padding-right: 30rpx;
  340. }
  341. .mg-amount {
  342. font-size: 30rpx;
  343. color: #398ade;
  344. font-weight: bold;
  345. padding-right: 30rpx;
  346. }
  347. .delete {
  348. font-size: 30rpx;
  349. color: #ff6a6c;
  350. font-weight: bold;
  351. }
  352. .edit {
  353. font-size: 30rpx;
  354. color: #3c9cff;
  355. font-weight: bold;
  356. padding-right: 20rpx;
  357. }
  358. /* 金额列对齐 */
  359. .amount {
  360. min-width: 100rpx;
  361. padding-right: 20rpx;
  362. }
  363. .item-right {
  364. flex: 1;
  365. min-width: 200rpx;
  366. text-align: right;
  367. }
  368. .add-popup {
  369. position: fixed;
  370. top: 0;
  371. left: 0;
  372. right: 0;
  373. bottom: 0;
  374. background-color: rgba(0, 0, 0, 0.5);
  375. display: flex;
  376. justify-content: center;
  377. align-items: center;
  378. z-index: 999;
  379. }
  380. .popup-content {
  381. background-color: white;
  382. width: 600rpx;
  383. padding: 40rpx;
  384. border-radius: 20rpx;
  385. }
  386. .popup-title {
  387. font-size: 36rpx;
  388. font-weight: bold;
  389. display: block;
  390. margin-bottom: 40rpx;
  391. }
  392. .popup-buttons {
  393. display: flex;
  394. }
  395. .new-expense-popup {
  396. position: fixed;
  397. top: 0;
  398. left: 0;
  399. right: 0;
  400. bottom: 0;
  401. background-color: rgba(0, 0, 0, 0.5);
  402. display: flex;
  403. justify-content: center;
  404. align-items: center;
  405. z-index: 1000;
  406. }
  407. </style>