import {InstructionsMessageType} from "$utils/request";

import popup from "$utils/tool/popup";
import {PopupExportComponent} from "$popup/popup-export/const";

export default <LibMixins>{

    data(){
      return {
          statusData:{
              '1':{
                  label:'审核中',
                  disabled:true
              },
              '2':{
                  label:'已认证',
                  disabled:true
              },
              '3':{
                  label:'已拒绝'
              }
          }
      }
    },

    methods:{

        getGame(item){

            if (this.statusData[item.status] && this.statusData[item.status].disabled) return ;

            if (this.loadingSatus) return ;
            this.setLoadingStatus(true);

            popup.$loading({
                title:'选取中',
                delay:1000
            });

            // @ts-ignore
            return Promise.all([this.getGamePrice(),this.getGameDetail(item)]).then(([prices,detail])=>{

                this.setLoadingStatus(false);
                if (prices.isSuccess && detail.isSuccess) {
                    // 如果都为真触发
                    detail.data.priceList = prices.data;

                    this.close();

                    return popup.$popup && popup.$popup.open(PopupExportComponent.settle,{
                        config: detail.data
                    });

                }

            }).catch(()=>{
                this.setLoadingStatus(false);
            })

        },

        getGameDetail(item){

            return this.$request({
                url:'game/get_game_info?gid='+item.gid,
                data:{
                    gid: item.gid
                },
                cache:true,
                loading:'选取中',
                failMessage:true,
                message:InstructionsMessageType.other
            });

        },

        getGamePrice(){
            return this.$request({
                url:'player/get_player_price_list',
                token:true,
                cache:true,
                message:InstructionsMessageType.other,
                failMessage:true,
            })
        },

        setLoadingStatus(status:boolean){

            if (this.loadingSatus !== status) {
                popup.hideLoading();
                this.loadingSatus = status;
            }
        },

        getCate(){
            this.$store.dispatch('initializationGameStatusPromise');
        }

    },

    created(){
        this.getCate();
    }

}