SubmitForm.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <a-card :bordered="false" v-show="visible" class="card">
  3. <a-row :gutter="48" slot="extra">
  4. <a-col :md="48" :sm="48">
  5. <a-space class="table-page-search-submitButtons">
  6. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  7. <a-button type="default" @click="handleCancel()">返回</a-button>
  8. </a-space>
  9. </a-col>
  10. </a-row>
  11. <a-form :form="form" :labelCol="BaseTool.Constant.labelCol" :wrapperCol="BaseTool.Constant.wrapperCol">
  12. <a-row>
  13. <MComponent class="hover" v-for="item in components" :key="item.id" :config="config" :detail="item" @selectInfo="handleInfoSelect" />
  14. </a-row>
  15. </a-form>
  16. <SelectInfo ref="selectInfo" @selected="handleInfoSelected" />
  17. </a-card>
  18. </template>
  19. <script>
  20. import MComponent from './component/modules/Component.vue'
  21. import SelectInfo from './component/modules/SelectInfo'
  22. import { addCustomData } from '@/api/custom/form'
  23. export default {
  24. components: {
  25. MComponent,
  26. SelectInfo,
  27. },
  28. data() {
  29. return {
  30. visible: false,
  31. confirmLoading: false,
  32. components: [],
  33. config: {},
  34. form: this.$form.createForm(this),
  35. record: {},
  36. }
  37. },
  38. created() {},
  39. methods: {
  40. base(record) {
  41. this.visible = true
  42. this.record = record
  43. this.components = JSON.parse(record.jsonString).components
  44. this.config = JSON.parse(record.jsonString).config
  45. },
  46. handleCancel() {
  47. this.visible = false
  48. this.confirmLoading = false
  49. this.form.resetFields()
  50. this.$emit('ok')
  51. },
  52. handleInfoSelect(item) {
  53. this.$refs.selectInfo.base(item)
  54. },
  55. handleInfoSelected(keys, rows, detail) {
  56. const {
  57. form: { setFieldsValue },
  58. } = this
  59. const data = rows[0]
  60. const value = {}
  61. detail.attrs.connect.forEach((item) => {
  62. value[item.bind] = data[item.columnName]
  63. })
  64. this.$nextTick(() => {
  65. setFieldsValue(value)
  66. })
  67. },
  68. save() {
  69. const {
  70. form: { validateFieldsAndScroll },
  71. } = this
  72. this.confirmLoading = true
  73. validateFieldsAndScroll((errors, values) => {
  74. console.log(2)
  75. if (errors) {
  76. this.confirmLoading = false
  77. return
  78. }
  79. console.log(3)
  80. const params = {
  81. jsonString: JSON.stringify(values),
  82. flowId: this.record.flowId,
  83. formId: this.record.id,
  84. }
  85. console.log(params)
  86. addCustomData(params).then((res) => {
  87. this.handleCancel()
  88. })
  89. })
  90. },
  91. },
  92. }
  93. </script>
  94. <style>
  95. </style>