8fd04d706daa211d48eb1e4e0bad5a944d60d66a.svn-base 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <el-form-item :label="$t('chart.order')">
  3. <draggable v-model="orderByStrs" :group="{name: 'orderBy',pull: false, put: false}" style="display: inline-block;">
  4. <el-tag v-for="(item,index) in orderByStrs" :key="index" closable size="small" @close="handleCloseOrderBy">
  5. {{ item }}
  6. </el-tag>
  7. </draggable>
  8. <el-cascader v-model="orderBy" :options="orderByOption" :disabled="orderByOption.length===0" size="mini" :placeholder="$t('chart.selectOrderBy')" style="width: 150px;" @change="handleOrderByChange" />
  9. </el-form-item>
  10. </template>
  11. <script>
  12. import draggable from 'vuedraggable'
  13. import store from '../store'
  14. export default {
  15. components: { draggable },
  16. props: {
  17. value: {
  18. required: true,
  19. type: Array
  20. }
  21. },
  22. data() {
  23. return {
  24. orderBy: []
  25. }
  26. },
  27. computed: {
  28. allSelected() {
  29. return store.state.caculCols.concat(store.state.dimensions)
  30. },
  31. orderByStrs: {
  32. set(value) {
  33. this.$emit('input', value)
  34. },
  35. get() {
  36. return this.value
  37. }
  38. },
  39. orderByOption() {
  40. return this.allSelected.map(col => {
  41. return {
  42. value: col.Column,
  43. label: col.Column,
  44. children: [{
  45. value: 'desc',
  46. label: this.$t('chart.descend')
  47. }, {
  48. value: 'asc',
  49. label: this.$t('chart.ascend')
  50. }]
  51. }
  52. })
  53. }
  54. },
  55. watch: {
  56. 'store.state.dimensions': function(value) {
  57. this.watchHandler(value)
  58. },
  59. 'store.state.caculCols': function(value) {
  60. this.watchHandler(value)
  61. }
  62. },
  63. methods: {
  64. watchHandler(cols) {
  65. this.orderByStrs.forEach((orderByStr, index) => {
  66. const colName = orderByStr.split(' ')[0]
  67. if (!cols.findIndex(col => col.Column === colName)) {
  68. this.orderByStrs.splice(index, 1)
  69. }
  70. })
  71. },
  72. handleOrderByChange(value) {
  73. this.orderBy = []
  74. const index = this.orderByStrs.findIndex(orderBy => orderBy.indexOf(value[0]) >= 0)
  75. if (index >= 0) {
  76. this.orderByStrs.splice(index, 1, `${value[0]} ${value[1]}`)
  77. } else {
  78. this.orderByStrs.push(`${value[0]} ${value[1]}`)
  79. }
  80. },
  81. handleCloseOrderBy(value) {
  82. this.orderByStrs.splice(this.orderByStrs.indexOf(value), 1)
  83. }
  84. }
  85. }
  86. </script>