AdsAccountForm.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <div style="min-height: 400px">
  3. <BasicForm @register="registerForm"></BasicForm>
  4. <div style="width: 100%;text-align: center" v-if="!formDisabled">
  5. <a-button @click="submitForm" pre-icon="ant-design:check" type="primary">提 交</a-button>
  6. </div>
  7. </div>
  8. </template>
  9. <script lang="ts">
  10. import {BasicForm, useForm} from '/src/components/Form';
  11. import {computed, defineComponent} from 'vue';
  12. import {defHttp} from '/src/utils/http/axios';
  13. import { propTypes } from '/src/utils/propTypes';
  14. import {getBpmFormSchema} from '../AdsAccount.data';
  15. import {saveOrUpdate} from '../AdsAccount.api';
  16. export default defineComponent({
  17. name: "AdsAccountForm",
  18. components:{
  19. BasicForm
  20. },
  21. props:{
  22. formData: propTypes.object.def({}),
  23. formBpm: propTypes.bool.def(true),
  24. },
  25. setup(props){
  26. const [registerForm, { setFieldsValue, setProps, getFieldsValue }] = useForm({
  27. labelWidth: 150,
  28. schemas: getBpmFormSchema(props.formData),
  29. showActionButtonGroup: false,
  30. baseColProps: {span: 24}
  31. });
  32. const formDisabled = computed(()=>{
  33. if(props.formData.disabled === false){
  34. return false;
  35. }
  36. return true;
  37. });
  38. let formData = {};
  39. const queryByIdUrl = '/adsaccount/adsAccount/queryById';
  40. async function initFormData(){
  41. let params = {id: props.formData.dataId};
  42. const data = await defHttp.get({url: queryByIdUrl, params});
  43. formData = {...data}
  44. //设置表单的值
  45. await setFieldsValue(formData);
  46. //默认是禁用
  47. await setProps({disabled: formDisabled.value})
  48. }
  49. async function submitForm() {
  50. let data = getFieldsValue();
  51. let params = Object.assign({}, formData, data);
  52. console.log('表单数据', params)
  53. await saveOrUpdate(params, true)
  54. }
  55. initFormData();
  56. return {
  57. registerForm,
  58. formDisabled,
  59. submitForm,
  60. }
  61. }
  62. });
  63. </script>