form.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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="queueEfficiency">
  11. <a-input-number v-model:value="formData.queueEfficiency" style="width:90%" :precision="0" :min="1" :max="99999" placeholder="请输入排队时效" allow-clear /><span style="margin-left:10px;">分钟</span>
  12. </a-form-item>
  13. <a-form-item label="时段下拉个数:" name="pullNumber">
  14. <a-input-number v-model:value="formData.pullNumber" style="width:90%" :precision="0" :min="1" :max="99999" placeholder="请输入时段下拉个数" allow-clear /><span style="margin-left:10px;">个</span>
  15. </a-form-item>
  16. <a-form-item label="停留时长:" name="stopDuration">
  17. <a-input-number v-model:value="formData.stopDuration" style="width:90%" :precision="0" :min="1" :max="99999" placeholder="请输入停留时长" allow-clear /><span style="margin-left:10px;">分钟</span>
  18. </a-form-item>
  19. <a-form-item label="预约审核开关:" name="auditSwitch">
  20. <a-radio-group button-style="solid" v-model:value="formData.auditSwitch">
  21. <a-radio-button value="1">
  22. 开启
  23. </a-radio-button>
  24. <a-radio-button value="2">
  25. 关闭
  26. </a-radio-button>
  27. </a-radio-group>
  28. </a-form-item>
  29. <a-form-item label="订单重量校验开关:" name="orderWeightSwitch">
  30. <a-radio-group button-style="solid" v-model:value="formData.orderWeightSwitch">
  31. <a-radio-button value="1">
  32. 开启
  33. </a-radio-button>
  34. <a-radio-button value="2">
  35. 关闭
  36. </a-radio-button>
  37. </a-radio-group>
  38. </a-form-item>
  39. <a-form-item label="门禁强制校验开关:" name="accessControlSwitch">
  40. <a-radio-group button-style="solid" v-model:value="formData.accessControlSwitch">
  41. <a-radio-button value="1">
  42. 开启
  43. </a-radio-button>
  44. <a-radio-button value="2">
  45. 关闭
  46. </a-radio-button>
  47. </a-radio-group>
  48. </a-form-item>
  49. </a-form>
  50. <template #footer>
  51. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  52. <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
  53. </template>
  54. </xn-form-container>
  55. </template>
  56. <script setup name="bizConfigForm">
  57. import { cloneDeep } from 'lodash-es'
  58. import { required } from '@/utils/formRules'
  59. import bizConfigApi from '@/api/biz/bizConfigApi'
  60. // 抽屉状态
  61. const open = ref(false)
  62. const emit = defineEmits({ successful: null })
  63. const formRef = ref()
  64. // 表单数据
  65. const formData = ref({})
  66. const submitLoading = ref(false)
  67. //设置表单样式
  68. const labelCol = ref({ span: 6})
  69. const wrapperCol = ref({ span: 16})
  70. // 打开抽屉
  71. const onOpen = (record) => {
  72. open.value = true
  73. if (record) {
  74. let recordData = cloneDeep(record)
  75. formData.value = Object.assign({}, recordData)
  76. }else{
  77. formData.value.auditSwitch = '2'
  78. formData.value.orderWeightSwitch = '2'
  79. formData.value.accessControlSwitch = '2'
  80. }
  81. }
  82. // 关闭抽屉
  83. const onClose = () => {
  84. formRef.value.resetFields()
  85. formData.value = {}
  86. open.value = false
  87. }
  88. // 默认要校验的
  89. const formRules = {
  90. queueEfficiency: [required('请输入排队时效')],
  91. pullNumber: [required('请输入时段下拉个数')],
  92. stopDuration: [required('请输入停留时长')],
  93. auditSwitch: [required('请输入预约审核开关(1:开启 2:关闭)')],
  94. orderWeightSwitch: [required('请输入订单重量校验开关(1:开启 2:关闭)')],
  95. accessControlSwitch: [required('请输入门禁强制校验开关')],
  96. }
  97. // 验证并提交数据
  98. const onSubmit = () => {
  99. formRef.value
  100. .validate()
  101. .then(() => {
  102. submitLoading.value = true
  103. const formDataParam = cloneDeep(formData.value)
  104. bizConfigApi
  105. .bizConfigSubmitForm(formDataParam, formDataParam.id)
  106. .then(() => {
  107. onClose()
  108. emit('successful')
  109. })
  110. .finally(() => {
  111. submitLoading.value = false
  112. })
  113. })
  114. .catch(() => {})
  115. }
  116. // 抛出函数
  117. defineExpose({
  118. onOpen
  119. })
  120. </script>