const $ = global;
const colors = [
    'blue',
    'green',
    'pink',
    'orange',
    'purple'
];
new $.Page({
    data: {
        toView: '',
        list: []
    },
    onLoad() {
        $.request('classifies', 'GET', {}).then((res) => {
            const data = res.data;
            const list = [];
            if (data.length > 0) {
                data.forEach(d => {
                    if (!d.pid) {
                        d.array = [];
                        list.push(d);
                    }
                });
                data.forEach(d => {
                    if (d.pid) {
                        list.forEach((l, index) => {
                            l.color = colors[index];
                            if (l.id === d.pid) {
                                l['array'].push(d);
                            }
                        });
                    }
                });
                this.setData({
                    list
                });
            }
        });
    },
    toIntroduce(e) {
        const {
            id,
            name
        } = e.currentTarget.dataset;
        if (id) {
            if (name.includes('母婴')) {
                $.router.goto({
                    path: `/pages/goodsList/index`
                });
            } else if (name.includes('咨询')) {
                $.wx.showToast({
                    title: '持续开发中'
                });
            } else {
                $.router.goto({
                    path: `/pages/introduce/index`,
                    query: {
                        id,
                        name
                    }
                });
            }
        }
    }
});