import Vue from 'vue'
import {HttpResetClass} from 'vue-client'
let GetAppDataService = {
  install(Vue, options) {
    // 给vue增添对话框显示方法
    Vue.$appdata = Vue.prototype.$appdata = GetAppDataService
  },

  // 开启卡监听
  async load (noSale) {
    let url1 = `${Vue.androidUtil.getProxyUrl()}/rs/logic/getInitData`
    if(Vue.isv4){
      url1 = `${Vue.androidUtil.getProxyUrl()}/api/af-system/logic/getInitData`
    }
    let result = await new HttpResetClass().load('POST',url1, {data: {f_filialeids: Vue.user.orgid}}, {resolveMsg: null, rejectMsg: null})
    console.log(JSON.stringify(result))
    let newdata = {
      singleValues : result.data.singleValues,
      params: result.data.params
    }
    newdata.singleValues.forEach((item) => {
      this.singleValues[item.name] = item.value
    })
    newdata.params.forEach((item) => {
      let value = []
      item.f_paramvalues.forEach((item, index) => {
        value[index] = {}
        value[index].label = item.name
        value[index].value = item.name
      })
      this.params[item.name] = value
    })
    if (!noSale){
      let url2 = `${Vue.androidUtil.getProxyUrl()}/rs/logic/getSaleInitData`
      if(Vue.isv4){
        url2 = `${Vue.androidUtil.getProxyUrl()}/api/af-revenue/logic/getSaleInitData`
      }
      let getParams =   await new HttpResetClass().load('post',url2, {data: {f_orgid: Vue.user.orgid}}, {resolveMsg: null, rejectMsg: null})
      console.log('获取营收参数')
      console.log(JSON.stringify(getParams))
      let newsaledata = {
        gasbrands : getParams.data.gasbrands
      }
      if (newsaledata) {
        newsaledata.gasbrands.forEach((item, index) => {
          this.saleParams.gasbrands[index] = {}
          this.saleParams.gasbrands[index].label = item.f_meter_brand
          this.saleParams.gasbrands[index].value = item.f_meter_brand
          let gasmodel = []
          item.gasmodel.forEach((item, index) => {
            gasmodel[index] = {}
            gasmodel[index].label = item.f_meter_style
            gasmodel[index].value = item.f_meter_style
          })
          this.params[item.f_meter_brand] = gasmodel
        })
      }
    }
  },

  params: {},
  singleValues: {},

  // 营收模块参数
  saleParams: {
    gasbrands:[]
  },

  // 安检模块参数
  safeCheckParams: {},

  getParam(key) {
    return this.params[key]
  },
  getSingleValue(key) {
    return this.singleValues[key]
  }
}
export default GetAppDataService
