// pages/homePage/homePage.js
var app = getApp()
var network = require("../../utils/net.js")
var timechage = require("../../utils/dateTimeUtil.js")

function GetUserProfile(successtion) {
  let method = '/MainSystem/B3MiniProgramRpc/XuRpcs/Customer/AccountBalanceRpc/GetCurrentBalanceMoney';
  let params = [];
  network.transfer_request(method, params, function(res) {
    successtion(res);
  })
}

Page({
  data: {
    currentDate: timechage.formatTimeTwo(Date.parse(new Date()), 'Y/M/D'),
    balance: "",
  },

  onLoad: function(options) {
    var that = this;
    //由登录页面进入详情页变更值为0；分享直接进入为1
    app.globalData.shareInState = 0;
    // 添加接口请求当前余额
    GetUserProfile(function(res) {
      if (res != null) {
        that.setData({
          balance: res.result
        });
      }
      var shareURL = app.globalData.shareInPath;
      if (shareURL) {
          wx.navigateTo({
            url: "../../" + shareURL,
            complete: function (res) {
              app.globalData.shareInPath = "";
            },
          })
      }
    });
  },

  /**
   * 点击页面按钮进行跳转
   */
  transBtnClicked: function(event) {
    var btnID = event.currentTarget.dataset.itemid;
    var transferURL = '';
    switch (btnID) {
        // 预报
      case "1":
        transferURL = '/pages/saleForecastList/saleForecastList';
        break;
        // 订单
      case "2":
        transferURL = '/pages/order/order';
        break;
        // 客户找车
      case "3":
        transferURL = '/pages/sendCargo/sendCargo';
        break;
        // 销售出库
      case "4":
        transferURL = '/pages/saleOutStore/saleOutStore';
        break;
        // 担保单
      case "5":
        transferURL = '/pages/guarantee/guarantee';
        break;
        // 客户对账
      case "6":
        transferURL = '/pages/statementOfAccount/statementOfAccount';
        break;
        // 欠款单
      case "7":
        transferURL = '/pages/debitNoteList/debitNoteList';
        break;
    }

    wx.navigateTo({
      url: transferURL,
    })
  },


})