综合办公系统
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

borrowDetail.vue 12KB

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