form.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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="licenseNumber">
  11. <a-input v-model:value="formData.licenseNumber" placeholder="请输入车牌号" allow-clear />
  12. </a-form-item>
  13. <a-form-item label="司机信息:" name="driverId">
  14. <xn-user-selector
  15. :org-tree-api="selectorApiFunction.orgTreeApi"
  16. :user-page-api="selectorApiFunction.userPageApi"
  17. :radio-model="true"
  18. placeholder="请选择司机"
  19. v-model:value="formData.driverId"
  20. />
  21. </a-form-item>
  22. </a-form>
  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="bizAppointmentRecordForm">
  30. import { cloneDeep } from 'lodash-es'
  31. import { required } from '@/utils/formRules'
  32. import bizChargeStationReservationApi from '@/api/biz/bizChargeStationReservationApi'
  33. import userApi from '@/api/biz/bizUserApi'
  34. // 抽屉状态
  35. const open = ref(false)
  36. const emit = defineEmits({ successful: null })
  37. const formRef = ref()
  38. // 表单数据
  39. const formData = ref({})
  40. const submitLoading = ref(false)
  41. const orderIdList = ref()
  42. const timeIdList = ref()
  43. const overIdList = ref()
  44. const loadPointIdList = ref()
  45. const loadTimeIdList = ref()
  46. //设置表单样式
  47. const labelCol = ref({ span: 5})
  48. const wrapperCol = ref({ span: 16})
  49. // 打开抽屉
  50. const onOpen = (record) => {
  51. open.value = true
  52. if (record) {
  53. let recordData = cloneDeep(record)
  54. formData.value = Object.assign({}, recordData)
  55. }
  56. }
  57. // 传递设计器需要的API
  58. const selectorApiFunction = {
  59. orgTreeApi: (param) => {
  60. return userApi.userOrgTreeSelector(param).then((data) => {
  61. return Promise.resolve(data)
  62. })
  63. },
  64. userPageApi: (param) => {
  65. param.roleName = '司机'
  66. return userApi.userSelectorByRole(param).then((data) => {
  67. return Promise.resolve(data)
  68. })
  69. }
  70. }
  71. // 关闭抽屉
  72. const onClose = () => {
  73. formRef.value.resetFields()
  74. formData.value = {}
  75. open.value = false
  76. }
  77. // 默认要校验的
  78. const formRules = {
  79. licenseNumber: [required('请输入车牌号')],
  80. driverId: [required('请选择司机')]
  81. }
  82. // 验证并提交数据
  83. const onSubmit = () => {
  84. formRef.value
  85. .validate()
  86. .then(() => {
  87. submitLoading.value = true
  88. const formDataParam = cloneDeep(formData.value)
  89. bizChargeStationReservationApi
  90. .bizChargeStationReservationSubmitForm(formDataParam, formDataParam.id)
  91. .then(() => {
  92. onClose()
  93. emit('successful')
  94. })
  95. .finally(() => {
  96. submitLoading.value = false
  97. })
  98. })
  99. .catch(() => {})
  100. }
  101. // 抛出函数
  102. defineExpose({
  103. onOpen
  104. })
  105. </script>