import {
    getProducts
} from '~/api/global'
import {
    getWxQrcode,
} from '~/api/user'
const app = getApp()

Component({
    properties: {

    },
    data: {
        show: false,
        products: [],
        // 是否购买过vip
        isIos: app.globalData.isIOS,
        qrCode: '',
        isPreferential: false
    },
    methods: {
        async open() {
            if (!this.data.isIos) {
                this.getProducts()
            } else {
                let qrCode = await getWxQrcode()
                console.log(qrCode);
                this.setData({
                    qrCode: qrCode.ticketUrl
                })
            }
            this.setData({
                show: true,
            })
        },
        closeModal() {
            this.setData({
                show: false
            })
        },
        async getProducts() {
            let {
                isPreferential,
                productList: products,
            } = await getProducts()
            this.setData({
                products,
                isPreferential
            })
        },
        toBuy({
            currentTarget
        }) {
            this.triggerEvent('toBuy', currentTarget.dataset.goods)
        }
    }
})