import {FlatListReload} from "$components/flat-list/const";
import roomList from '$utils/control/roomList';

export default <LibMixins>{

    methods:{

        fetch(obj){
            roomList.getRequestList(this.talkingWhere,obj.data).then((data)=>{
                return  obj.success(data.data);
            }).catch(obj.fail);
        },

        triggerChangeName(item){

            if (item && item.options && item.options.collect) {
                roomList.on('view-talking',{
                    vm:this
                });
            } else {
                roomList.off('view-talking');
            }

            return this.$refs.flat && this.$refs.flat.flat_clear_to_start();
        },

        triggerChange(item){

            this.talkingWhere = {
                tid: item.id,
                ...(item.options || {})
            };

            this.$refs.flat && this.$refs.flat.reload(FlatListReload.start);
        }

    },

    beforeUnmount() {
        roomList.off('view-talking');
    }

}