edit.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="cmain">
  3. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  4. <el-form-item label="新闻标题" prop="title">
  5. <el-input v-model="form.title" placeholder="请输入标题"></el-input>
  6. </el-form-item>
  7. <el-row>
  8. <el-col :span="12">
  9. <el-form-item label="新闻类型" prop="type">
  10. <el-select v-model="form.type" placeholder="请选择" style="width: 100%">
  11. <el-option v-for="item in typeList" :key="item.value + 'typeList'" :label="item.label" :value="item.value"></el-option>
  12. </el-select>
  13. </el-form-item>
  14. </el-col>
  15. <el-col :span="12">
  16. <el-form-item label="新闻来源">
  17. <el-input v-model="form.source" placeholder="请输入来源"></el-input>
  18. </el-form-item>
  19. </el-col>
  20. </el-row>
  21. <el-form-item label="新闻封面">
  22. <cropper v-model="form.picture" :fixed_number="[4, 2]"></cropper>
  23. </el-form-item>
  24. <el-form-item label="新闻内容" prop="content">
  25. <editor v-model="form.content" />
  26. </el-form-item>
  27. </el-form>
  28. <div class="mfooter">
  29. <el-button type="primary" @click="submitForm">确 定</el-button>
  30. <el-button @click="$layer.close(layerid)">取 消</el-button>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import { listNEWS, getNEWS, delNEWS, addNEWS, updateNEWS, upload, setTop, newCommit, updateAndex, downloadpic } from '@/api/portal/news/NEWS.js';
  36. export default {
  37. data() {
  38. return {
  39. typeList: [
  40. { label: '要闻动态', value: 1 },
  41. { label: '政策法规', value: 2 },
  42. { label: '通知公告', value: 3 },
  43. { label: '政策解读', value: 4 },
  44. { label: '投资导航', value: 5 }
  45. ],
  46. form: {type:2},
  47. rules: {
  48. title: [{ required: true, message: '标题不能为空', trigger: 'blur' }],
  49. content: [{ required: true, message: '内容不能为空', trigger: 'blur' }],
  50. fileUrl: [{ required: true, message: '附件不能为空', trigger: 'blur' }],
  51. type: [{ required: true, message: '类型不能为空', trigger: 'change' }],
  52. typeName: [{ required: true, message: '字典类型名称不能为空', trigger: 'blur' }],
  53. picture: [{ required: true, message: '图片不能为空', trigger: 'blur' }],
  54. status: [{ required: true, message: '状态(0.草稿,1.下架,2.审核中,3.审核驳回,4.已发布,5.已上报)不能为空', trigger: 'blur' }]
  55. }
  56. };
  57. },
  58. props: {
  59. param: {
  60. type: Object,
  61. default: () => {
  62. return {};
  63. }
  64. },
  65. layerid: {
  66. type: String
  67. }
  68. },
  69. mounted() {
  70. console.log('asd:' + this.param.type);
  71. if (this.param.type) {
  72. this.form.type =parseInt(this.param.type);
  73. }
  74. if (this.param.id) {
  75. getNEWS(this.param.id).then(response => {
  76. this.form = response.data;
  77. this.form.type=parseInt(this.form.type);
  78. this.form.content = response.data.content.replace(new RegExp('/profile/upload/', 'g'), this.baseUrl + '/profile/upload/');
  79. });
  80. }
  81. },
  82. methods: {
  83. /** 提交按钮 */
  84. submitForm() {
  85. this.$refs['form'].validate(valid => {
  86. if (valid) {
  87. if (this.form.id != null) {
  88. updateAndex(this.form).then(response => {
  89. this.$modal.msgSuccess('修改成功');
  90. this.$layer.close(this.layerid);
  91. this.$parent.getList();
  92. });
  93. } else {
  94. this.form.status = '1';
  95. addNEWS(this.form).then(response => {
  96. this.$modal.msgSuccess('新增成功');
  97. this.$layer.close(this.layerid);
  98. this.$parent.getList();
  99. });
  100. }
  101. }
  102. });
  103. }
  104. }
  105. };
  106. </script>