// pages/mainBody/detail/detail.js
import * as UTIL from '../../../utils/util.js';
import * as API from '../../../utils/API.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isIPX: app.globalData.isIPX,
    // 主体类别字典
    statisticsTypeIdOptions: [],
    // 示范社类型字典
    modelSocietyTypeOptions: [],
    // 经营状态字典
    registrationStatusOptions: [],
    // 企业类型字典
    enterpriseTypeOptions: [],
    //产业分类字典项
    industryClassificationTypeOptions: [],
    // 审核状态字典
    reviewStatusOptions: [],
  },
  back:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var that = this;
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'newBusinessEntity_statistics_project', {method:'GET'}, {
      success: (res) => {
        that.setData({
          statisticsTypeIdOptions:res.data,
        })
      }
    })
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'model_society_type', {method:'GET'}, {
      success: (res) => {
        that.setData({
          modelSocietyTypeOptions:res.data,
        })
      }
    })
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'registration_status', {method:'GET'}, {
      success: (res) => {
        that.setData({
          registrationStatusOptions:res.data,
        })
      }
    })
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'enterprise_type', {method:'GET'}, {
      success: (res) => {
        that.setData({
          enterpriseTypeOptions:res.data,
        })
      }
    })
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'Industrial_classification_type', {method:'GET'}, {
      success: (res) => {
        that.setData({
          industryClassificationTypeOptions:res.data,
        })
      }
    })
    UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'sys_yes_no', {method:'GET'}, {
      success: (res) => {
        that.setData({
          reviewStatusOptions:res.data,
        })
      }
    })
    let data = {
      method: 'GET'
    }
    UTIL.httpRequest(API.URL_GET_ENTITYDETAIL + options.id ,data,{
      success: (res) => {
        if (res.code == API.SUCCESS_CODE) {
          res.data.statisticsTypeIdText = UTIL.getTransform(res.data.statisticsTypeId,that.data.statisticsTypeIdOptions);
          res.data.industryClassificationTypeText = UTIL.getTransform(res.data.industryClassificationType,that.data.industryClassificationTypeOptions);
          res.data.modelSocietyTypeText = UTIL.getTransform(res.data.modelSocietyType,that.data.modelSocietyTypeOptions);
          res.data.registrationStatusText = UTIL.getTransform(res.data.registrationStatus,that.data.registrationStatusOptions);
          res.data.enterpriseTypeText = UTIL.getTransform(res.data.enterpriseType,that.data.enterpriseTypeOptions);

          UTIL.httpRequest('/system/dept/treeselectByDeptId', {deptId: res.data.serviceDeptId,method:'GET'}, {
            success: (res2) => {
              res.data.serviceDeptIdName = res2.data[0].label;
            }
          })

          let fileList = res.data.masterMap.split(',');
          let fileImg = []
          fileList.map((rr,index) => {
            fileImg.push({
              url: wx.getStorageSync('dressCode') + rr,
              name: '图片' + index,
              isImage: true,
            });
          })
          res.data.fileImg = fileImg;
          console.log(fileImg);

          UTIL.httpRequest('/finance/book/list', {deptId: 0,method:'GET'}, {
            success: (res2) => {
              console.log(res2.rows.filter(function (e) { return e.id == res.data.bookId; })[0]);
              res.data.bookName = res2.rows.filter(function (e) { return e.id == res.data.bookId; })[0].bookName;
              this.setData({
                detail:res.data,
              })
            }
          })

        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

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

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

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

  },

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

  },

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

  },

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

  }
})