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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <!--
  2. * @Author: ysh
  3. * @Date: 2025-02-27 10:43:04
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2025-03-03 10:41:01
  6. -->
  7. <template>
  8. <view class="container">
  9. <u-button type="primary" @click="showAddPopup = true">+ 新增借款项</u-button>
  10. <!-- 列表标题 -->
  11. <view class="list-header">
  12. <text class="header-item">开支项目</text>
  13. <text class="header-item amount">申请金额</text>
  14. </view>
  15. <!-- 数据列表 -->
  16. <view class="list-box" v-for="(item, index) in detailList" :key="item.borrowDetailId">
  17. <view class="indexs">
  18. <text>{{ index + 1 }}</text>
  19. </view>
  20. <view class="list-item">
  21. <view class="item-left">
  22. <text class="item-title">{{ item.borrowItem }}</text>
  23. <text class="item-sub">
  24. ¥{{ item.price }} × {{ item.quantity }}{{ item.unit }}
  25. </text>
  26. </view>
  27. <view class="item-right">
  28. <text class="total-amount">¥{{ item.applyAmount }}</text>
  29. </view>
  30. </view>
  31. <view class="box-button" v-if="taskName == '借款申请'">
  32. <u-button size="normal" icon="edit-pen">修改</u-button>
  33. <u-button size="normal" icon="trash" @click="deleteItem(item)">删除</u-button>
  34. </view>
  35. </view>
  36. <!-- 借款弹窗 -->
  37. <view v-if="showAddPopup" class="add-popup">
  38. <view class="popup-content">
  39. <text class="popup-title">新增借款项</text>
  40. <uni-forms ref="form" :modelValue="newItem" :rules="rules" label-position="top" label-width="150"
  41. class="custom-form">
  42. <uni-forms-item label="开支项目" name="borrowItem" required class="form-item">
  43. <uni-easyinput v-model="newItem.borrowItem" placeholder="请输入开支项目" />
  44. </uni-forms-item>
  45. <uni-forms-item label="单位" name="unit" required class="form-item">
  46. <uni-easyinput v-model="newItem.unit" placeholder="请输入单位" />
  47. </uni-forms-item>
  48. <uni-forms-item label="单价" name="price" required class="form-item">
  49. <uni-easyinput type="number" v-model="newItem.price" placeholder="请输入单价" />
  50. </uni-forms-item>
  51. <uni-forms-item label="数量" name="quantity" required class="form-item">
  52. <uni-easyinput type="number" v-model="newItem.quantity" placeholder="请输入数量" />
  53. </uni-forms-item>
  54. <uni-forms-item label="合计">
  55. <text>{{ getTotal() }}</text>
  56. </uni-forms-item>
  57. </uni-forms>
  58. <view class="popup-buttons">
  59. <u-button @click="cancelAdd">取消</u-button>
  60. <u-button type="primary" class="confirm" @click="confirmAdd">确认添加</u-button>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import { listBorrowDetail, addBorrowDetail, updateBorrowDetail, delBorrowDetail, delBorrowDetailByDetailId } from "@/api/oa/borrow/borrowDetail";
  68. import uButton from '../../../uni_modules/uview-ui/components/u-button/u-button.vue';
  69. export default {
  70. components: { uButton },
  71. props: {
  72. borrowId: String,
  73. taskName: String,
  74. },
  75. data() {
  76. return {
  77. detailList: [],
  78. showAddPopup: false,
  79. newItem: {
  80. borrowItem: '',
  81. unit: '',
  82. price: '',
  83. quantity: '',
  84. applyAmount: 0
  85. },
  86. rules: {
  87. borrowItem: {
  88. rules: [{
  89. required: true,
  90. errorMessage: '请填写开支项目',
  91. },]
  92. },
  93. unit: {
  94. rules: [{
  95. required: true,
  96. errorMessage: '请填写单位',
  97. },]
  98. },
  99. price: {
  100. rules: [{
  101. required: true,
  102. errorMessage: '请填写单价',
  103. },]
  104. },
  105. quantity: {
  106. rules: [{
  107. required: true,
  108. errorMessage: '请填写数量',
  109. },]
  110. },
  111. },
  112. errorMessage: '',
  113. }
  114. },
  115. created() {
  116. },
  117. watch: {
  118. borrowId() {
  119. this.initList();
  120. },
  121. detailList(newval) {
  122. let sum = newval.reduce((sum, item) => sum + Number(item.applyAmount), 0);
  123. this.$emit('getApplyAmount', sum)
  124. }
  125. },
  126. methods: {
  127. initList() {
  128. listBorrowDetail({ pageSize: 999, borrowId: this.borrowId }).then(res => {
  129. if (res.rows.length != 0) {
  130. this.detailList = res.rows
  131. console.log(res.rows);
  132. }
  133. });
  134. },
  135. // 确认添加
  136. confirmAdd() {
  137. this.$refs.form.validate().then(res => {
  138. console.log('表单数据信息:', res);
  139. res.borrowId = this.borrowId;
  140. res.applyAmount = this.getTotal();
  141. addBorrowDetail(res);
  142. this.clearForm()
  143. this.showAddPopup = false
  144. this.initList();
  145. }).catch(err => {
  146. console.log('表单错误信息:', err);
  147. })
  148. },
  149. // 清空表单
  150. clearForm() {
  151. this.newItem = {
  152. borrowItem: '',
  153. unit: '',
  154. price: '',
  155. quantity: '',
  156. applyAmount: 0
  157. }
  158. },
  159. // 取消添加
  160. cancelAdd() {
  161. this.clearForm()
  162. this.showAddPopup = false
  163. },
  164. getTotal() {
  165. return (Number(this.newItem.price) * Number(this.newItem.quantity)).toFixed(2)
  166. },
  167. deleteItem(item) {
  168. this.$modal.confirm('是否删除开支项目为' + item.borrowItem + '的项?').then(() => {
  169. delBorrowDetailByDetailId(item.borrowDetailId).then(res => {
  170. this.$modal.msgSuccess(res.msg);
  171. this.initList();
  172. })
  173. })
  174. }
  175. },
  176. }
  177. </script>
  178. <style lang="scss" scoped>
  179. .container {
  180. padding: 20rpx 30rpx;
  181. background-color: #f8f8f8;
  182. }
  183. /* 列表标题样式 */
  184. .list-header {
  185. display: flex;
  186. justify-content: space-between;
  187. padding: 20rpx 0;
  188. font-weight: bold;
  189. border-bottom: 1rpx solid #eee;
  190. }
  191. .list-box {
  192. margin-bottom: 20rpx;
  193. padding: 30rpx 10rpx;
  194. border-bottom: 1rpx solid #eee;
  195. background-color: #fff;
  196. border-radius: 12rpx;
  197. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  198. .indexs {
  199. font-size: 25rpx;
  200. height: 30rpx;
  201. position: relative;
  202. text {
  203. display: block;
  204. position: absolute;
  205. right: 10rpx;
  206. width: 32rpx;
  207. height: 32rpx;
  208. text-align: center;
  209. }
  210. }
  211. .box-button {
  212. display: flex;
  213. padding: 10rpx;
  214. }
  215. }
  216. /* 列表项样式 */
  217. .list-item {
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. }
  222. .item-left {
  223. flex: 1;
  224. }
  225. .item-title {
  226. display: block;
  227. font-size: 32rpx;
  228. font-weight: bold;
  229. color: #333;
  230. margin-bottom: 15rpx;
  231. }
  232. .item-sub {
  233. font-size: 26rpx;
  234. color: #999;
  235. }
  236. .total-amount {
  237. font-size: 30rpx;
  238. color: #f1a532;
  239. font-weight: bold;
  240. padding-right: 30rpx;
  241. }
  242. .delete {
  243. font-size: 30rpx;
  244. color: #ff6a6c;
  245. font-weight: bold;
  246. }
  247. .edit {
  248. font-size: 30rpx;
  249. color: #3c9cff;
  250. font-weight: bold;
  251. padding-right: 20rpx;
  252. }
  253. /* 金额列对齐 */
  254. .amount {
  255. min-width: 100rpx;
  256. padding-right: 20rpx;
  257. }
  258. .item-right {
  259. min-width: 200rpx;
  260. text-align: right;
  261. }
  262. .add-popup {
  263. position: fixed;
  264. top: 0;
  265. left: 0;
  266. right: 0;
  267. bottom: 0;
  268. background-color: rgba(0, 0, 0, 0.5);
  269. display: flex;
  270. justify-content: center;
  271. align-items: center;
  272. z-index: 999;
  273. }
  274. .popup-content {
  275. background-color: white;
  276. width: 600rpx;
  277. padding: 40rpx;
  278. border-radius: 20rpx;
  279. }
  280. .popup-title {
  281. font-size: 36rpx;
  282. font-weight: bold;
  283. display: block;
  284. margin-bottom: 40rpx;
  285. }
  286. .popup-buttons {
  287. display: flex;
  288. }
  289. </style>