// components/diy-group/index.js
var Nova = getApp().Nova;
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        options: null,
        buybutton: {
            type: Number,
            value: 3,
        },
    },

    /**
     * 组件的初始数据
     */
    data: {
        timeData: {},
    },

    ready: function() { // 在组件布局完成后执行，确保options参数中有data信息
        this.loadData()
    },
    /**
     * 组件的方法列表
     */
    methods: {
        async loadData() {
            await Nova.checkComponentsDataProperties(this);
            console.log(this.data.options.data)
            let list = await Nova.getBlockData(this.data.options.data)

            let {
                options
            } = this.data
            console.log('拼团', options);
            list.forEach((li, index) => {
                let now = new Date()
                let endTime = new Date(li.endTime.iso).getTime()
                let time = (endTime - now.getTime()) > 0 ? (endTime - now.getTime()) : 0
                list[index].time = time
                list[index].timeDate = {}
            });
            let {
                column,
                data,
                style,
            } = options
            let {
                className,
                filter
            } = data
            this.setData({
                column,
                list,
                data,
                style,
                className,
                filter
            })

            console.log(this.data.list)
        },

        onChange(e) {
            let index = e.currentTarget.dataset.index
            let timeData = `list[${index}].timeDate`
            this.setData({
                [timeData]: e.detail,
            });
        },
        toUrl(e) {
            console.log(e)
            let id = e.currentTarget.dataset.id
            wx.navigateTo({
                url: '/nova-shop/pages/goods/groupBuy/discount/index?id=' + id
            });
        }
    }
})