<template>

    <el-popover
        placement="bottom"
        title="排序"
        width="200"
        ref="draggablePopover"
        trigger="click"
    > 
    <div style="max-height:400px;overflow-y:auto;">
        <!-- <el-radio-group v-model="radio" @input="change"> -->
        <draggable ref="el" v-model="tableData" @end="end">
                <div v-for="item in tableData" :key="item.id" class="item" style="display:flex">
                    <span>
                        <el-radio v-model="radio" @input="change" :label="item.id">{{  }}</el-radio>
                    </span>
                    <my-tooltip :content="item.name" placement="right">
                            <div class="noWrap" style="cursor:move;">{{ item.name }}</div>
                    </my-tooltip>
                </div>
        </draggable>
    <!-- </el-radio-group> -->
    </div>
    
    <span slot="reference">
        <i class="el-icon-arrow-right" v-if="show" @click="show = !show"></i>
        <i class="el-icon-arrow-down" v-else @click="show = !show"></i>
    </span>
  </el-popover>
    

</template>

<script>
import draggable from 'vuedraggable'
export default {
  components: {
    draggable
  },
  props: {
    list:{
        default:[]
    },
    check:{
        default:''
    },

  },
  data() {
    return {
        show:true,
        tableData:JSON.parse(JSON.stringify(this.list)),
        radio:this.check
    };
  },
  watch: {
    list(){
        this.tableData = JSON.parse(JSON.stringify(this.list))
    },
    check(){
        this.radio = this.check
    },
  },
  computed: {},
  created() {},
  mounted() {},
  methods: {
    end(val){
        var newIndex = val.newIndex
        var oldIndex = val.oldIndex
        this.$emit('update',newIndex,oldIndex)
        // this.closePopover()
    },
    change(val){
        this.$emit('change',val,this.check)
        // this.closePopover()
    },
    //关闭弹窗
    closePopover(){
        this.$refs.draggablePopover.doClose()
        this.show = true
    }
  },
};
</script>
<style lang="scss" scoped>
.item{
    line-height: 30px;
}
</style>