edbCollectDia.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div class="edbCollectDia-container">
  3. <el-dialog
  4. :visible.sync="show"
  5. :close-on-click-modal="false"
  6. :modal-append-to-body="false"
  7. title="收藏"
  8. @close="cancelHandle"
  9. custom-class="dialog"
  10. center
  11. width="560px"
  12. v-dialogDrag
  13. >
  14. <div class="dialog-min">
  15. <div class="classify-cont">
  16. <el-tag
  17. v-for="item in classifyArr"
  18. :class="['classify-tag',{'act': checkedClassifys.includes(item.ClassifyId)}]"
  19. :key="item.ClassifyId"
  20. type="info"
  21. effect="plain"
  22. @click="chooseClassify(item.ClassifyId)"
  23. >
  24. {{ item.ClassifyName }}
  25. </el-tag>
  26. </div>
  27. <div class="add-cont" @click="$parent.handleOpenCollectClassify">
  28. <i class="el-icon-circle-plus-outline" />新增
  29. </div>
  30. <p>提示:收藏后的指标,请在{{collectPath}}查看</p>
  31. </div>
  32. <div class="dia-bot">
  33. <el-button type="primary" style="margin-right: 20px" plain @click="cancelHandle">{{$t('Dialog.cancel_btn')}}</el-button>
  34. <el-button type="primary" @click="saveHandle"
  35. >{{$t('Dialog.confirm_save_btn')}}</el-button
  36. >
  37. </div>
  38. </el-dialog>
  39. </div>
  40. </template>
  41. <script>
  42. import { edbCollectInterface,chartBaseV2Interface } from '@/api/modules/chartApi'
  43. export default {
  44. name:'',
  45. props: {
  46. show: {
  47. type: Boolean,
  48. },
  49. id: {
  50. type: Number,
  51. },
  52. add_ids: {
  53. type: Array,
  54. default: []
  55. },
  56. source: { //指标或图库 edb chart
  57. type: String,
  58. default: 'edb'
  59. },
  60. },
  61. computed: {
  62. collectPath() {
  63. return this.source === 'edb' ? '指标加工/我的指标/收藏指标' : '图库/我的图表/收藏图表'
  64. }
  65. },
  66. watch: {
  67. show(newval) {
  68. if(newval) {
  69. this.getClassify();
  70. }
  71. }
  72. },
  73. data () {
  74. return {
  75. classifyArr:[],//分类列表
  76. checkedClassifys: [],
  77. addRules: {
  78. name:[
  79. { required: true, message: /* '分类名称不能为空' */this.$t('Chart.Vailds.classify_msg'), trigger: 'blur' },
  80. ],
  81. }
  82. };
  83. },
  84. methods: {
  85. /* 获取分类列表 */
  86. async getClassify() {
  87. const res = this.source ==='edb'
  88. ? await edbCollectInterface.getEdbCollectClassifyOne()
  89. : await chartBaseV2Interface.getChartCollectClassifyOne();
  90. if(res.Ret !== 200) return
  91. this.classifyArr = res.Data || [];
  92. this.checkedClassifys = _.cloneDeep(this.add_ids);
  93. },
  94. chooseClassify(id) {
  95. if(this.checkedClassifys.includes(id)) {
  96. let index = this.checkedClassifys.indexOf(id);
  97. this.checkedClassifys.splice(index, 1);
  98. }else {
  99. this.checkedClassifys.push(id);
  100. }
  101. },
  102. /* 加入收藏 */
  103. async saveHandle() {
  104. if(!this.checkedClassifys.length) return this.$message.warning('请选择分类');
  105. const res = this.source === 'edb'
  106. ? await edbCollectInterface.edbCollect({
  107. EdbInfoId: this.id,
  108. ClassifyIdList: this.checkedClassifys
  109. })
  110. : await chartBaseV2Interface.chartCollect({
  111. ChartInfoId: this.id,
  112. ClassifyIdList: this.checkedClassifys
  113. })
  114. if(res.Ret !== 200) return
  115. this.$message.success('收藏成功')
  116. this.$emit('confirm',this.checkedClassifys);
  117. this.cancelHandle();
  118. },
  119. cancelHandle() {
  120. this.checkedClassifys = [];
  121. this.$emit('update:show')
  122. }
  123. },
  124. }
  125. </script>
  126. <style lang="scss">
  127. .edbCollectDia-container {
  128. .el-dialog--center .el-dialog__body {
  129. padding: 25px 25px 30px !important;
  130. }
  131. .dialog-min {
  132. .classify-cont {
  133. padding: 30px 10px;
  134. border: 1px dashed #999;
  135. display: flex;
  136. flex-wrap: wrap;
  137. margin-bottom: 20px;
  138. .classify-tag {
  139. margin: 5px;
  140. padding: 0 20px;
  141. cursor: pointer;
  142. &.act {
  143. background: #0052D9;
  144. color: #fff;
  145. }
  146. }
  147. }
  148. .add-cont {
  149. color: #0052D9;
  150. cursor: pointer;
  151. margin-bottom: 10px;
  152. }
  153. }
  154. .dia-bot {
  155. margin: 52px 0 30px;
  156. display: flex;
  157. justify-content: center;
  158. }
  159. }
  160. </style>