BaseForm.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1400"
  5. :visible="visible"
  6. class="ant-modal2"
  7. :confirmLoading="confirmLoading"
  8. @cancel="handleCancel"
  9. >
  10. <a-form :form="form">
  11. <a-form-item v-show="false" >
  12. <a-input v-decorator="['id']" type="hidden"/>
  13. <a-input v-decorator="['planid']" type="hidden"/>
  14. </a-form-item>
  15. <a-form-item
  16. label="标题"
  17. :labelCol="labelCol"
  18. :wrapperCol="wrapperCol"
  19. >
  20. <a-input
  21. v-decorator="['plantitle', {rules: [{required: true, message: '标题不能为空'}]}]" />
  22. </a-form-item>
  23. <a-form-item
  24. label="摘要"
  25. :labelCol="labelCol"
  26. :wrapperCol="wrapperCol"
  27. >
  28. <a-input
  29. v-decorator="['digest', {rules: [{required: true, message: '摘要不能为空'}]}]" />
  30. </a-form-item>
  31. <a-form-item
  32. label="简介"
  33. :labelCol="labelCol"
  34. :wrapperCol="wrapperCol"
  35. >
  36. <a-input
  37. v-decorator="['shortdesc']" />
  38. </a-form-item>
  39. <a-form-item
  40. label="关键字"
  41. :labelCol="labelCol"
  42. :wrapperCol="wrapperCol"
  43. >
  44. <a-input
  45. v-decorator="['keywords']" />
  46. </a-form-item>
  47. <a-form-item
  48. label="排序"
  49. :labelCol="labelCol"
  50. :wrapperCol="wrapperCol"
  51. >
  52. <a-input
  53. type="number"
  54. v-decorator="['orderid', {rules: [{required: true, message: '排序不能为空'}]}]" />
  55. </a-form-item>
  56. <a-form-item
  57. label="内容"
  58. :labelCol="labelCol"
  59. :wrapperCol="wrapperCol"
  60. >
  61. <wang-editor
  62. :content="plancontext"
  63. @catchData="catchData"
  64. ></wang-editor>
  65. </a-form-item>
  66. </a-form>
  67. <template slot="footer">
  68. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  69. </template>
  70. </a-modal>
  71. </template>
  72. <script>
  73. import pick from 'lodash.pick'
  74. import { addPlanDetail, updatePlanDetail } from '@/api/qykh/plandetails'
  75. import WangEditor from '@/components/Editor/WangEditor'
  76. import UploadImg from '@/components/Upload/UploadImg'
  77. import UploadArticleFile from '@/components/Upload/UploadArticleFile'
  78. export default {
  79. name: 'BaseForm',
  80. components: {
  81. WangEditor,
  82. UploadImg,
  83. UploadArticleFile
  84. },
  85. data () {
  86. return {
  87. labelCol: {
  88. xs: { span: 24 },
  89. sm: { span: 4 }
  90. },
  91. wrapperCol: {
  92. xs: { span: 24 },
  93. sm: { span: 20 }
  94. },
  95. topFlag: 0,
  96. status: 1,
  97. confirmLoading: false,
  98. mdl: {},
  99. modalTitle: null,
  100. form: this.$form.createForm(this),
  101. visible: false,
  102. plancontext: '',
  103. picture: '',
  104. resultContent: '',
  105. type: null
  106. }
  107. },
  108. props: {
  109. },
  110. created () {
  111. },
  112. methods: {
  113. base (record) {
  114. this.visible = true
  115. // 如果是空标识添加
  116. if (this.BaseTool.Object.isBlank(record)) {
  117. this.modalTitle = '添加'
  118. this.plancontext = ''
  119. return
  120. }
  121. this.modalTitle = '编辑'
  122. this.type = record.type
  123. const { form: { setFieldsValue } } = this
  124. this.$nextTick(() => {
  125. setFieldsValue(Object.assign(pick(record, [
  126. 'id',
  127. 'plantitle',
  128. 'shortdesc',
  129. 'planid',
  130. 'orderid',
  131. 'planid',
  132. 'seoid',
  133. 'time',
  134. 'digest',
  135. 'keywords'
  136. ])))
  137. this.plancontext = record.plancontext
  138. })
  139. },
  140. catchData (content) {
  141. this.resultContent = content
  142. },
  143. save () {
  144. const { form: { validateFieldsAndScroll } } = this
  145. this.confirmLoading = true
  146. validateFieldsAndScroll((errors, values) => {
  147. if (errors) {
  148. this.confirmLoading = false
  149. return
  150. }
  151. values = {
  152. ...values,
  153. plancontext: this.resultContent ? this.resultContent : this.plancontext
  154. }
  155. /* if (this.type === 2) {
  156. if (values.parentId == null) {
  157. this.$message.error('请选择父文章')
  158. return
  159. }
  160. } */
  161. if (this.BaseTool.String.isBlank(values.id)) {
  162. addPlanDetail(values)
  163. .then(() => {
  164. this.handleCancel(values)
  165. }).catch(() => {
  166. this.confirmLoading = false
  167. })
  168. } else {
  169. updatePlanDetail(values)
  170. .then(() => {
  171. this.handleCancel(values)
  172. }).catch(() => {
  173. this.confirmLoading = false
  174. })
  175. }
  176. })
  177. },
  178. handleCancel (values) {
  179. this.visible = false
  180. this.confirmLoading = false
  181. this.plancontext = ''
  182. this.resultContent = ''
  183. this.topFlag = ''
  184. this.status = 1
  185. this.picture = ''
  186. this.form.resetFields()
  187. if (this.BaseTool.Object.isNotBlank(values)) {
  188. this.$emit('ok', values)
  189. }
  190. }
  191. }
  192. }
  193. </script>