import {Module} from "vuex";

import $request from '$utils/request';

export default <Module<any,any>>{

    state:{
        payList:[],
        payRatio:0
    },

    mutations:{

        setPayInfo(state,data){


            state.payList = data.config;

            state.payRatio = data.ratio;

        }

    },

    actions:{

        initializationPayPromise({commit}){

            return new Promise(function (resolve, reject) {
                Promise.all([$request({
                    url:'pay/get_can_recharge_list',
                    cache:true,
                    failMessage:true,
                    token:true,
                    login:false
                }),$request({
                    url:'user/exchange_check',
                    data:{
                      money:1
                    },
                    cache:true,
                    failMessage:true,
                    token:true,
                    login:false
                })]).then(([reList,check])=>{

                    let data ={
                        config: reList.data || [],
                        ratio: check.data.money
                    }

                    commit('setPayInfo',data);
                    return resolve(data);
                });
                // $request({
                //     url:'pay/get_can_recharge_list',
                //     cache:true,
                //     failMessage:true,
                //     token:true,
                //     login:false
                // }).then((data)=>{
                //     commit('setPayInfo',data);
                //     return resolve(data);
                // }).catch(reject)
            });

        }

    }

}