StockInItemForm.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. >
  10. <el-table :data="formData" show-summary class="-mt-10px">
  11. <el-table-column label="序号" type="index" width="60" />
  12. <el-table-column label="仓库名称" min-width="150">
  13. <template #default="{ row, $index }">
  14. <el-form-item
  15. :prop="`${$index}.warehouseId`"
  16. :rules="formRules.warehouseId"
  17. class="mb-0px!"
  18. >
  19. <el-input v-model="row.warehouseId" placeholder="请输入仓库编号" />
  20. </el-form-item>
  21. </template>
  22. </el-table-column>
  23. <el-table-column label="产品名称" min-width="150">
  24. <template #default="{ row, $index }">
  25. <el-form-item :prop="`${$index}.productId`" :rules="formRules.productId" class="mb-0px!">
  26. <el-input v-model="row.productId" placeholder="请输入产品编号" />
  27. </el-form-item>
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="条码" min-width="150">
  31. <template #default="{ row }">
  32. <el-form-item class="mb-0px!">
  33. <el-input disabled v-model="row.productId" placeholder="请输入条码" />
  34. </el-form-item>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="单位" min-width="150">
  38. <template #default="{ row }">
  39. <el-form-item class="mb-0px!">
  40. <el-input disabled v-model="row.productUnitId" placeholder="请输入单位编号" />
  41. </el-form-item>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="数量" prop="count" min-width="150">
  45. <template #default="{ row, $index }">
  46. <el-form-item :prop="`${$index}.count`" :rules="formRules.count" class="mb-0px!">
  47. <el-input v-model="row.count" placeholder="请输入商品数量" />
  48. </el-form-item>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="商品单价" min-width="150">
  52. <template #default="{ row, $index }">
  53. <el-form-item
  54. :prop="`${$index}.productPrice`"
  55. :rules="formRules.productPrice"
  56. class="mb-0px!"
  57. >
  58. <el-input v-model="row.productPrice" placeholder="请输入商品单价" />
  59. </el-form-item>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="合计金额" min-width="150">
  63. <template #default="{ row, $index }">
  64. <el-form-item
  65. :prop="`${$index}.totalPrice`"
  66. :rules="formRules.totalPrice"
  67. class="mb-0px!"
  68. >
  69. <el-input v-model="row.totalPrice" placeholder="请输入合计金额,单位:元" />
  70. </el-form-item>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="备注" min-width="150">
  74. <template #default="{ row, $index }">
  75. <el-form-item :prop="`${$index}.remark`" :rules="formRules.remark" class="mb-0px!">
  76. <el-input v-model="row.remark" placeholder="请输入备注" />
  77. </el-form-item>
  78. </template>
  79. </el-table-column>
  80. <el-table-column align="center" fixed="right" label="操作" width="60">
  81. <template #default="{ $index }">
  82. <el-button @click="handleDelete($index)" link>—</el-button>
  83. </template>
  84. </el-table-column>
  85. </el-table>
  86. </el-form>
  87. <el-row justify="center" class="mt-3">
  88. <el-button @click="handleAdd" round>+ 添加入库产品</el-button>
  89. </el-row>
  90. </template>
  91. <script setup lang="ts">
  92. import { StockInApi } from '@/api/erp/stock/in'
  93. const props = defineProps<{
  94. inId: undefined // 入库编号(主表的关联字段)
  95. }>()
  96. const formLoading = ref(false) // 表单的加载中
  97. const formData = ref([])
  98. const formRules = reactive({
  99. inId: [{ required: true, message: '入库编号不能为空', trigger: 'blur' }],
  100. warehouseId: [{ required: true, message: '仓库编号不能为空', trigger: 'blur' }],
  101. productId: [{ required: true, message: '产品编号不能为空', trigger: 'blur' }],
  102. productUnitId: [{ required: true, message: '商品单位编号不能为空', trigger: 'blur' }],
  103. productPrice: [{ required: true, message: '商品单价不能为空', trigger: 'blur' }],
  104. count: [{ required: true, message: '商品数量不能为空', trigger: 'blur' }],
  105. totalPrice: [{ required: true, message: '合计金额,单位:元不能为空', trigger: 'blur' }]
  106. })
  107. const formRef = ref() // 表单 Ref
  108. /** 监听主表的关联字段的变化,加载对应的子表数据 */
  109. watch(
  110. () => props.inId,
  111. async (val) => {
  112. // 1. 重置表单
  113. formData.value = []
  114. // 2. val 非空,则加载数据
  115. if (!val) {
  116. return
  117. }
  118. try {
  119. formLoading.value = true
  120. formData.value = await StockInApi.getStockInItemListByInId(val)
  121. } finally {
  122. formLoading.value = false
  123. }
  124. },
  125. { immediate: true }
  126. )
  127. /** 新增按钮操作 */
  128. const handleAdd = () => {
  129. const row = {
  130. id: undefined,
  131. inId: undefined,
  132. warehouseId: undefined,
  133. productId: undefined,
  134. productUnitId: undefined,
  135. productPrice: undefined,
  136. count: undefined,
  137. totalPrice: undefined,
  138. remark: undefined
  139. }
  140. row.inId = props.inId
  141. formData.value.push(row)
  142. }
  143. /** 删除按钮操作 */
  144. const handleDelete = (index) => {
  145. formData.value.splice(index, 1)
  146. }
  147. /** 表单校验 */
  148. const validate = () => {
  149. return formRef.value.validate()
  150. }
  151. /** 表单值 */
  152. const getData = () => {
  153. return formData.value
  154. }
  155. defineExpose({ validate, getData })
  156. </script>