12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <template>
- <el-form-item label="排序">
- <draggable v-model="orderByStrs" :group="{name: 'orderBy',pull: false, put: false}" style="display: inline-block;">
- <el-tag v-for="(item,index) in orderByStrs" :key="index" closable size="small" @close="handleCloseOrderBy">
- {{ item }}12
- </el-tag>
- </draggable>
- <el-cascader v-model="orderBy" :options="orderByOption" :disabled="orderByOption.length===0" size="mini" :placeholder="$t('chart.selectOrderBy')" style="width: 150px;" @change="handleOrderByChange" />
- </el-form-item>
- </template>
- <script>
- import draggable from 'vuedraggable'
- import store from '../store'
- export default {
- components: { draggable },
- props: {
- value: {
- required: true,
- type: Array
- }
- },
- data() {
- return {
- orderBy: []
- }
- },
- computed: {
- allSelected() {
- return store.state.caculCols.concat(store.state.dimensions)
- },
- orderByStrs: {
- set(value) {
- this.$emit('input', value)
- },
- get() {
- return this.value
- }
- },
- orderByOption() {
- return this.allSelected.map(col => {
- return {
- value: col.Column,
- label: col.Comment,
- children: [{
- value: 'desc',
- label: '降序'
- }, {
- value: 'asc',
- label: '正序'
- }]
- }
- })
- }
- },
- watch: {
- 'store.state.dimensions': function (value) {
- this.watchHandler(value)
- },
- 'store.state.caculCols': function (value) {
- this.watchHandler(value)
- }
- },
- methods: {
- watchHandler(cols) {
- console.log("cols", cols)
- this.orderByStrs.forEach((orderByStr, index) => {
- console.log('orderByStr', orderByStr)
- const colName = orderByStr.split(' ')[0]
- console.log('colName', colName)
- if (!cols.findIndex(col => col.Column === colName)) {
- this.orderByStrs.splice(index, 1)
- }
- })
- },
- handleOrderByChange(value) {
- console.log('handleOrderByChange:', value)
- this.orderBy = []
- const index = this.orderByStrs.findIndex(orderBy => orderBy.indexOf(value[0]) >= 0)
- if (index >= 0) {
- this.orderByStrs.splice(index, 1, `${value[0]} ${value[1]}`)
- } else {
- this.orderByStrs.push(`${value[0]} ${value[1]}`)
- }
- console.log('handleOrderByChange:', value)
- console.log('this.orderByStrs', this.orderByStrs)
- },
- handleCloseOrderBy(value) {
- this.orderByStrs.splice(this.orderByStrs.indexOf(value), 1)
- }
- }
- }
- </script>
|