BaseForm.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <a-card :bordered="false" v-show="visible" class="card" :title="modalTitle">
  3. <a-row :gutter="48" slot="extra">
  4. <a-col :md="48" :sm="48">
  5. <span class="table-page-search-submitButtons" style="float: right">
  6. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  7. <a-button style="margin-left: 8px" type="default" @click="handleCancel()">返回</a-button>
  8. </span>
  9. </a-col>
  10. </a-row>
  11. <a-form :form="form">
  12. <a-form-item v-show="false">
  13. <a-input v-decorator="['id']" type="hidden" />
  14. </a-form-item>
  15. <row-list :col="2">
  16. <row-item>
  17. <a-form-item label="关联类型" :labelCol="BaseTool.Constant.labelCol" :wrapperCol="BaseTool.Constant.wrapperCol">
  18. <a-select v-decorator="['linkType', {rules: [{required: true, message: '关联类型不能为空'}]}]">
  19. <a-select-option v-for="(label,value) in linkTypeMap" :value="value" :key="value">
  20. {{ label }}
  21. </a-select-option>
  22. </a-select>
  23. </a-form-item>
  24. </row-item>
  25. <row-item>
  26. <a-form-item label="关联流程" :labelCol="BaseTool.Constant.labelCol" :wrapperCol="BaseTool.Constant.wrapperCol">
  27. <a-select v-model="flowId">
  28. <a-select-option v-for="{name,id} in workFlowList" :value="id" :key="id">
  29. {{ name }}
  30. </a-select-option>
  31. </a-select>
  32. </a-form-item>
  33. </row-item>
  34. </row-list>
  35. <row-list :col="2">
  36. <row-item>
  37. <a-form-item
  38. label="备注"
  39. :labelCol="BaseTool.Constant.labelCol"
  40. :wrapperCol="BaseTool.Constant.wrapperCol"
  41. >
  42. <a-textarea
  43. :rows="3"
  44. v-decorator="['remark']"/>
  45. </a-form-item>
  46. </row-item>
  47. </row-list>
  48. </a-form>
  49. </a-card>
  50. </template>
  51. <script>
  52. import pick from 'lodash.pick'
  53. import { addCustomWorkflowRelation, updateCustomWorkflowRelation } from '@/api/custom/flowrelation'
  54. import { queryWorkflow } from '@/api/workflow/workflow'
  55. export default {
  56. name: 'BaseCustomWorkflowRelation',
  57. data () {
  58. return {
  59. confirmLoading: false,
  60. modalTitle: null,
  61. form: this.$form.createForm(this),
  62. visible: false,
  63. flowId: null,
  64. linkTypeMap: {},
  65. workFlowList: []
  66. // 下拉框map
  67. }
  68. },
  69. props: {},
  70. created () {
  71. // 下拉框map
  72. this.linkTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.LINK_TYPE)
  73. queryWorkflow().then((res) => {
  74. this.workFlowList = res.data
  75. })
  76. },
  77. methods: {
  78. base (record) {
  79. this.visible = true
  80. // 如果是空标识添加
  81. if (this.BaseTool.Object.isBlank(record)) {
  82. this.modalTitle = '添加关联'
  83. return
  84. }
  85. this.modalTitle = '编辑关联'
  86. const { form: { setFieldsValue } } = this
  87. this.flowId = record.flowId
  88. // 日期处理
  89. this.$nextTick(() => {
  90. setFieldsValue(Object.assign(pick(record, [
  91. 'id',
  92. 'linkType',
  93. 'flowId',
  94. 'remark'
  95. ])))
  96. })
  97. },
  98. save () {
  99. const { form: { validateFieldsAndScroll } } = this
  100. this.confirmLoading = true
  101. validateFieldsAndScroll((errors, values) => {
  102. if (errors) {
  103. this.confirmLoading = false
  104. return
  105. }
  106. values.flowId = this.flowId
  107. if (!values.flowId) {
  108. this.$message.error('流程不可为空')
  109. this.confirmLoading = false
  110. return
  111. }
  112. // 日期处理
  113. if (this.BaseTool.String.isBlank(values.id)) {
  114. addCustomWorkflowRelation(values)
  115. .then(() => {
  116. this.handleCancel(values)
  117. }).catch(() => {
  118. this.confirmLoading = false
  119. })
  120. } else {
  121. updateCustomWorkflowRelation(values)
  122. .then(() => {
  123. this.handleCancel(values)
  124. }).catch(() => {
  125. this.confirmLoading = false
  126. })
  127. }
  128. })
  129. },
  130. handleCancel (values) {
  131. this.visible = false
  132. this.confirmLoading = false
  133. this.form.resetFields()
  134. if (this.BaseTool.Object.isNotBlank(values)) {
  135. this.$emit('ok', values)
  136. } else {
  137. this.$emit('ok')
  138. }
  139. }
  140. }
  141. }
  142. </script>