33e588a2c1cc2d30472c4c38ae021ebee0c4a1e2.svn-base 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <el-form-item label="排序">
  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 }}12
  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.Comment,
  44. children: [{
  45. value: 'desc',
  46. label: '降序'
  47. }, {
  48. value: 'asc',
  49. label: '正序'
  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. console.log("cols", cols)
  66. this.orderByStrs.forEach((orderByStr, index) => {
  67. console.log('orderByStr', orderByStr)
  68. const colName = orderByStr.split(' ')[0]
  69. console.log('colName', colName)
  70. if (!cols.findIndex(col => col.Column === colName)) {
  71. this.orderByStrs.splice(index, 1)
  72. }
  73. })
  74. },
  75. handleOrderByChange(value) {
  76. console.log('handleOrderByChange:', value)
  77. this.orderBy = []
  78. const index = this.orderByStrs.findIndex(orderBy => orderBy.indexOf(value[0]) >= 0)
  79. if (index >= 0) {
  80. this.orderByStrs.splice(index, 1, `${value[0]} ${value[1]}`)
  81. } else {
  82. this.orderByStrs.push(`${value[0]} ${value[1]}`)
  83. }
  84. console.log('handleOrderByChange:', value)
  85. console.log('this.orderByStrs', this.orderByStrs)
  86. },
  87. handleCloseOrderBy(value) {
  88. this.orderByStrs.splice(this.orderByStrs.indexOf(value), 1)
  89. }
  90. }
  91. }
  92. </script>