form.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <xn-form-container
  3. :title="formData.id ? '编辑停车费配置' : '增加停车费配置'"
  4. :width="700"
  5. v-model:open="open"
  6. :destroy-on-close="true"
  7. @close="onClose"
  8. >
  9. <a-form ref="formRef" :model="formData" :rules="formRules" :wrapper-col="wrapperCol" :label-col="labelCol">
  10. <a-form-item label="预约类型:" name="appointmentType">
  11. <a-radio-group button-style="solid" v-model:value="formData.appointmentType">
  12. <a-radio-button v-for="appointmentItem in appointmentClassifyOptions" :key="appointmentItem.value" :value="appointmentItem.value" >
  13. {{ appointmentItem.label }}
  14. </a-radio-button>
  15. </a-radio-group>
  16. </a-form-item>
  17. <a-form-item label="免费停留时长(分钟):" name="freeParkTime">
  18. <a-input-number v-model:value="formData.freeParkTime" :min="0" style="width: 100%;" placeholder="请输入免费停留时长" allow-clear />
  19. </a-form-item>
  20. <a-form-item label="超出费用(元/小时):" name="exceedAmount">
  21. <a-input-number v-model:value="formData.exceedAmount" :min="0" style="width: 100%;" placeholder="请输入超出每小时费用" allow-clear />
  22. </a-form-item>
  23. <a-form-item label="支付后停留时长(分钟):" name="payAfterParkTime">
  24. <a-input-number v-model:value="formData.payAfterParkTime" :min="0" style="width: 100%;" placeholder="请输入支付后停留时长" allow-clear />
  25. </a-form-item>
  26. </a-form>
  27. <template #footer>
  28. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  29. <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
  30. </template>
  31. </xn-form-container>
  32. </template>
  33. <script setup name="bizParkConfigForm">
  34. import { cloneDeep } from 'lodash-es'
  35. import { required } from '@/utils/formRules'
  36. import bizParkConfigApi from '@/api/biz/bizParkConfigApi'
  37. import tool from '@/utils/tool'
  38. // 抽屉状态
  39. const open = ref(false)
  40. const emit = defineEmits({ successful: null })
  41. const formRef = ref()
  42. // 表单数据
  43. const formData = ref({})
  44. const submitLoading = ref(false)
  45. //设置表单样式
  46. const labelCol = ref({ span: 6})
  47. const wrapperCol = ref({ span: 16})
  48. // 预约分类
  49. const appointmentClassifyOptions = tool.dictList('appointment_classify')
  50. // 打开抽屉
  51. const onOpen = (record) => {
  52. open.value = true
  53. if (record) {
  54. let recordData = cloneDeep(record)
  55. formData.value = Object.assign({}, recordData)
  56. }
  57. }
  58. // 关闭抽屉
  59. const onClose = () => {
  60. formRef.value.resetFields()
  61. formData.value = {}
  62. open.value = false
  63. }
  64. // 默认要校验的
  65. const formRules = {
  66. appointmentType: [required('请选择预约类型')],
  67. freeParkTime: [required('请输入免费停留时长')],
  68. exceedAmount: [required('请输入超出每小时费用')],
  69. payAfterParkTime: [required('请输入支付后停留时长')],
  70. }
  71. // 验证并提交数据
  72. const onSubmit = () => {
  73. formRef.value
  74. .validate()
  75. .then(() => {
  76. submitLoading.value = true
  77. const formDataParam = cloneDeep(formData.value)
  78. bizParkConfigApi
  79. .bizParkConfigSubmitForm(formDataParam, formDataParam.id)
  80. .then(() => {
  81. onClose()
  82. emit('successful')
  83. })
  84. .finally(() => {
  85. submitLoading.value = false
  86. })
  87. })
  88. .catch(() => {})
  89. }
  90. // 抛出函数
  91. defineExpose({
  92. onOpen
  93. })
  94. </script>