const util =require('../../utils/util.js')
const app = getApp()
Page({
  data: {
    info:{},
    phone:'',
    id:''
  },
  onLoad: function (options) {
    this.setData({id:options.id})
    this.getInfo()
  },
  inputChange(e){
    this.setData({phone:e.detail.value})
  },
  getInfo(){//成长卡领取详情
    let that = this;
    util.ajax({
      func: "v2/growthCard/receiveStatus",
      data: { "id":that.data.id },
      load: false
    }, function (res) {
      if (res.code == 0) {
        that.setData({info:res.data})
      } else {
        util.showTips(res.reason);
      }
    });
  },
  submit(){//成长卡领取
    let that = this;
    if(util.isPhone(this.data.phone)){
      util.showTips("请输入正确的手机号");
      return false
    }
    util.ajax({
      func: "v2/growthCard/receive",
      data: {"phone": that.data.phone,"id":that.data.id},
    }, function (res) {
      if (res.code == 0) {
        wx.navigateTo({
          url: '/pages/growthCard/result?status=' +res.data.status 
        })
      } else {
        util.showTips(res.reason);
      }
    });
  }
})