EditFAQ.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <el-form ref="form" :model="form" label-width="120px">
  3. <el-form-item label="问题">
  4. <el-input v-model="form.question" size="mini"></el-input>
  5. </el-form-item>
  6. <el-form-item label="答案">
  7. <el-input type="textarea" v-model="form.answer" :rows="3" size="mini"></el-input>
  8. </el-form-item>
  9. <el-form-item label="标签状态">
  10. <el-switch v-model="form.status" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" @click="save" size="mini">保存</el-button>
  14. <el-button @click="goBack" size="mini">取消</el-button>
  15. </el-form-item>
  16. </el-form>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. form: {
  23. id: 0,
  24. question: "",
  25. answer: "",
  26. status: true
  27. }
  28. };
  29. },
  30. methods: {
  31. save: function() {
  32. var param = {
  33. id: this.form.id,
  34. question: this.form.question,
  35. answer: this.form.answer,
  36. status: this.form.status ? 1 : 0
  37. };
  38. var that = this;
  39. this.$http.saveFaq(param, this).then(res => {
  40. if (res.code === 0) {
  41. this.$message({
  42. message: "操作成功",
  43. type: "success",
  44. duration: 1000,
  45. onClose: function() {
  46. that.goBack();
  47. }
  48. });
  49. }
  50. });
  51. },
  52. goBack: function() {
  53. this.$router.back();
  54. }
  55. },
  56. mounted: function() {
  57. var id = this.$route.query.id;
  58. this.form.id = id;
  59. if (id === 0) {
  60. return;
  61. }
  62. this.$http.geFaq({ id: id }, this).then(res => {
  63. if (res.code === 0) {
  64. this.form.question = res.obj.question;
  65. this.form.answer = res.obj.answer;
  66. this.form.status = res.obj.status === 1;
  67. }
  68. });
  69. }
  70. };
  71. </script>
  72. <style scoped>
  73. .el-form-item {
  74. margin-bottom: 0px;
  75. }
  76. </style>