import request from '@/utils/request'

class API {
    constructor(url, req) {
        const map = {
            add: 'POST',
            del: 'DELETE',
            update: 'PUT',
            get: 'GET'
        }
        this.url = url
        for (let key in map) {
            this[key] = function (data) {
                data = Array.isArray(data) ? data : {
                    ...data, shopId: localStorage.getItem("shopId"),
                }
                if (key === 'del') {
                    delete data.shopId
                }
                const par={ url, method: map[key] }
                if(key==='get'){
                    par.params=data
                }else{
                    par.data=data
                }
                return request(par)
            }
        }
    }
}

export default API