<template>
  <div id="unit" class="flex-row" v-if="listpage" >

    <div :class="{'basic-main':((!isdetail) && (!usershow)),'binary-left':isdetail||usershow}" >
    <gas-price-list v-ref:list :row="row" :config="config" :ispartial="gasPriceShow" :f_filialeid.sync="f_filialeid" @select-changed="selected" ></gas-price-list>
    </div>
    <div class="binary-right" style="overflow-y: scroll" v-if="isdetail&&!usershow">
      <ul class="nav nav-tabs" v-if="row.pricecount">
        <li class="active"><a href="#">气价变更情况汇总</a></li>
      </ul>
      <div style="max-height: 200px;" v-if="row.pricecount">
        <update-info v-ref:update :data="row" :parent-data="parentData" @select-changed="selected2"></update-info>
      </div>
      <gas-price :data="row" :config="config" :f_filialeid.sync="f_filialeid" @close="refresh" v-ref:gas v-if="gasPriceShow"></gas-price>
    </div>
    <div class="binary-right" v-if="usershow">
      <ul class="nav nav-tabs">
      <li class="active"><a href="#">气价使用人</a></li>
      </ul>
      <gasprice-user :priceid="priceid"></gasprice-user>
    </div>

  </div>
    <div v-if="!listpage">
      <user-info-detail-manage :f_userinfo_id="f_userinfo_id" @cancel-main="cancel"></user-info-detail-manage>
    </div>

</template>
<script>
/**
*阶梯气价管理组件
*/


let readGen = async function (self) {
  // 获取气价里面的配置
  let getConfig = await self.$getConfig(self, 'GasPrice')
  if (getConfig) {
    Object.assign(self.config, self.config, getConfig.data)
  }
  console.log('获取气价配置', self.config)
}

export default {
  title: '气价管理',
  data () {
    return {
      f_userinfo_id:'',
      f_filialeid: this.$login.f.orgid,
      config: {
        isLimit: false, // 限购
        audit: false,  // 启用审核
        heatingSeason: false, // 采暖季
      },
      listpage: true,
      row: null,
      parentData: '',
      isdetail: false,
      priceid:'',
      gasPriceShow: false,
      usershow:false,
    }
  },
  ready () {
    readGen(this)
  },
  methods: {
    cancel(obj) {
      this.listpage = true
    },
    dealMsg(val) {
      this.listpage = false
      this.f_userinfo_id = val.f_userinfo_id
    },
    selected (obj) {
      this.row = obj.val
      this.parentData = this.row.id
      this.isdetail = true
      this.usershow =false
      this.listpage=true
      if (this.row.pricecount <= 1) {
        this.row.pricecount = null
      }
      this.gasPriceShow = !this.row.pricecount
    },
    selected2 (obj) {
      this.row = Object.assign({}, this.row, obj.val)
      this.gasPriceShow = true
      this.listpage=true
      this.usershow =false
    },
    refresh () {
      this.row = null
      this.gasPriceShow = false
      this.isdetail = false
      this.usershow =false
      this.listpage=true
      this.$refs.list.search()
    }
  },
  events: {
    'success' (name, row, res) {
      this.row = row
      this.gasPriceShow = false
      this.isdetail = false
      this.usershow =false
      this.listpage=true
      this.$refs.list.search()
      if (row.pricecount) {
        this.$refs.update.getUpdate()
      }
    },
    'error' (name, row, res) {
      this.row = row
      this.gasPriceShow = false
      this.isdetail = false
      this.usershow =false
      this.listpage=true
      this.$refs.list.search()
      if (row.pricecount) {
        row.pricecount === 1
        this.$refs.update.getUpdate()
      }
    },
    'close' (res) {
      this.row = null
      this.gasPriceShow = false
      this.isdetail = false
      this.usershow =false
      this.listpage=true
    },
    'search' () {
      this.row = null
      this.gasPriceShow = false
      this.isdetail = false
      this.usershow =false
      this.listpage=true
      // this.$refs.list.search()
    },

    'add' () {
      this.isdetail = true
      this.usershow =false
      this.listpage=true
      if(this.gasPriceShow){
        this.$refs.gas.initModel()
      }
      this.gasPriceShow = true
      this.$refs.list.$refs.paged.$refs.grid.selectStore.selected = null
      this.row = null
    }
  }
}
</script>
<style>

</style>
