import {FlatListReload} from "$components/flat-list/const";

import cateData from '$config/cate';
import socket from "$utils/socket";
import {NoticeType} from "$utils/socket/const";

export default <LibMixins>{

    data(){
      return {
          cate_name:''
      }
    },

    methods:{

        fetch(obj){

            return this.$request({
                url:'player/get_player_list',
                token:true,
                data: this.playerWhere,
                page:obj.data
            }).then((data)=>{

                if (cateData.gameCate.object) {
                    data.data.map((item)=>{
                        item.game_name = cateData.gameCate.object[item.gid].game_name;
                    });
                }

                return  obj.success(data.data);

            }).catch(obj.fail);

        },

        triggerChangeName(item){
            this.cate_name = item.name;
            return this.$refs.fetch && this.$refs.fetch.flat_clear_to_start();
        },

        triggerChange(item){

            this.playerWhere = {
                gid: item.id,
                ...(item.options || {})
            };

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

    },

    created(){

        socket.on('view-play-with', (data)=>{
            console.log(data);
            if (this.$refs.fetch) {
                let item = this.$refs.fetch.flat_get_data(data.uid);
                item.guanming = data.naming;
                this.$refs.fetch.flat_update(data.uid,item);
            }
        },NoticeType.naming);

    },

    beforeUnmount() {
        socket.off('view-play-with',NoticeType.naming);
    }
}
