createdMonthly.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <el-dialog :show="show" :title="title" :visible.sync="monthly_show" width="60%" class="public_task" @close="$emit('update:show', false)">
  3. <div class="blueStripe" />
  4. <el-form ref="monthly_form" :model="monthly_form" :rules="rules" label-position="left" label-width="80px">
  5. <el-form-item label="标题" prop="title">
  6. <el-input v-model="monthly_form.title" placeholder="请输入" />
  7. </el-form-item>
  8. <el-form-item label="缩略图" prop="thumb">
  9. <el-upload action="http://star.xiaojukeji.com/upload/img.node" list-type="picture-card" :limit="1" :multiple="false" :on-success="handlePictureCardPreview" :on-remove="handleRemove">
  10. <i class="el-icon-plus" />
  11. <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过5MB</div>
  12. </el-upload>
  13. </el-form-item>
  14. <el-form-item label="素材" prop="content">
  15. <el-upload action="http://star.xiaojukeji.com/upload/img.node" list-type="picture-card" :limit="1" :multiple="false" :on-success="handlePictureCardPreviewTow" :on-remove="handleRemoveTow">
  16. <i class="el-icon-plus" />
  17. <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过5MB</div>
  18. </el-upload>
  19. </el-form-item>
  20. </el-form>
  21. <span slot="footer" class="dialog-footer">
  22. <el-button @click="monthly_show = false">取 消</el-button>
  23. <el-button type="primary" @click="monthly_dialog">创 建</el-button>
  24. </span>
  25. </el-dialog>
  26. </template>
  27. <script>
  28. export default {
  29. props: {
  30. show: { type: Boolean, default: false },
  31. title: { type: String, required: true }
  32. },
  33. data() {
  34. return {
  35. monthly_show: this.show,
  36. monthly_form: {},
  37. rules: {
  38. title: [{ required: true, message: '标题不能为空', trigger: 'change' }],
  39. thumb: [{ required: true, message: '缩略图不能为空', trigger: 'change' }],
  40. content: [{ required: true, message: '素材不能为空', trigger: 'change' }]
  41. }
  42. }
  43. },
  44. watch: {
  45. show: {
  46. handler(newV) {
  47. this.monthly_show = newV
  48. },
  49. immediate: true
  50. }
  51. },
  52. methods: {
  53. monthly_dialog() {
  54. this.$refs.monthly_form.validate((valid) => {
  55. if (valid) {
  56. this.$emit('monthly_created', this.monthly_form)
  57. this.$emit('update:show', false)
  58. }
  59. })
  60. },
  61. handleClose(done) {
  62. this.monthly_show = false
  63. },
  64. handleRemoveTow(file, fileList) {
  65. if (fileList.length === 0) {
  66. this.kfFormRules.content = [{ required: true, message: '素材不能为空', trigger: 'change' }]
  67. }
  68. },
  69. handlePictureCardPreviewTow(file) {
  70. this.monthly_form.content = 'http:' + file.url
  71. this.$refs.monthly_form.clearValidate('content')
  72. },
  73. handleRemove(file, fileList) {
  74. if (fileList.length === 0) {
  75. this.kfFormRules.thumb = [{ required: true, message: '缩略图不能为空', trigger: 'change' }]
  76. }
  77. },
  78. handlePictureCardPreview(file) {
  79. this.monthly_form.thumb = 'http:' + file.url
  80. this.$refs.monthly_form.clearValidate('thumb')
  81. }
  82. }
  83. }
  84. </script>
  85. <style lang="scss" scoped>
  86. .public_task {
  87. /deep/ .el-dialog__title {
  88. line-height: 24px;
  89. font-size: 16px;
  90. color: #303133;
  91. padding-left: 10px;
  92. }
  93. .blueStripe {
  94. width:4px;
  95. height:17px;
  96. background:#409EFF;
  97. border-radius:1px;
  98. position: absolute;
  99. top: 23px;
  100. left: 20px;
  101. }
  102. }
  103. </style>