import config from "../../../utils/config.js"
Page({
  data: {
    code: 'QJ234W85' // 这里是二维码下方的变量文本
  },
  onInputChange(e) {
    this.setData({ code: e.detail.value });
  },
  onOpenReward() {
    if (!this.data.code.trim()) {
      wx.showToast({
        title: '请输入明码',
        icon: 'none'
      });
      return;
    }
  
    wx.showToast({
      title: '正在验证...',
      icon: 'loading'
    });
  
    // 请求服务器验证明码
    setTimeout(() => {
		// let latitude = getApp().globalData.userInfo.latitude
		// let longitude = getApp().globalData.userInfo.longitude
		const apiBase = config.dataServer
		wx.request({
			url: apiBase + `/junyao/${this.data.code}`,
			header: {
				'Authorization': `Bearer ${getApp().globalData.userInfo?.token}`,
				'serialId': getApp().userInfo?.serialId
			},
			method: "POST",
			data: {},
			timeout: 30 * 1000,
			success: (res) => {
				let tag = res.data.tag
				wx.navigateTo({
				  url: `/scanGroup/jyScan/index/index?tag=${tag}`,
				})
			},
			fail: (res) => {
				console.log(res)
				// const msg = await getErrortxt()
				// wx.showModal({
				// 	title: '提示',
				// 	content: msg,
				// 	showCancel: false,
				// 	confirmText: '知道了',
				// 	confirmColor: '#fe8600'
				// })
			},
			complete: () => {
				// wx.hideNavigationBarLoading()
				// if (showLoading) {
				// 	wx.hideLoading()
				// }
			}
		})
      // wx.showToast({
      //   title: '奖励已领取!',
      //   icon: 'success'
      // });
    }, 2000);
  }
});