<template>
  <div id="unit" class="flex-row">
    <gas-price-list v-ref:list :row="row" :config="config" :ispartial="gasPriceShow" @select-changed="selected" style="width:50%"></gas-price-list>
    <div style="width:50%; margin-left: 20px;" class="flex" v-if="isdetail">
      <!-- <p class="bg-info text-center" style="padding: 8px;" v-if="row.pricecount">气价变更情况汇总</p> -->
      <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" @close="refresh" v-ref:gas v-if="gasPriceShow"></gas-price>
    </div>
  </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 {
        config: {
          isLimit: false, // 限购
          audit: false,  // 启用审核
          heatingSeason: false, // 采暖季
        },
        row: null,
        parentData: '',
        isdetail: false,
        gasPriceShow: false
      }
    },
    ready () {
      readGen(this)
    },
    methods: {
      selected (obj) {
        this.row = obj.val
        this.parentData = this.row.id
        this.isdetail = true
        if (this.row.pricecount <= 1) {
          this.row.pricecount = null
        }
        this.gasPriceShow = !this.row.pricecount
      },
      selected2 (obj) {
        this.gasPriceShow = true
        this.row = Object.assign({}, this.row, obj.val)
      },
      refresh () {
        this.row = null
        this.gasPriceShow = false
        this.isdetail = false
        this.$refs.list.search()
      }
    },
    events: {
      'success' (name, row, res) {
        this.row = row
        this.gasPriceShow = false
        this.isdetail = false
        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.$refs.list.search()
        if (row.pricecount) {
          row.pricecount === 1
          this.$refs.update.getUpdate()
        }
      },
      'close' (res) {
        this.row = null
        this.gasPriceShow = false
        this.isdetail = false
      },
      'search' () {
        this.row = null
        this.gasPriceShow = false
        this.isdetail = false
        // this.$refs.list.search()
      },
      'add' () {
        this.isdetail = 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>
