reportDetailed.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <el-dialog
  3. :title="id==null ? '新增' : '编辑'"
  4. width="520px"
  5. :visible="visible"
  6. :keyboard="false"
  7. @close="handleCancel"
  8. :show-close="false"
  9. @open="init"
  10. >
  11. <el-form :model="dataForm" label-width="120px" ref="form">
  12. <el-form-item label="标题" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }" prop="title">
  13. <el-input v-model="dataForm.title" />
  14. </el-form-item>
  15. <el-form-item label="内容" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }" prop="content">
  16. <el-input v-model="dataForm.content" />
  17. </el-form-item>
  18. </el-form>
  19. <template slot="footer">
  20. <el-button @click="visible = false">取消</el-button>
  21. <el-button type="primary" @click="dataFormSubmitHandle()">保存</el-button>
  22. </template>
  23. </el-dialog>
  24. </template>
  25. <script>
  26. import { reportDe, reportSave, reportPut } from "@/api/report";
  27. export default {
  28. name: "reportDe",
  29. props: {
  30. visible: {
  31. default: false,
  32. type: Boolean
  33. },
  34. id: {
  35. default: null,
  36. type: Number
  37. }
  38. },
  39. data() {
  40. return {
  41. dataForm: {
  42. title: "",
  43. content: ""
  44. }
  45. };
  46. },
  47. methods: {
  48. //关闭模态框
  49. handleCancel() {
  50. console.log("关闭弹窗");
  51. this.visible = false;
  52. // 退出弹窗需要清空对象,否则新增时会有上次编辑的数据
  53. this.dataForm = {
  54. title: "",
  55. content: ""
  56. };
  57. this.$emit("deClose", {});
  58. },
  59. // form提交按钮触发,根据是否有id决定是新增api还是保存api
  60. dataFormSubmitHandle() {
  61. console.log("试图保存");
  62. console.log(this.id);
  63. if (this.id == null) {
  64. reportSave(this.dataForm).then(res => {
  65. console.log("新增成功:");
  66. console.log(res);
  67. this.$message({
  68. message: "新增成功",
  69. type: "success"
  70. });
  71. this.handleCancel();
  72. this.$emit("getReport", {});
  73. });
  74. } else {
  75. reportPut(this.id, this.dataForm).then(res => {
  76. console.log("更新成功");
  77. this.$message({
  78. message: "更新成功",
  79. type: "success"
  80. });
  81. this.handleCancel();
  82. this.$emit("getReport", {});
  83. });
  84. }
  85. },
  86. // 弹窗组件自动触发,决定是否需要请求某个具体的日报内容
  87. init() {
  88. console.log("init:" + this.id);
  89. if (this.id == null) {
  90. return;
  91. }
  92. reportDe(this.id).then(res => {
  93. this.dataForm.title = res.data.title;
  94. this.dataForm.content = res.data.content;
  95. });
  96. }
  97. }
  98. };
  99. </script>