form.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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="beginTime">
  11. <!-- <a-input v-model:value="formData.beginTime" placeholder="请输入开始时段" allow-clear />-->
  12. <a-time-picker v-model:value="formData.beginTime" valueFormat="HH:mm" format = "HH:mm" placeholder="请选择预约开始时间段" style="width: 100%" />
  13. </a-form-item>
  14. <a-form-item label="结束时段:" name="endTime">
  15. <a-time-picker v-model:value="formData.endTime" valueFormat="HH:mm" format = "HH:mm" placeholder="请选择预约结束时间段" style="width: 100%" />
  16. </a-form-item>
  17. <a-form-item label="申请数量:" name="applyNumber">
  18. <a-input-number v-model:value="formData.applyNumber" style="width:90%" :precision="0" :min="1" :max="99999" placeholder="请输入申请数量" allow-clear /><span style="margin-left:10px;">次</span>
  19. </a-form-item>
  20. </a-form>
  21. <template #footer>
  22. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  23. <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
  24. </template>
  25. </xn-form-container>
  26. </template>
  27. <script setup name="bizAppointmentTimeForm">
  28. import { cloneDeep } from 'lodash-es'
  29. import { required } from '@/utils/formRules'
  30. import bizAppointmentTimeApi from '@/api/biz/bizAppointmentTimeApi'
  31. // 抽屉状态
  32. const open = ref(false)
  33. const emit = defineEmits({ successful: null })
  34. const formRef = ref()
  35. // 表单数据
  36. const formData = ref({})
  37. const submitLoading = ref(false)
  38. //设置表单样式
  39. const labelCol = ref({ span: 5})
  40. const wrapperCol = ref({ span: 16})
  41. // 打开抽屉
  42. const onOpen = (record) => {
  43. open.value = true
  44. if (record) {
  45. let recordData = cloneDeep(record)
  46. formData.value = Object.assign({}, recordData)
  47. }
  48. }
  49. // 关闭抽屉
  50. const onClose = () => {
  51. formRef.value.resetFields()
  52. formData.value = {}
  53. open.value = false
  54. }
  55. // 默认要校验的
  56. const formRules = {
  57. beginTime: [required('请输入开始时段')],
  58. endTime: [required('请输入结束时段')],
  59. applyNumber: [required('请输入申请数量')],
  60. }
  61. // 验证并提交数据
  62. const onSubmit = () => {
  63. formRef.value
  64. .validate()
  65. .then(() => {
  66. submitLoading.value = true
  67. const formDataParam = cloneDeep(formData.value)
  68. bizAppointmentTimeApi
  69. .bizAppointmentTimeSubmitForm(formDataParam, formDataParam.id)
  70. .then(() => {
  71. onClose()
  72. emit('successful')
  73. })
  74. .finally(() => {
  75. submitLoading.value = false
  76. })
  77. })
  78. .catch(() => {})
  79. }
  80. // 抛出函数
  81. defineExpose({
  82. onOpen
  83. })
  84. </script>