edit.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php defined('YII_ENV') or exit('Access Denied'); ?>
  2. <style>
  3. .form-body {
  4. padding: 20px 0;
  5. background-color: #fff;
  6. margin-bottom: 20px;
  7. padding-right: 50%;
  8. }
  9. .form-button {
  10. margin: 0!important;
  11. }
  12. .form-button .el-form-item__content {
  13. margin-left: 0!important;
  14. }
  15. .button-item {
  16. padding: 9px 25px;
  17. }
  18. .text {
  19. cursor: pointer;
  20. color: #419EFB;
  21. }
  22. </style>
  23. <section id="app" v-cloak>
  24. <el-card class="box-card" shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  25. <div slot="header" class="clearfix">
  26. <div flex="cross:center box:first">
  27. <div><span @click="$navigate({r:'plugin/course/admin/discuss/index'})" class="text">评论管理</span>/评论编辑</div>
  28. </div>
  29. </div>
  30. <div class="form-body" >
  31. <el-form :model="ruleForm" label-width="80px" v-loading="loading" :rules="formRules" ref="ruleForm">
  32. <el-form-item label="选择课程" prop="cid">
  33. <el-select style="width: 100%" v-model="ruleForm.cid" placeholder="请选择">
  34. <el-option
  35. v-for="item in course_info"
  36. :key="item.id"
  37. :label="item.name"
  38. :value="item.id"
  39. :disabled="item.disabled">
  40. </el-option>
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item label="评论内容" prop="content">
  44. <el-input type="textarea" :rows="2" placeholder="请输入评论内容" v-model="ruleForm.content"> </el-input>
  45. </el-form-item>
  46. <el-form-item label="选择评分" prop="score">
  47. <el-rate v-model="ruleForm.score" show-text :max = 5 :texts = score_text style="margin-top:10px;"> </el-rate>
  48. </el-form-item>
  49. <el-form-item label="是否匿名" prop="is_anonymous">
  50. <el-switch v-model="ruleForm.is_anonymous" :active-value="0" :inactive-value="1" active-text="不匿名" inactive-text="匿名" >
  51. </el-switch>
  52. </el-form-item>
  53. <div flex="dir:right">
  54. <div>
  55. <el-button class="button-item" type="primary" size="small" :loading=btnLoading @click="submit('ruleForm')">提交</el-button>
  56. </div>
  57. </div>
  58. </el-form>
  59. </div>
  60. </el-card>
  61. </section>
  62. <script>
  63. const app = new Vue({
  64. el: '#app',
  65. data() {
  66. return {
  67. form: {},
  68. loading: false,
  69. btnLoading: false,
  70. score_text: ['一星', '两星', '三星', '四星', '五星'],
  71. course_info: {
  72. id: '',
  73. name:''
  74. },
  75. star_list:[
  76. {name:'一星',value:1},
  77. {name:'二星',value:2},
  78. {name:'三星',value:3},
  79. {name:'四星',value:4},
  80. {name:'五星',value:5}
  81. ],
  82. ruleForm: {
  83. id: null,
  84. cid: null, // 课程id
  85. score: null,
  86. content: ''
  87. },
  88. formRules: {
  89. cid: [ { required: true, message: '请选择课程', trigger: 'blur' } ],
  90. score: [ { required: true, message: '请选择评分值', trigger: 'blur' } ],
  91. content: [{ required: true, pattern:/\S/, message: '请填写评论内容', trigger: 'blur' }]
  92. },
  93. };
  94. },
  95. methods: {
  96. submit(formName) {
  97. this.$refs[formName].validate((valid, obj) => {
  98. if (valid) {
  99. this.btnLoading = true;
  100. let para = Object.assign(this[formName]);
  101. request({
  102. params: {
  103. r: 'course/discuss/edit',
  104. },
  105. data: para,
  106. method: 'post'
  107. }).then(e => {
  108. this.btnLoading = false;
  109. if (e.data.code == 0) {
  110. this.$message({
  111. message: e.data.msg,
  112. type: 'success'
  113. });
  114. setTimeout(function(){
  115. navigateTo({ r: 'course/discuss/index'});
  116. },300);
  117. } else {
  118. this.$message({
  119. message: e.data.msg,
  120. type: 'error'
  121. });
  122. }
  123. }).catch(e => {
  124. this.btnLoading = false;
  125. this.$alert(e.data.msg, '提示', {
  126. confirmButtonText: '确定'
  127. })
  128. });
  129. } else {
  130. var msg = '';
  131. for (let index in obj) {
  132. msg = msg + '*' + obj[index][0].message + ' ';
  133. }
  134. this.$message({
  135. message: msg,
  136. type: 'error'
  137. });
  138. return false;
  139. }
  140. });
  141. },
  142. getDiscussForm() {
  143. this.loading = true;
  144. let _this = this;
  145. request({
  146. params: {
  147. r: 'course/discuss/edit',
  148. id: getQuery('id'),
  149. },
  150. method: 'get'
  151. }).then(e => {
  152. this.loading = false;
  153. if (e.data.code == 0) {
  154. if(e.data.data.discuss_info!=''){
  155. _this.ruleForm = e.data.data.discuss_info;
  156. }
  157. _this.course_info = e.data.data.course_list;
  158. }
  159. }).catch(e => {
  160. this.loading = false;
  161. this.$alert(e.data.msg, '提示', {
  162. confirmButtonText: '确定'
  163. })
  164. });
  165. },
  166. },
  167. mounted() {
  168. this.getDiscussForm();
  169. }
  170. })
  171. </script>