addNotice.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div>
  3. <div class="notice-add">
  4. <div class="notice-add-box">
  5. <el-form ref="form" :model="notice" :rules="rules" label-width="90px" id="selectForm">
  6. <el-form-item label="公告名称:" size="mini" prop="noticeTitle">
  7. <el-input v-model="notice.noticeTitle" placeholder="请输入公告名称" style="width: 510px"></el-input>
  8. </el-form-item>
  9. <el-form-item label="发布时间:" required>
  10. <el-col :span="11">
  11. <el-form-item prop="date1">
  12. <el-date-picker type="date" placeholder="选择日期" v-model="notice.date1" style="width: 100%;"></el-date-picker>
  13. </el-form-item>
  14. </el-col>
  15. <el-col class="line" :span="1.5">-</el-col>
  16. <el-col :span="11">
  17. <el-form-item prop="date2">
  18. <el-time-picker placeholder="选择时间" v-model="notice.date2" style="width: 100%;"></el-time-picker>
  19. </el-form-item>
  20. </el-col>
  21. </el-form-item>
  22. <el-form-item label="公告内容:" prop="content">
  23. <editor v-model="notice.content" :min-height="192"/>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" @click="submitForm('form')">提交</el-button>
  27. <el-button @click="resetForm('form')">重置</el-button>
  28. </el-form-item>
  29. </el-form>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import { submitNotice } from '../../api/notice/notice.js'
  36. export default {
  37. data() {
  38. return {
  39. notice: {
  40. noticeTitle: '',
  41. date1:'',
  42. date2:'',
  43. content:"",
  44. cnt:1
  45. },
  46. rules: {
  47. noticeTitle: [{ required: true, message: "请输入公告名称", trigger: "blur" }],
  48. date1: [{ type: 'date', required: true, message: '请选择日期', trigger: 'change' }],
  49. date2: [{ type: 'date', required: true, message: '请选择时间', trigger: 'change' }],
  50. content: [{ required: true, message: "请输入公告内容", trigger: "blur" }],
  51. },
  52. }
  53. },
  54. mounted() {
  55. console.log( "-****" , this.notice.noticeTitle);
  56. console.log( "-****" , this.notice.date1);
  57. console.log( "-****" , this.notice.date2);
  58. console.log( "-****" , this.notice.content);
  59. },
  60. methods: {
  61. change(){
  62. console.log(1);
  63. this.cnt = this.cnt+ 1
  64. console.log(this.cnt);
  65. },
  66. onEditorChange() {
  67. //内容改变事件
  68. this.$emit("input", this.content);
  69. },
  70. submitForm(formName) {
  71. console.log( "-****title" , this.notice.noticeTitle);
  72. console.log( "-****date1" , this.notice.date1);
  73. console.log( "-****date2" , this.notice.date2);
  74. console.log( "-****content" , this.notice.content);
  75. // console.log( "lxzhen-****content" , this.content);
  76. var dateTime = this.notice.date1;
  77. function add0(m){return m<10?'0'+m:m }
  78. function format(shijianchuo)
  79. {
  80. var time = new Date(shijianchuo);
  81. var y = time.getFullYear();
  82. var m = time.getMonth()+1;
  83. var d = time.getDate()+1;
  84. var h = time.getHours()+1;
  85. var mm = time.getMinutes()+1;
  86. var s = time.getSeconds()+1;
  87. return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
  88. }
  89. var date = format(dateTime);
  90. console.log(date);
  91. this.$refs[formName].validate((valid) => {
  92. if (valid) {
  93. // alert('submit!');
  94. submitNotice({
  95. newsTitle:this.notice.noticeTitle,
  96. newsContent:this.notice.content,
  97. createTime:'1994-12-01 12:22:33',
  98. updateTime:'1994-12-01 12:22:33',
  99. })
  100. .then((res) => {
  101. console.log(res);
  102. // 添加成功
  103. this.$notice({
  104. notice:"公告添加成功!",
  105. type:"success",
  106. });
  107. this.$refs[notice].resetFields();//添加成功后清空
  108. this.$router.push('/notice/noticeList')//跳转
  109. })
  110. // 失败
  111. .catch((err) => {
  112. console.log(err);
  113. });
  114. } else {
  115. console.log('error submit!!');
  116. return false;
  117. }
  118. });
  119. },
  120. resetForm(formName) {
  121. this.$refs[formName].resetFields();
  122. },
  123. }
  124. };
  125. </script>
  126. <style scoped>
  127. .notice-add {
  128. width: 750px;
  129. height: 100%;
  130. position: absolute;
  131. top: 75px;
  132. bottom: 0;
  133. left: 0;
  134. right: 0;
  135. margin: auto;
  136. border: 1px solid #ccc;
  137. border-radius: 5px;
  138. }
  139. .notice-add-box {
  140. width: 100%;
  141. height: 100%;
  142. padding: 35px;
  143. }
  144. /* 调节form表单中label的字体大小 */
  145. #selectForm >>> .el-form-item__label {
  146. font-size: 12px;
  147. color: #808080;
  148. }
  149. .quill-editor /deep/ .ql-container {
  150. min-height: 220px;
  151. }
  152. .ql-container {
  153. min-height: 230px;
  154. }
  155. .ql-toolbar.ql-snow {
  156. border: 1px solid #ccc;
  157. -webkit-box-sizing: border-box;
  158. box-sizing: border-box;
  159. font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
  160. padding: 8px;
  161. width: 450px;
  162. }
  163. .ql-toolbar.ql-snow + .ql-container.ql-snow {
  164. border-top: 0px;
  165. width: 450px;
  166. }
  167. </style>