<template>
  <div class="binary">
    <div :class="{'basic-main': !showDetail,'binary-left': showDetail}">
      <div class="flex" style="flex: 1;">
        <div style="flex: 1.2">
          <criteria-paged :model="model" v-ref:paged @sort="sort">
            <criteria @condition-changed="$parent.selfSearch" partial='criteria' v-ref:criteria>
              <div class="form-horizontal select-overspread container-fluid auto" novalidate partial>
                <div class="row">
                  <div
                    :class="{'col-sm-2':!$parent.$parent.showDetail,'col-sm-4':$parent.$parent.showDetail}"
                    class="form-group">
                    <label class="font_normal_body">&nbsp;&nbsp;&nbsp;小区&nbsp;&nbsp;&nbsp;</label>
                    <v-select :value.sync="model.f_residential_area"
                              class="select_list select"
                              enter-push multiple
                              v-model="model.f_residential_area"
                              style="width: 60%"
                              condition="a.f_residential_area in {}"
                              :options='$parent.$parent.residentialArea' placeholder='选择小区'
                              close-on-select>
                    </v-select>
                  </div>

                  <div
                    :class="{'col-sm-2':!$parent.$parent.showDetail,'col-sm-4':$parent.$parent.showDetail}"
                    class="form-group">
                    <label class="font_normal_body">客户状态</label>
                    <v-select :options='$parent.$parent.userstates' :value.sync="model.f_user_state"
                              close-on-select condition="ui.f_user_state='{}'"
                              placeholder='客户状态' v-model="model.f_user_state"></v-select>
                  </div>
                  <div
                    :class="{'col-sm-2':!$parent.$parent.showDetail,'col-sm-4':$parent.$parent.showDetail}"
                    class="form-group">
                    <label class="font_normal_body">组织机构</label>
                    <res-select
                      :initresid='$parent.$parent.curorgid'
                      @res-select="$parent.$parent.getorg"
                      is-mul="false"
                      restype='organization'
                    >
                    </res-select>
                  </div>
                  <div
                    :class="{'col-sm-2':!$parent.$parent.showDetail,'col-sm-4':$parent.$parent.showDetail}"
                    v-if="!$parent.$parent.showDetail"
                    class="form-group">
                    <label class="font_normal_body">&nbsp;&nbsp;&nbsp;区域&nbsp;&nbsp;&nbsp;</label>
                    <v-select :value.sync="model.f_street"
                              class="select_list select"
                              enter-push
                              condition="a.f_street = '{}'"
                              v-model="model.f_street"
                              style="width: 60%"
                              :options='$parent.$parent.street' placeholder='选择区域'
                              close-on-select>

                    </v-select>
                  </div>
                  <div
                    :class="{'col-sm-2':!$parent.$parent.showDetail,'col-sm-4':$parent.$parent.showDetail}"
                    class="form-group button-range">

                    <button @click="search(), $parent.$parent.clean()" class="button_search button_spacing"
                            style="float: right">查询
                    </button>
                    <export-excel :data="$parent.$parent.getCondition"
                                  :field="$parent.$parent.getfield"
                                  :header="$parent.$parent.other"
                                  sqlurl="api/af-revenue/logic/openapi/exportfile"
                                  sql-name="areaBuildingInfoSummary"
                                  template-name='小区楼栋汇总信息'
                                  :choose-col="true"></export-excel>
                    <print-data :sum-field="$parent.$parent.getfield" :model="$parent.model"
                                :field="$parent.$parent.getfield"
                                titletable="用户查询" :starthead="$parent.$parent.startDate"
                                :defaultfield="$parent.$parent.defaultfield"
                    ></print-data>

                    <div
                      :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                      @click="$parent.$parent.hidden()"
                      class="button_spacing"
                      style="float: right"></div>
                  </div>
                </div>
                <div class="row" v-if="$parent.$parent.criteriaShow">
                  <div
                    :class="{'col-sm-2':!$parent.$parent.showDetail,'col-sm-4':$parent.$parent.showDetail}"
                    v-if="$parent.$parent.showDetail"
                    class="form-group">
                    <label class="font_normal_body">&nbsp;&nbsp;&nbsp;区域&nbsp;&nbsp;&nbsp;</label>
                    <v-select :value.sync="model.f_street"
                              class="select_list select"
                              enter-push
                              condition="a.f_street = '{}'"
                              v-model="model.f_street"
                              style="width: 60%"
                              :options='$parent.$parent.street' placeholder='选择区域'
                              close-on-select>

                    </v-select>
                  </div>
                </div>
              </div>
            </criteria>
            <data-grid :model="model" class="list_area table_sy" @dblclick="$parent.modifyUser" v-ref:grid
                       partial='list'>
              <template partial='head'>
                <tr>
                  <th>
                    <nobr>序号</nobr>
                  </th>
                  <th>
                    <nobr>小区名称</nobr>
                  </th>
                  <th>
                    <nobr>楼栋数</nobr>
                  </th>
                  <th>
                    <nobr>用户数</nobr>
                  </th>
                  <th>
                    <nobr>已开户</nobr>
                  </th>
                  <th>
                    <nobr>已通气</nobr>
                  </th>
                  <th>
                    <nobr>未通气</nobr>
                  </th>
                  <th>
                    <nobr>空户</nobr>
                  </th>
                  <th>
                    <nobr>操作</nobr>
                  </th>
                </tr>
              </template>
              <template partial='body'>
                <td style="text-align: center;">{{ $index + 1 }}</td>
                <td style="text-align: center;">{{ row.f_residential_area }}</td>
                <td style="text-align: center;">{{ row.f_building_num }}</td>
                <td style="text-align: center;">{{ row.f_user_num }}</td>
                <td style="text-align: center;">{{ row.f_open_num }}</td>
                <td style="text-align: center;">{{ row.f_gas_num }}</td>
                <td style="text-align: center;">{{ row.f_nogas_num }}</td>
                <td style="text-align: center;">{{ row.f_empty_num }}</td>
                <td style="text-align: center;">
                  <button type="button" name="button" class="button_search-2 button_spacing width-60"
                          @click.stop="$parent.$parent.$parent.toDetail(row)">详情
                  </button>
                </td>
              </template>
            </data-grid>
          </criteria-paged>
        </div>
      </div>
    </div>
    <div class="binary-right" :style="{width:'70%'}" v-if="showDetail">
      <div class="auto" style="height: 100%; margin-top: 1%">
        <area-building-detail-info :row="row" :user-state="userState" v-ref:info></area-building-detail-info>
      </div>
    </div>
  </div>
</template>

<script>
import {HttpResetClass, PagedList} from 'vue-client'
import Vue from 'vue'
import exportConfig from './exportConfig'

export default {
  'title': '小区楼栋信息汇总',
  data () {
    return {
      model: new PagedList('api/af-revenue/sql/areaBuildingInfoSummary', 20),
      showDetail: false,
      criteriaShow: false,
      condition: '',
      row: null,
      curorgid: [this.$login.f.orgid],
      f_filialeid: this.$login.f.orgid,
      userState: '',
      residentialArea: [],
      street: []
    }
  },
  ready () {
    this.$refs.paged.$refs.criteria.model.f_user_state = ['正常']
    this.getaddress()
  },
  methods: {
    getotherfooter () {
      this.other = []
      this.footer = []
      let otherInData = []
      otherInData.push(`导出时间: ${this.$login.toStandardTimeString()}`)
      this.other.push(otherInData)
    },
    clean () {
      this.showDetail = false
      this.row = null
      this.userState = ''
    },
    /**
     * 退出用户详细信息页面
     */
    cancel () {
      this.isShowDetailInfo = false
    },
    close () {
      this.clean()
    },
    hidden () {
      this.criteriaShow = !this.criteriaShow
    },
    search () {
      this.$refs.paged.$refs.criteria.search()
    },
    toDetail (row) {
      this.showDetail = true
      this.row = row
      this.userState = this.$refs.paged.$refs.criteria.model.f_user_state[0]
    },
    selfSearch (args) {
      if (!this.f_filialeid) {
        this.f_filialeid = this.$login.f.orgid
      }
      args.condition = `${args.condition} and ui.f_filialeid = '${this.f_filialeid}'`
      this.criteriaShow = false
      this.$refs.paged.$refs.grid.$el.scrollTop = 0
      this.condition = args.condition
      this.model.search(args.condition, args.model)
      this.clean()
    },
    clear () {
      Object.keys(this.$refs.paged.$refs.criteria.model).forEach((key) => {
        this.$refs.paged.$refs.criteria.model[key] = []
      })
    },
    getorg (val) {
      this.f_filialeid = val[0]
    },
    async  getaddress(){
      console.log('开始获取小区')
      let HttpReset = new HttpResetClass()
      var data = await HttpReset.load('POST', 'api/af-revenue/sql/manage_getarealist', {
        data: {
          condition: `1=1 and s.f_filialeid = '${this.$login.f.orgid}'`
        }
      }, {resolveMsg: null, rejectMsg: '获取小区失败!'})
      console.log('小区',data)
      let house = []
      for (let row of data.data){
        console.log('开始保存小区')
        house.push({label: row.f_residential_area, value: row.f_residential_area})
      }
      this.residentialArea = house
      let street= await HttpReset.load('POST', 'api/af-revenue/sql/manage_getstreetlist', {
        data: {
          condition: `1=1 and s.f_filialeid = '${this.$login.f.orgid}'`
        }
      }, {resolveMsg: null, rejectMsg: '获取区域失败!'})
      console.log('区域',data)
      let abc = []
      for (let row of street.data){
        console.log('开始保存区域')
        abc.push({label: row.f_street, value: row.f_street})
      }
      this.street = abc
    }
  },
  computed: {
    getCondition () {
      return {
        condition: this.condition
      }
    },
    getfield () {
      return exportConfig.areaBuildingInfoSummary
    },
    userstates () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('客户状态')]
    }
  },
  watch: {},
  events: {
    'clean' () {
      this.clean()
    }
  }
}
</script>
<style>
.nav-tabss ul > li > a {
  padding: 5px 10px;
}
</style>

