GoodLabelManage.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div>
  3. <div class="old">
  4. <el-tag
  5. class="tag"
  6. v-for="(oit, oindex) in oldLabels"
  7. :key="oit.id"
  8. closable
  9. type="success"
  10. size="medium"
  11. @close="removeOldLabel(oindex)"
  12. >{{oit.name}}</el-tag>
  13. </div>
  14. <div class="new">
  15. <el-button
  16. type="danger"
  17. plain
  18. v-for="(nit, nindex) in newLabels"
  19. :key="nit.id"
  20. v-on:click="add(nindex)"
  21. size="mini"
  22. >{{nit.name}}</el-button>
  23. </div>
  24. <div class="option">
  25. <el-button type="primary" @click="save" size="mini">保存</el-button>
  26. <el-button @click="goBack" size="mini">取消</el-button>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. gid: 0,
  35. oldLabels: [],
  36. newLabels: []
  37. };
  38. },
  39. methods: {
  40. getOldGoodLabels: function() {
  41. this.$http.getGoodLabels({ gid: this.gid }, this).then(res => {
  42. if (res.code === 0) {
  43. this.oldLabels = res.obj;
  44. }
  45. });
  46. },
  47. getNewGoodLabels: function() {
  48. this.$http.okLabels({}, this).then(res => {
  49. this.newLabels = res.obj;
  50. });
  51. },
  52. removeOldLabel: function(index) {
  53. this.oldLabels.splice(index, 1);
  54. },
  55. goBack: function() {
  56. this.$router.back();
  57. },
  58. add: function(index) {
  59. var item = this.newLabels[index];
  60. var have = false;
  61. this.oldLabels.forEach(it => {
  62. if (it.id === item.id) {
  63. have = true;
  64. }
  65. });
  66. if (!have) {
  67. this.oldLabels.push({ id: item.id, name: item.name });
  68. }
  69. },
  70. save: function() {
  71. var lids = [];
  72. this.oldLabels.forEach(it => {
  73. lids.push(it.id);
  74. });
  75. var that = this;
  76. this.$http
  77. .setGoodLabels({ gid: this.gid, lids: lids }, this)
  78. .then(res => {
  79. this.$message({
  80. message: "操作成功",
  81. type: "success",
  82. duration: 1000,
  83. onClose: function() {
  84. that.goBack();
  85. }
  86. });
  87. });
  88. }
  89. },
  90. mounted() {
  91. var gid = this.$route.query.gid;
  92. this.gid = gid;
  93. this.getOldGoodLabels();
  94. this.getNewGoodLabels();
  95. }
  96. };
  97. </script>
  98. <style scoped>
  99. .old {
  100. min-height: 45px;
  101. }
  102. .new {
  103. border-top: 1px solid #E6E6E6;
  104. padding-top: 20px;
  105. min-height: 45px;
  106. }
  107. .tag {
  108. margin-right: 10px;
  109. }
  110. .option {
  111. border-top: 1px solid #E6E6E6;
  112. padding-top: 20px;
  113. }
  114. </style>