addAnnModal.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <a-modal
  3. :title="title"
  4. v-model="addModalVisible"
  5. :confirmLoading="confirmLoading"
  6. @ok="handleOk"
  7. @cancel="handleCancel"
  8. width="86%"
  9. >
  10. <a-spin :spinning="confirmLoading">
  11. <a-form :form="addAnnForm" :label-col="{ span: 4 }" :wrapper-col="{ span: 14 }">
  12. <!-- 标题 类型 -->
  13. <a-row :gutter="24">
  14. <a-col :span="12">
  15. <a-form-item label="标题">
  16. <a-input
  17. v-decorator="['title', { rules: [{ required: true, message: '请输入标题' }] }]"
  18. placeholder="请输入标题"
  19. />
  20. </a-form-item>
  21. </a-col>
  22. <a-col :span="12">
  23. <a-form-item label="类型">
  24. <a-select
  25. v-decorator="['type', { rules: [{ required: true, message: '请选择类型' }] }]"
  26. placeholder="请选择类型"
  27. >
  28. <a-select-option value="规章制度">规章制度</a-select-option>
  29. <a-select-option value="党建学习">党建学习</a-select-option>
  30. <a-select-option value="公告信息">公告信息</a-select-option>
  31. </a-select>
  32. </a-form-item>
  33. </a-col>
  34. </a-row>
  35. <!-- 创建人创建日期>>>>新增弹框-->
  36. <div v-if="title == '新增馆内公告'">
  37. <a-row :gutter="24">
  38. <a-col :span="12">
  39. <a-form-item label="创建人">
  40. <a-input
  41. v-decorator="['createBy', { rules: [{ required: false, message: '请输入创建人' }] }]"
  42. placeholder="系统回显"
  43. disabled
  44. />
  45. </a-form-item>
  46. </a-col>
  47. <a-col :span="12">
  48. <a-form-item label="创建日期">
  49. <a-date-picker
  50. disabled
  51. style="width:100%"
  52. showTime
  53. format="YYYY-MM-DD HH:mm"
  54. placeholder="系统回显"
  55. @change="createTimeChange"
  56. @ok="createTimeOk"
  57. v-decorator="['createTime', { rules: [{ required: false, message: '请选择紧创建日期' }] }]"
  58. />
  59. </a-form-item>
  60. </a-col>
  61. </a-row>
  62. </div>
  63. <!-- 创建人创建日期>>>>编辑弹框 -->
  64. <div v-if="title == '编辑馆内公告'">
  65. <a-row :gutter="24">
  66. <a-col :span="12">
  67. <a-form-item label="创建人">
  68. <a-input
  69. v-decorator="['createBy', { rules: [{ required: false, message: '请输入创建人' }] }]"
  70. disabled
  71. />
  72. </a-form-item>
  73. </a-col>
  74. <a-col :span="12">
  75. <a-form-item label="创建日期">
  76. <a-date-picker
  77. disabled
  78. style="width:100%"
  79. showTime
  80. format="YYYY-MM-DD HH:mm:ss"
  81. @change="createTimeChange"
  82. @ok="createTimeOk"
  83. v-decorator="['createTime', { rules: [{ required: false, message: '请选择紧创建日期' }] }]"
  84. />
  85. </a-form-item>
  86. </a-col>
  87. </a-row>
  88. </div>
  89. <!-- 发布 -->
  90. <!-- <a-row :gutter="24">
  91. <a-col :span="12">
  92. <a-form-item label="是否发布:">
  93. <a-radio-group v-decorator="['isRelease', { rules: [{ required: true, message: '请选择是否发布' }] }]">
  94. <a-radio value="0">
  95. 仅存稿
  96. </a-radio>
  97. <a-radio value="1">
  98. 发布
  99. </a-radio>
  100. </a-radio-group>
  101. </a-form-item>
  102. </a-col>
  103. </a-row> -->
  104. <!-- 公告富文本 -->
  105. <a-row :gutter="24">
  106. <a-col :span="12">
  107. <a-form-item label="公告内容:"></a-form-item>
  108. </a-col>
  109. <a-col :span="24">
  110. <JEditor ref="JEditor" :value="smallText" style="margin:0 170px 0 130px;"></JEditor>
  111. </a-col>
  112. </a-row>
  113. </a-form>
  114. </a-spin>
  115. </a-modal>
  116. </template>
  117. <script>
  118. import moment from 'moment'
  119. import 'moment/locale/zh-cn'
  120. import JEditor from '@/components/jeecg/JEditor'
  121. import { enterpriseEAdd, enterpriseEUpdate } from '@api/oa/cd-enterprise-announcement'
  122. export default {
  123. name: 'AddAnnModal',
  124. components: {
  125. JEditor // 富文本组件
  126. },
  127. data () {
  128. return {
  129. addAnnForm: this.$form.createForm(this),
  130. confirmLoading: false,
  131. addModalVisible: false,
  132. smallText: '', // 弹框内 富文本的内容
  133. annInfo: {}, // 表单数据(回显)
  134. title: ''
  135. }
  136. },
  137. // 接收父组件查询公告的方法
  138. props: {
  139. fatherGetList: {
  140. type: Function,
  141. default: null
  142. }
  143. },
  144. created () {},
  145. methods: {
  146. // 回显表单
  147. getAnnFormInfo (e) {
  148. this.$nextTick(() => {
  149. // 判断是否回显(创建人、创建日期)
  150. if (this.title == '新增馆内公告') {
  151. this.addAnnForm.setFieldsValue({
  152. title: this.annInfo.title,
  153. type: this.annInfo.type,
  154. isRelease: this.annInfo.isRelease
  155. })
  156. } else {
  157. this.addAnnForm.setFieldsValue({
  158. title: this.annInfo.title,
  159. type: this.annInfo.type,
  160. isRelease: this.annInfo.isRelease,
  161. // --编辑 回显时间
  162. createBy: this.annInfo.createBy,
  163. createTime: moment(this.annInfo.createTime, 'YYYY-MM-DD HH:mm:ss')
  164. })
  165. }
  166. this.$refs.JEditor.myValue = this.annInfo.content
  167. })
  168. },
  169. // 弹框 保存
  170. handleOk () {
  171. this.addAnnForm.validateFields((err, vals) => {
  172. if (!err && this.$refs.JEditor.myValue !== '') {
  173. console.log('>>>>>>', vals)
  174. var news = {}
  175. news.title = vals.title
  176. news.type = vals.type
  177. news.createBy = vals.createBy
  178. news.isRelease = vals.isRelease
  179. news.content = this.$refs.JEditor.myValue
  180. // 编辑--------------------------------------
  181. if (this.annInfo.id) {
  182. news.id = this.annInfo.id
  183. console.log('这是修改')
  184. enterpriseEUpdate(news).then(res => {
  185. if (res.success) {
  186. this.$message.success('修改成功')
  187. this.addModalVisible = false
  188. this.addAnnForm.resetFields() // 清空表单
  189. this.$refs.JEditor.myValue = '' // 清空富文本
  190. this.fatherGetList() // 调用父组件的查询方法
  191. }
  192. })
  193. } else {
  194. // 新增--------------------------------------
  195. enterpriseEAdd(news).then(res => {
  196. if (res.success) {
  197. // console.log(res)
  198. this.addModalVisible = false
  199. this.$message.success('新增成功')
  200. this.addAnnForm.resetFields() // 清空
  201. this.$refs.JEditor.myValue = '' // 清空富文本
  202. this.fatherGetList()
  203. }
  204. })
  205. }
  206. } else {
  207. this.addAnnForm.resetFields() // 清空表单
  208. this.$refs.JEditor.myValue = '' // 清空富文
  209. this.$message.error('请填写馆内公告必要信息')
  210. }
  211. })
  212. },
  213. handleCancel () {
  214. this.$emit('close')
  215. this.visible = false
  216. this.$refs.JEditor.myValue = '' // 清空富文
  217. this.addAnnForm.resetFields() // 清空表单
  218. },
  219. createTimeChange (value, dateString) {
  220. console.log('选择的时间:', value)
  221. console.log('格式化选择的时间:', dateString)
  222. },
  223. createTimeOk (value) {
  224. console.log('createTimeOk:', value)
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="less" scoped>
  230. @import '~@assets/less/common.less';
  231. </style>