accountForm.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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="loginAccount">
  11. <a-input v-model:value="formData.loginAccount" placeholder="请输入账号" allow-clear />
  12. </a-form-item>
  13. <a-form-item label="授信额度:" name="creditAmount">
  14. <a-input v-model:value="formData.creditAmount" placeholder="请输入授信额度" allow-clear />
  15. </a-form-item>
  16. </a-form>
  17. <template #footer>
  18. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  19. <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
  20. </template>
  21. </xn-form-container>
  22. </template>
  23. <script setup name="bizServiceCustomerAccountForm">
  24. import { cloneDeep } from 'lodash-es'
  25. import { required } from '@/utils/formRules'
  26. import bizServiceCustomerAccountApi from '@/api/biz/bizServiceCustomerAccountApi'
  27. // 抽屉状态
  28. const open = ref(false)
  29. const emit = defineEmits({ successful: null })
  30. const formRef = ref()
  31. // 表单数据
  32. const formData = ref({})
  33. const submitLoading = ref(false)
  34. //设置表单样式
  35. const labelCol = ref({ span: 4})
  36. const wrapperCol = ref({ span: 16})
  37. // 打开抽屉
  38. const onOpen = (record) => {
  39. open.value = true
  40. if (record) {
  41. let recordData = cloneDeep(record)
  42. formData.value = Object.assign({}, recordData)
  43. }
  44. }
  45. // 关闭抽屉
  46. const onClose = () => {
  47. formRef.value.resetFields()
  48. formData.value = {}
  49. open.value = false
  50. }
  51. // 默认要校验的
  52. const formRules = {
  53. loginAccount: [required('请输入账户')],
  54. creditAmount: [required('请输入授信额度')],
  55. }
  56. // 验证并提交数据
  57. const onSubmit = () => {
  58. formRef.value
  59. .validate()
  60. .then(() => {
  61. submitLoading.value = true
  62. const formDataParam = cloneDeep(formData.value)
  63. bizServiceCustomerAccountApi
  64. .bizServiceCustomerAccountSubmitForm(formDataParam, formDataParam.id)
  65. .then(() => {
  66. onClose()
  67. emit('successful')
  68. })
  69. .finally(() => {
  70. submitLoading.value = false
  71. })
  72. })
  73. .catch(() => {})
  74. }
  75. // 抛出函数
  76. defineExpose({
  77. onOpen
  78. })
  79. </script>