// pages/handle/expenditureAudit/expenditureAudit.js
import * as UTIL from '../../../utils/util.js';
import * as API from '../../../utils/API.js';

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isIPX: app.globalData.isIPX,
    form:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      id:options.id,
      typeid:options.typeid
    })
    wx.showLoading({
      title: '正在加载模板',
      mask:true
    })
    //所属银行
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'bank_type', {method:'GET'}, {
      success: (res) => {
        this.setData({
          bankTypeOptions:res.data
        });
      }
    })
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'resource_farming_type', {method:'GET'}, {
      success: (res) => {
        that.setData({
          farmingTypeOptions:res.data,
        })
      }
    })
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'resources_build_type', {method:'GET'}, {
      success: (res) => {
        that.setData({
          buildTypeOptions:res.data,
        })
      }
    })
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'resources_unused_type', {method:'GET'}, {
      success: (res) => {
        that.setData({
          unusedTypeOptions:res.data,
        })
      }
    })
    /**使用情况 字典  1:自用  2:闲置  3:出租或外借  4:其他*/ 
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'use_type', {method:'GET'}, {
      success: (res) => {
        that.setData({
          useTypeOptions:res.data,
        })
      }
    })
    setTimeout(function(){
      //详情
      UTIL.httpRequest(API.URL_GET_GETRESOURCEGET + options.id, {method:'GET'}, {
        success: (res) => {
          res.data.resourceSortText = UTIL.getTransform(res.data.resourceSort,that.data.typeid == 1 ? that.data.farmingTypeOptions : that.data.typeid == 2 ? that.data.buildTypeOptions : that.data.typeid == 3 ? that.data.unusedTypeOptions : '');

          res.data.useTypeText = UTIL.getTransform(res.data.useType,that.data.useTypeOptions);

          that.setData({
            form:res.data
          })
        }
      })
    })
    
   wx.hideLoading()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  back:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})