weightForm.vue 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <xn-form-container
  3. :title="'编辑提货重量'"
  4. :width="700"
  5. v-model:open="open"
  6. :destroy-on-close="true"
  7. @close="onClose"
  8. >
  9. <a-descriptions :column="4" size="middle" bordered class="mb-2" :label-style="labelStyle" :contentStyle="contentStyle">
  10. <a-descriptions-item label="货品编码" :span="4">{{ formData.goodsCode }}</a-descriptions-item>
  11. <a-descriptions-item label="货品信息" :span="4">{{ formData.goodsName }} ( {{ formData.goodsModel }} )</a-descriptions-item>
  12. <a-descriptions-item label="提货时间段" :span="4">{{ formData.confStartTime }} ~ {{ formData.confEndTime }}</a-descriptions-item>
  13. <a-descriptions-item label="原最大提货重量" :span="4">{{ confWeight }} KG</a-descriptions-item>
  14. <a-descriptions-item label="已提货重量" :span="4">{{ formData.usedWeight }} KG</a-descriptions-item>
  15. <a-descriptions-item label="剩余提货重量" :span="4">{{ formData.lastWeight }} KG</a-descriptions-item>
  16. </a-descriptions>
  17. <a-form ref="formRef" :model="formData" :rules="formRules" :wrapper-col="wrapperCol" :label-col="labelCol">
  18. <a-form-item label="最大提货重量(KG):" name="confWeight">
  19. <a-input-number v-model:value="formData.confWeight" :min="formData.usedWeight" style="width: 100%;" placeholder="请输入最大提货重量" allow-clear />
  20. </a-form-item>
  21. </a-form>
  22. <div style="color: red;">提示:不得小于当前已提货重量 {{ formData.usedWeight }} KG</div>
  23. <template #footer>
  24. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  25. <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
  26. </template>
  27. </xn-form-container>
  28. </template>
  29. <script setup name="goodsConfForm">
  30. import { cloneDeep } from 'lodash-es'
  31. import { required } from '@/utils/formRules'
  32. import goodsConfApi from '@/api/biz/goodsConfApi'
  33. // 抽屉状态
  34. const open = ref(false)
  35. const emit = defineEmits({ successful: null })
  36. const formRef = ref()
  37. // 表单数据
  38. const formData = ref({})
  39. const submitLoading = ref(false)
  40. const confWeight = ref("")
  41. //设置表单样式
  42. const labelCol = ref({ span: 5})
  43. const wrapperCol = ref({ span: 16})
  44. // 打开抽屉
  45. const onOpen = (record) => {
  46. open.value = true
  47. if (record) {
  48. let recordData = cloneDeep(record)
  49. formData.value = Object.assign({}, recordData)
  50. confWeight.value = formData.value.confWeight
  51. }
  52. }
  53. // 关闭抽屉
  54. const onClose = () => {
  55. formRef.value.resetFields()
  56. formData.value = {}
  57. open.value = false
  58. }
  59. // 默认要校验的
  60. const formRules = {
  61. confWeight: [required("请输入最大提货重量")]
  62. }
  63. // 验证并提交数据
  64. const onSubmit = () => {
  65. formRef.value
  66. .validate()
  67. .then(() => {
  68. submitLoading.value = true
  69. const formDataParam = cloneDeep(formData.value)
  70. goodsConfApi
  71. .goodsConfSubmitForm(formDataParam, formDataParam.id)
  72. .then(() => {
  73. onClose()
  74. emit('successful')
  75. })
  76. .finally(() => {
  77. submitLoading.value = false
  78. })
  79. })
  80. .catch(() => {})
  81. }
  82. // 抛出函数
  83. defineExpose({
  84. onOpen
  85. })
  86. </script>