var app = getApp();
var that;
Page({
  data: {
    val: 1,
    detail:{},
    num:'',
    remark:'',
    disabled: false,
    gxd:'',
  },
  onLoad(e) {
    that = this;
    dd.setNavigationBar({ title: "奖品详情" });
    if(e.item){
        let item=JSON.parse(e.item);
        that.setData({gxd:item.gxd })
        that.getData(item.id);
    }
  },
  showImg(e) {
    var url = e.target.dataset.url
    dd.previewImage({
      current: 0,
      urls:[url]
    });
  },
  getData(id) {
    app.$get('api/shop/goods/detail', { id:id}).then((res) => {
      this.setData({
        detail:res.data.data,
      })
    })
  },
  active(e) {
    var id = e.target.dataset.id;
    let val = this.data.val;
    if (id == 1) {
      if (val != 1) {
        val--;
      }
    } else {
      val++
    }
    this.setData({
      val: val
    })
  },
    //备注输入
  bindTextAreaBlur: function (e) {
    this.setData({
      remark: e.detail.value,
    });
  },
  openText(){
    if(this.data.disabled){
        return false
    };
    if(this.data.detail.gxd<this.data.num){
      app.globalData.showToast("功勋点不足");
      return false
    }
    let data={
      goods_id:this.data.detail.id,
      num:this.data.val,
      remark:this.data.remark,
    }
    this.setData({ disabled: true });
    app.$post("api/shop/exchange/create", data).then((res) => {
      app.globalData.showToast("已兑换");
      setTimeout(() => {
        this.setData({ disabled: false });
        dd.navigateBack({ delta: 1 })
      }, 1000);
    }).catch(err => {
        this.setData({ disabled: false });
    })
  },
  showText() {
    this.setData({ 
      isBh: !this.data.isBh,
      num: this.data.val*this.data.detail.price,
    })
  },
  handleCopy() {
    dd.setClipboard({
      text: this.data.text,
    })
    app.globalData.showToast("已复制");
  }
});
