EditLabel.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <el-form ref="form" :model="form" label-width="120px">
  3. <el-form-item label="标签名称">
  4. <el-input v-model="form.name" size="mini"></el-input>
  5. </el-form-item>
  6. <el-form-item label="顺序号">
  7. <el-input v-model="form.sort" type="number" 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. name: "",
  25. sort: 0,
  26. status: true
  27. },
  28. saveLabel: null,
  29. getLabel: null,
  30. onCloseRouter: null
  31. };
  32. },
  33. methods: {
  34. save: function() {
  35. var that = this;
  36. console.log(this.$http.getNewLabel, this.$http[this.saveLabel], [
  37. this.saveLabel
  38. ]);
  39. this.$http[this.saveLabel](
  40. {
  41. id: this.form.id,
  42. name: this.form.name,
  43. sort: this.form.sort,
  44. status: this.form.status ? 1 : 0
  45. },
  46. this
  47. ).then(res => {
  48. if (res.code === 0) {
  49. const onCloseRouter = this.onCloseRouter;
  50. this.$message({
  51. message: "操作成功",
  52. type: "success",
  53. duration: 1000,
  54. onClose: function() {
  55. that.$router.push(onCloseRouter);
  56. }
  57. });
  58. }
  59. });
  60. },
  61. goBack: function() {
  62. this.$router.back();
  63. }
  64. },
  65. mounted: function() {
  66. console.log(this.$route.query);
  67. const id = this.$route.query.id;
  68. const type = this.$route.query.type;
  69. if (type === "new") {
  70. this.getLabel = "getNewLabel";
  71. this.saveLabel = "saveNewLabel";
  72. this.onCloseRouter = "/newLabelManager";
  73. } else {
  74. this.getLabel = "getLabel";
  75. this.saveLabel = "saveLabel";
  76. this.onCloseRouter = "/sysLabelManager";
  77. }
  78. this.form.id = id;
  79. if (id === 0) {
  80. return;
  81. }
  82. this.$http[this.getLabel]({ id: id }, this).then(res => {
  83. if (res.code === 0) {
  84. this.form.name = res.obj.name;
  85. this.form.status = res.obj.status === 1;
  86. this.form.sort = res.obj.sort;
  87. }
  88. });
  89. }
  90. };
  91. </script>
  92. <style scoped>
  93. .el-form-item {
  94. margin-bottom: 0px;
  95. }
  96. </style>