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

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