let API_HOST = "http://xxx.com/xxx";
let DEBUG = true; //切换数据入口

function ajax(index, fn, method = "get", header = {}) {
    if (!DEBUG) {
        wx.request({
            url: config.API_HOST + data,
            method: method ? method : 'get',
            data: {},
            header: header ? header : {
                "Content-Type": "application/json"
            },
            success: function (res) {
                fn(res);
            }
        });
    } else {
        // 模拟数据

        switch (index) {
            case 0:
                var res = Mock.mock({
                    'error_code': '',
                    'error_msg': '',
                    'data': [{
                        id: 1,
                        title: "葛优躺（北京躺）电影足疗",
                        price: "299",
                        desc: "全店通用",
                        open: true,
                        imgurl:"../../images/product01.jpg",
                    }, {
                        id: 2,
                        title: "葛优躺（北京躺）电影足疗",
                        price: "299",
                        desc: "全店通用",
                        open: false,
                        imgurl:"../../images/product02.jpg",
                    }]
                })
                break;
            case 1:
                var res = Mock.mock({
                    'error_code': '',
                    'error_msg': '',
                    'data': [{
                        id: 1,
                        title: "葛优躺（北京躺）电影足疗",
                        price: "299",
                        desc: "全店通用",
                        open: true,
                        imgurl:"../../images/product01.jpg"
                    }]
                })
            break;
            case 2:
                var res = Mock.mock({
                    'error_code': '',
                    'error_msg': '',
                    'data': [{
                        id: 1,
                        title: "葛优躺（北京躺）电影足疗",
                        price: "299",
                        desc: "全店通用",
                        open: true,
                        imgurl:"../../images/product01.jpg"
                    }]
                })
            break;
            case 3:
                var res = Mock.mock({
                    'error_code': '',
                    'error_msg': '',
                    'data': [{
                        id: 1,
                        title: "葛优躺（北京躺）电影足疗",
                        price: "299",
                        desc: "全店通用",
                        open: true,
                        imgurl:"../../images/product01.jpg"
                    }]
                })
            break;
            case 4:
                var res = Mock.mock({
                    'error_code': '',
                    'error_msg': '',
                    'data': [{
                        id: 1,
                        title: "葛优躺（北京躺）电影足疗",
                        price: "299",
                        desc: "全店通用",
                        open: true,
                        imgurl:"../../images/product01.jpg"
                    }]
                })
            break;
        }




        // 输出结果
        // console.log(JSON.stringify(res, null, 2))
        fn(res);
    }
}
module.exports = {
    ajax: ajax
}