FinancePaymentItemForm.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <el-form
  3. ref="formRef"
  4. :model="formData"
  5. :rules="formRules"
  6. v-loading="formLoading"
  7. label-width="0px"
  8. :inline-message="true"
  9. :disabled="disabled"
  10. >
  11. <el-table :data="formData" show-summary :summary-method="getSummaries" class="-mt-10px">
  12. <el-table-column label="序号" type="index" align="center" width="60" />
  13. <el-table-column label="采购单据编号" min-width="200">
  14. <template #default="{ row }">
  15. <el-form-item class="mb-0px!">
  16. <el-input disabled v-model="row.bizNo" />
  17. </el-form-item>
  18. </template>
  19. </el-table-column>
  20. <el-table-column label="应付金额" prop="totalPrice" fixed="right" min-width="100">
  21. <template #default="{ row }">
  22. <el-form-item class="mb-0px!">
  23. <el-input disabled v-model="row.totalPrice" :formatter="erpPriceInputFormatter" />
  24. </el-form-item>
  25. </template>
  26. </el-table-column>
  27. <el-table-column label="已付金额" prop="paidPrice" fixed="right" min-width="100">
  28. <template #default="{ row }">
  29. <el-form-item class="mb-0px!">
  30. <el-input disabled v-model="row.paidPrice" :formatter="erpPriceInputFormatter" />
  31. </el-form-item>
  32. </template>
  33. </el-table-column>
  34. <el-table-column label="本次付款" prop="paymentPrice" fixed="right" min-width="115">
  35. <template #default="{ row, $index }">
  36. <el-form-item :prop="`${$index}.paymentPrice`" class="mb-0px!">
  37. <el-input-number
  38. v-model="row.paymentPrice"
  39. controls-position="right"
  40. :min="0"
  41. :precision="2"
  42. class="!w-100%"
  43. />
  44. </el-form-item>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="备注" min-width="150">
  48. <template #default="{ row, $index }">
  49. <el-form-item :prop="`${$index}.remark`" class="mb-0px!">
  50. <el-input v-model="row.remark" placeholder="请输入备注" />
  51. </el-form-item>
  52. </template>
  53. </el-table-column>
  54. <el-table-column align="center" fixed="right" label="操作" width="60">
  55. <template #default="{ $index }">
  56. <el-button @click="handleDelete($index)" link>—</el-button>
  57. </template>
  58. </el-table-column>
  59. </el-table>
  60. </el-form>
  61. <el-row justify="center" class="mt-3" v-if="!disabled">
  62. <el-button @click="handleAdd" round>+ 添加采购入库单</el-button>
  63. <el-button @click="handleAdd" round>+ 添加采购退货单</el-button>
  64. </el-row>
  65. </template>
  66. <script setup lang="ts">
  67. import { ProductApi, ProductVO } from '@/api/erp/product/product'
  68. import { StockApi } from '@/api/erp/stock/stock'
  69. import {
  70. erpCountInputFormatter,
  71. erpPriceInputFormatter,
  72. erpPriceMultiply,
  73. getSumValue
  74. } from '@/utils'
  75. const props = defineProps<{
  76. items: undefined
  77. disabled: false
  78. }>()
  79. const formLoading = ref(false) // 表单的加载中
  80. const formData = ref([])
  81. const formRules = reactive({
  82. paymentPrice: [{ required: true, message: '本次付款不能为空', trigger: 'blur' }]
  83. })
  84. const formRef = ref([]) // 表单 Ref
  85. const productList = ref<ProductVO[]>([]) // 产品列表
  86. /** 初始化设置入库项 */
  87. watch(
  88. () => props.items,
  89. async (val) => {
  90. formData.value = val
  91. },
  92. { immediate: true }
  93. )
  94. /** 合计 */
  95. const getSummaries = (param: SummaryMethodProps) => {
  96. const { columns, data } = param
  97. const sums: string[] = []
  98. columns.forEach((column, index: number) => {
  99. if (index === 0) {
  100. sums[index] = '合计'
  101. return
  102. }
  103. if (['totalPrice', 'paidPrice', 'paymentPrice'].includes(column.property)) {
  104. const sum = getSumValue(data.map((item) => Number(item[column.property])))
  105. sums[index] = erpPriceInputFormatter(sum)
  106. } else {
  107. sums[index] = ''
  108. }
  109. })
  110. return sums
  111. }
  112. /** 新增按钮操作 */
  113. const handleAdd = () => {
  114. const row = {
  115. id: undefined,
  116. totalPrice: undefined,
  117. paidPrice: undefined,
  118. paymentPrice: undefined,
  119. totalPrice: undefined,
  120. remark: undefined
  121. }
  122. formData.value.push(row)
  123. }
  124. /** 删除按钮操作 */
  125. const handleDelete = (index: number) => {
  126. formData.value.splice(index, 1)
  127. }
  128. /** 表单校验 */
  129. const validate = () => {
  130. return formRef.value.validate()
  131. }
  132. defineExpose({ validate })
  133. </script>