<template>
  <div id="unit" class="flex-row">
    <div class="basic-main" @keyup.enter="search">
      <criteria-paged :model="model" v-ref:paged>
        <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="row">
              <div class="span" style="float:right;">
                <!--                  <button class="button_search button_spacing" @click="search()">查询</button>-->
                <!--                  <button class="button_clear  button_spacing" @click="$parent.$parent.clear()">清空</button>-->
                <button class="button_clear  button_spacing" @click="$parent.$parent.cancel()">返回</button>
              </div>
              <!--                  <export-excel :data="$parent.$parent.getCondition"-->
              <!--                                :field="$parent.$parent.getfield"-->
              <!--                                :header="$parent.$parent.other"-->
              <!--                                :footer="$parent.$parent.footer"-->
              <!--                                sqlurl="api/af-revenue/logic/openapi/exportfile"-->
              <!--                                sql-name="manage_companyGasSummary"-->
              <!--                                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"-->
              <!--                              :sumsmodel="$parent.$parent.sumsmodel"></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>
        </criteria>
        <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid :classname="$parent.classname">
          <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>
              <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">
              <nobr>{{ $index + 1 }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.f_userinfo_code }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_user_name }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_meter_brand }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_meternumber }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_user_usetype }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_use_institution }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_user_usenature }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_gasproperties }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_oughtamount }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_pregas }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_user_phone }}</nobr>
            </td>
            <td style="text-align: center;">
              <nobr>{{ row.f_table_state }}</nobr>
            </td>
          </template>
          <template partial='foot'></template>
        </data-grid>
      </criteria-paged>
      <!--        <table class="table-hover">-->
      <!--          <tr style="position: relative" class="table-bordered">-->
      <!--            <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;color: #5CB95C;font-weight: bold">-->
      <!--              汇总信息-->
      <!--            </td>-->
      <!--            <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">-->
      <!--              用气量:&emsp;{{ sumsmodel.f_oughtamount }}m³-->
      <!--            <' and f_user_usetype in (\'居民用气\')'d style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">-->
      <!--            ' and f_user_usetype in (\'公福用气\',\'商业用户\',\'工业用户\')'  <!--            </td>-->
      <!--          </tr>-->
      <!--        </table>-->
    </div>
  </div>
</template>
<script>
import {PagedList} from 'vue-client'
import exportConfig from './config/exportConfig'

export default {
  title: '单位表具详情',
  data () {
    return {
      depresid: [],
      userresid: [],
      f_orgid: this.$login.f.orgid,
      f_depid: this.$login.f.depids,
      f_operatorid: this.$login.f.id,
      operatorid: [],
      depid: [],
      orgname: '',
      depname: [],
      operatorname: '',
      condition: '',
      orgConditionStr: '',
      data: {},
      other: [],
      footer: [],
      model: new PagedList('api/af-revenue/sql/manage_companyMeterDetail', 20, {
        startDate: 'this.model.startDate',
        endDate: 'this.model.endDate'
      }),
      gasproperties: [],
      show: false,
      rowdata: {},
      areaList: [],
      modelval: [],
      startDate: '',
      endDate: '',
      inputtouPerson: [],
      printshow: false,
      all: false,
      fields: {},
      thead: '',
      tfoot: '',
      defaultfield: [],
      sumsmodel: {},
      sumExport: {'f_oughtamount': '期间用气量', 'f_pregas': '期间售气量'},
      initres: {
        org: [this.$login.f.orgid]
      },
      criteriaShow: false,
      userusetypes: [],
      useinstitutions: [],
      userusenatures: [],
      corporatename: []
    }
  },
  ready () {
    this.search()
  },
  props: ['data'],
  methods: {
    clear () {
      // 清空部门和人员
      this.$refs.paged.$refs.cri.$refs.sel.$children[1].selectres = []
      // 部门和人员变为全选
      this.$refs.paged.$refs.cri.$refs.sel.$children[1].$children[0].isSelectAll = false
      this.$refs.paged.$refs.cri.$refs.sel.$children[2].$children[0].isSelectAll = false
      Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
        this.$refs.paged.$refs.cri.model[key] = []
      })
    },
    getotherfooter () {
      this.other = []
      this.footer = []
      let exportdata = this.getCondition
      let otherInData = []
      otherInData.push(`导出时间: ${this.$login.toStandardTimeString()}`)
      let footerData = [], exportfield = this.sumExport
      footerData.push('合计')
      let self = this
      for (var field in self.sumsmodel) {
        footerData.push(`${exportfield[field]}合计:${self.sumsmodel[field]}`)
      }
      this.footer.push(footerData)
      this.other.push(otherInData)
    },
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    selfSearch (args) {
      args.condition = `${args.condition} and f_corporate_name_id = '${this.data.id}'`
      this.$refs.paged.$refs.cri.model.startDate = this.data.startDate
      this.$refs.paged.$refs.cri.model.endDate = this.data.endDate
      if (this.data.f_user_type == '民用' && !this.data.f_user_usetype) {
        args.condition = args.condition + " and f_user_usetype in ('居民用气')"
      } else if (this.data.f_user_type == '非民用' && !this.data.f_user_usetype) {
        args.condition = args.condition + " and f_user_usetype in ('公福用气','商业用户','工业用户')"
      }
      if (this.data.f_user_usetype) {
        args.condition = args.condition + ` and f_user_usetype in (${this.data.f_user_usetype})`
      }
      if (this.data.f_user_usenature) {
        args.condition = args.condition + ` and f_user_usenature in ('${this.data.f_user_usenature}')`
      }
      if (this.data.f_use_institution) {
        args.condition = args.condition + ` and f_use_institution in ('${this.data.f_use_institution}')`
      }
      this.condition = args.condition
      console.log('查看条件', this.condition)
      this.model.search(args.condition, args.model)
    },
    getRes (obj) {
      this.orgConditionStr = obj
    },
    cancel () {
      this.data = null
      this.$dispatch('cancel')
    }
  },
  watch: {
    'data' (val) {
      if (val) {
        this.search()
      }
    }
  },
  computed: {
    getCondition () {
      return {
        condition: this.condition,
        startDate: this.$refs.paged.$refs.cri.model.startDate,
        endDate: this.$refs.paged.$refs.cri.model.endDate
      }
    },
    getfield () {
      return exportConfig.manageCompanyGasSummary
    }
  }
}
</script>

