74059e8c02fab891484a3093ac43c728c90ab1f1.svn-base 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 }}
  6. </el-tag>
  7. </draggable> -->
  8. <draggable v-model="orderByStrs" :group="{name: 'orderBy',pull: false, put: false}" style="display: inline-block;">
  9. <el-tag v-for="(item,index) in orderByStrs" :key="index" closable size="small" @close="handleCloseOrderBy" style="display:none">
  10. {{ item }}
  11. </el-tag>
  12. <el-tag v-for="(item,index) in orderByStrs1" :key="index" closable size="small" @close="handleCloseOrderBy">
  13. {{ item }}
  14. </el-tag>
  15. </draggable>
  16. <el-cascader v-model="orderBy" :options="orderByOption" :disabled="orderByOption.length===0" size="mini" :placeholder="$t('chart.selectOrderBy')" style="width: 150px;" @change="handleOrderByChange" />
  17. </el-form-item>
  18. </template>
  19. <script>
  20. import draggable from 'vuedraggable'
  21. import store from '../store'
  22. export default {
  23. components: { draggable },
  24. props: {
  25. value: {
  26. required: true,
  27. type: Array
  28. }
  29. },
  30. data() {
  31. return {
  32. orderBy: [],
  33. orderBy1: [],
  34. orderByStrs1: []
  35. }
  36. },
  37. computed: {
  38. allSelected() {
  39. return store.state.caculCols.concat(store.state.dimensions)
  40. },
  41. orderByStrs: {
  42. set(value) {
  43. this.$emit('input', value)
  44. },
  45. get() {
  46. return this.value
  47. }
  48. },
  49. orderByOption() {
  50. return this.allSelected.map(col => {
  51. return {
  52. value: col.Column,
  53. label: col.Comment,
  54. children: [{
  55. value: 'desc',
  56. label: '降序'
  57. }, {
  58. value: 'asc',
  59. label: '正序'
  60. }]
  61. }
  62. })
  63. }
  64. },
  65. watch: {
  66. 'store.state.dimensions': function (value) {
  67. this.watchHandler(value)
  68. },
  69. 'store.state.caculCols': function (value) {
  70. this.watchHandler(value)
  71. }
  72. },
  73. methods: {
  74. watchHandler(cols) {
  75. console.log("cols", cols)
  76. this.orderByStrs.forEach((orderByStr, index) => {
  77. console.log('orderByStr', orderByStr)
  78. const colName = orderByStr.split(' ')[0]
  79. console.log('colName', colName)
  80. if (!cols.findIndex(col => col.Column === colName)) {
  81. this.orderByStrs.splice(index, 1)
  82. }
  83. })
  84. },
  85. // handleOrderByChange(value) {
  86. // console.log('handleOrderByChange:', value)
  87. // this.orderBy = []
  88. // const index = this.orderByStrs.findIndex(orderBy => orderBy.indexOf(value[0]) >= 0)
  89. // if (index >= 0) {
  90. // this.orderByStrs.splice(index, 1, `${value[0]} ${value[1]}`)
  91. // } else {
  92. // this.orderByStrs.push(`${value[0]} ${value[1]}`)
  93. // }
  94. // console.log('handleOrderByChange:', value)
  95. // console.log('this.orderByStrs', this.orderByStrs)
  96. // },
  97. handleOrderByChange(value) {
  98. console.log('handleOrderByChange:', value)
  99. console.log('orderBy:', this.orderBy)
  100. console.log('orderByOption:', this.orderByOption)
  101. var china_value = ""
  102. this.orderByOption.forEach(function (i, j) {
  103. if (i.value == value[0]) {
  104. china_value = i.label
  105. }
  106. })
  107. console.log('china_value:', china_value)
  108. this.orderBy = []
  109. const index = this.orderByStrs.findIndex(orderBy => orderBy.indexOf(value[0]) >= 0)
  110. if (index >= 0) {
  111. this.orderByStrs.splice(index, 1, `${value[0]} ${value[1]}`)
  112. } else {
  113. this.orderByStrs.push(`${value[0]} ${value[1]}`)
  114. }
  115. this.orderBy1 = []
  116. if (value[1] == 'desc') {
  117. var sort = '降序'
  118. } else {
  119. var sort = '正序'
  120. }
  121. const index1 = this.orderByStrs1.findIndex(orderBy1 => orderBy1.indexOf(china_value) >= 0)
  122. if (index1 >= 0) {
  123. this.orderByStrs1.splice(index1, 1, `${china_value} ${sort}`)
  124. } else {
  125. this.orderByStrs1.push(`${china_value} ${sort}`)
  126. }
  127. console.log('handleOrderByChange:', value)
  128. console.log('this.orderByStrs', this.orderByStrs)
  129. console.log('this.orderByStrs1', this.orderByStrs1)
  130. },
  131. handleCloseOrderBy(value) {
  132. this.orderByStrs.splice(this.orderByStrs.indexOf(value), 1)
  133. this.orderByStrs1.splice(this.orderByStrs1.indexOf(value), 1)
  134. }
  135. }
  136. }
  137. </script>