import typeData from '../data/type';
import user from "$config/user";
export default <LibMixins>{

    inject:['getRoomInfo','openUserInfo','allowForWheat','getAgoraRTMIM','setPeopleOnline'],

    computed:{
      audienceItem(){
          return typeData[this.type] || {};
      }
    },

    methods:{

        changeData(data){
            if (this.audienceItem && this.audienceItem.number) {
                return this[this.audienceItem.number](data.length);
            }
        },

        fetch(obj){
            if (this.type === 'audience') {
                return this.getAudienceList(obj);
            } else {
                return this.getWheatList(obj);
            }
        },

        // 获取在线用户列表
        getAudienceList(obj){
            return this.$request({
                url:'room/get_room_alluser_list',
                data:{
                    rid: this.roomInfo.rid
                },
                page:obj.data,
                token:true
            }).then((data)=>{
                data = data.data || {};

                data = [...data.room_admin_list,...data.room_visitor_list,...data.micro_user_list,user.user];

                return obj.success(data);

            }).catch(obj.fail);
        },

        // 获取排麦列表
        getWheatList(obj){
            return this.$request({
                url:'room/get_room_mc_queue_list',
                data:{
                    rid: this.roomInfo.rid
                },
                page:obj.data,
                token:true
            }).then((data)=>{
                return obj.success(data.data || []);
            }).catch(obj.fail);
        },

        // 拉人上麦
        triggerAllowForWheat(user){
            if (user.uid) {
                this.allowForWheat(user);
            }
        }
    },

    created() {
        this.roomInfo = this.getRoomInfo();
        this.agoraRTMIM = this.getAgoraRTMIM();
    }

}
