// pages/debitNoteList/debitNoteDetail/debitNoteDetail.js

const app = getApp();
var network = require("../../../utils/net.js");
var timechage = require("../../../utils/dateTimeUtil.js");
var getDebitNoteDetail = '/MainSystem/B3MiniProgramRpc/XuRpcs/Customer/DebitNoteRpc/GetDebitNoteDetail'
var confirmDebitNote = "/MainSystem/B3MiniProgramRpc/XuRpcs/Customer/DebitNoteRpc/ConfirmDebitNote"

Page({
  data: {

    item:{},
    ConfirmTime: '',
    Date: '',
    orderState:false
    },

  onLoad: function(options) {
    var that =this;
    let orderID = Number(options.ID);
    if (options.State == "未确认"){
      that.setData({
        orderState:true,
      });
    };

    let method = getDebitNoteDetail;
    let params = [orderID];
    network.transfer_request(method, params, function (res) {
      var backDate = timechage.formatTimeTwo(res.result.Date.substring(6, 19), 'Y/M/D');
      if (res.result.ConfirmTime){
        var backConfirmTime = timechage.formatTimeTwo(res.result.ConfirmTime.substring(6, 19), 'Y/M/D');

      }
      that.setData({
        item: res.result,
        Date: backDate,
        ConfirmTime: backConfirmTime,
      })
    })
  },

  // 新增按钮点击
  confirmDebitNoteBtnClicked: function(event) {
    var orderID = event.currentTarget.dataset.orderid;
    let method = confirmDebitNote;
    let params = [orderID];
    network.transfer_request(method, params, function (res) {
      wx.showToast({
        title: '操作成功',
        success: function (res){
          wx:wx.navigateBack({
            delta: 1,
          });
        }
      });
  });
},

})