Edit.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <el-form ref="form" :model="form" label-width="120px">
  3. <el-form-item label="说明">
  4. <el-input v-model="form.rewark" placeholder="请输入说明" size="mini"></el-input>
  5. </el-form-item>
  6. <el-form-item label="数量">
  7. <el-input v-model="form.num" :readonly="numReadonly" placeholder="请输入生成兑换码书里那个" size="mini"></el-input>
  8. </el-form-item>
  9. <el-form-item label="有效期">
  10. <el-date-picker
  11. size="mini"
  12. v-model="form.endtime"
  13. value-format="yyyy-MM-dd"
  14. type="date"
  15. placeholder="选择兑换码有效期"
  16. ></el-date-picker>
  17. </el-form-item>
  18. <el-form-item label="标签状态">
  19. <el-switch v-model="form.status" active-color="#13ce66" inactive-color="#ff4949"></el-switch>
  20. </el-form-item>
  21. <el-form-item>
  22. <el-button type="primary" @click="save" size="mini">保存</el-button>
  23. <el-button @click="goBack" size="mini">取消</el-button>
  24. </el-form-item>
  25. </el-form>
  26. </template>
  27. <script>
  28. import { timeFormater } from "../../../util";
  29. export default {
  30. data() {
  31. return {
  32. form: {
  33. rewark: "",
  34. num: "",
  35. endtime: "",
  36. status: true
  37. },
  38. gid: 0,
  39. eid: 0,
  40. numReadonly: false
  41. };
  42. },
  43. methods: {
  44. save() {
  45. if (this.eid === 0) {
  46. this.add();
  47. } else {
  48. this.update();
  49. }
  50. },
  51. add() {
  52. let that = this;
  53. this.$http
  54. .exchangeCodeCreate(
  55. {
  56. gid: this.gid,
  57. num: this.form.num,
  58. remark: this.form.rewark,
  59. endtime: this.form.endtime
  60. },
  61. this
  62. )
  63. .then(res => {
  64. if (res.code === 0) {
  65. this.$message({
  66. message: "操作成功",
  67. type: "success",
  68. duration: 1000,
  69. onClose: function() {
  70. that.goBack();
  71. }
  72. });
  73. }
  74. });
  75. },
  76. update() {
  77. let that = this;
  78. this.$http
  79. .exchangeCodeUpdate(
  80. {
  81. id: this.eid,
  82. remark: this.form.rewark,
  83. endtime: this.form.endtime,
  84. status: this.form.status ? 1 : 0
  85. },
  86. this
  87. )
  88. .then(res => {
  89. if (res.code === 0) {
  90. this.$message({
  91. message: "操作成功",
  92. type: "success",
  93. duration: 1000,
  94. onClose: function() {
  95. that.goBack();
  96. }
  97. });
  98. }
  99. });
  100. },
  101. goBack() {
  102. this.$router.back();
  103. }
  104. },
  105. mounted: function() {
  106. let queryObj = this.$route.query;
  107. this.gid = queryObj.gid;
  108. this.eid = queryObj.id;
  109. if (this.eid !== 0) {
  110. this.$http.echangeCodeGet({ id: this.eid }, this).then(res => {
  111. if (res.code === 0) {
  112. this.form.rewark = res.obj.remark;
  113. this.form.num = res.obj.num;
  114. this.form.endtime = timeFormater(res.obj.endtime);
  115. this.form.status = res.obj.status === 1;
  116. this.numReadonly = true;
  117. }
  118. });
  119. }
  120. }
  121. };
  122. </script>
  123. <style scoped>
  124. .el-form-item {
  125. margin-bottom: 0px;
  126. }
  127. </style>