export function bindInput(event) {
  var obj = {},
    key = event.target.dataset['key'];
  obj[key] = event.detail.value;
  console.log(obj)
  this.setData(obj);
}

let hasAuth = false
const subId = 'yDycTlNKWUr_cDztZXLXqc4Nfe2TlKy5hrQdwj0yoUs'
export function subcribe() {
  
  return new Promise((resolve, reject) => {
    wx.requestSubscribeMessage({
      tmplIds: [subId],
      success(res) {
        res.subId = subId
        console.log('订阅成功')
        resolve(res)
      },
      fail(err) {
        console.log(err, '订阅消息失败')
        reject(err)
      }
    })
  })

}

export function autoSubcrebe() {
  return new Promise(resolve => {
    wx.getSetting({
      withSubscriptions: true,
      success: (setting) => {
        let hasAuto = false
        if (setting && setting.subscriptionsSetting && setting.subscriptionsSetting.itemSettings && setting.subscriptionsSetting.itemSettings[subId]) {
          subcribe()
          hasAuto = true
        }
        resolve(hasAuto)
      }
    })
  })
  
}