Component({
    properties: {
    },
    /**
     * 组件的初始数据
     */
    data: {
        state: false,
        img: ''
    },
    lifetimes: {
        attached: function () {
            if (wx.getPrivacySetting) {
                wx.getPrivacySetting({
                    success: res => {
                        if (res.needAuthorization) {
                            this.setData({
                                state: true
                            })
                            if (typeof this.getTabBar === 'function') {
                                this.getTabBar().setData({
                                    mask: true
                                })
                            }
                        } else {
                            this.triggerEvent("agree")
                        }
                    },
                    fail: () => {},
                    complete: () => {},
                })
            } else {
                // 低版本基础库不支持 wx.getPrivacySetting 接口,隐私接口可以直接调用
                this.triggerEvent("agree")
            }
        },
    },
    methods: {
        handleAgree(e) {
            this.triggerEvent("agree")
            this.setData({
                state: false
            })
            this.getTabBar().setData({
                mask: false
            })
        },
        openPrivacyContract() {
            wx.openPrivacyContract({
                success: res => {
                    console.log('openPrivacyContract success')
                },
                fail: res => {
                    console.error('openPrivacyContract fail', res)
                }
            })
        }
    }
})