var app = getApp();
var that;
var animation;
Page({
  data: {
    defaultVal: '',
    process: {
      recorder_id: app.globalData.userData.id,
      recorder: app.globalData.userData.name,
      remark: '',
      point: 0,
      img_url: app.globalData.userData.img_url,
      time: app.globalData.allDate
    },
    items:[],
    id:'',
    isArrindex:true,//正还是负
  },
  onLoad(e) {
    that = this;
    dd.setNavigationBar({ title: "任务过程" });
    if(e.id){
      this.setData({
        id:e.id,
        items:JSON.parse(e.item),
        process: {
          recorder_id: app.globalData.userData.id,
          recorder: app.globalData.userData.name,
          remark: '',
          point: 0,
          img_url: app.globalData.userData.img_url,
          time: app.globalData.allDate
        },
      })
    }
  },
    //备注输入
  bindTextAreaBlur: function (e) {
    this.setData({
      [`process.remark`]: e.detail.value,
    });
  },
  bindKeyInput(e) {
    this.setData({
      [`process.point`]: e.detail.value,
    });
  },
  formSubmit() {
    var page1 = getCurrentPages()[getCurrentPages().length - 2]//上一个页面的数据
    if(this.data.process.point==0||!this.data.process.point){
          app.globalData.showToast("请输入记分");
          return;
    }
    var data={
      work_id:this.data.id,
      process:[]
    }
    var items=this.data.items;
    var process=this.data.process;
    this.data.isArrindex === false ? process.point = process.point * -1 : process.point = process.point * 1
    items.unshift(process)
    data.process=JSON.stringify(items);
    app.$post("api/integral/work", data).then((res) => {
        page1.getDetail(this.data.id,function(){
            app.globalData.showToast(res.data.msg);
            setTimeout(() => {
              dd.navigateBack({ delta: 1 })
            }, 1000);
        })
    })
    console.log(page1)
  },
  //选择奖还是扣(细则)
  bindPickerChange() {
    this.setData({
      isArrindex: !this.data.isArrindex,
    });
  },
});
