<template>
  <div id="unit" class="flex-row">
    <div class="basic-main" @keyup.enter="search">
      <div class="flex">
        <div style="flex:1;" class="flex" v-if="!show">
          <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="col-sm-2 form-group">
                    <label class="font_normal_body">企业名称</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.f_userinfo_code"
                           condition="ui.f_paper_name = '{}' " placeholder="企业名称">
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">信用代码</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.f_user_name"
                           condition="ui.f_taxpayer_id = '{}'" placeholder="客户名称">
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">燃气户号</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.f_olduserinfo_code"
                           condition="ui.f_userinfo_code = '{}' " placeholder="燃气户号">
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">联系方式</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.f_address_phone"
                           condition="ui.f_address_phone = '{}'" placeholder="联系方式">
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">燃气公司标志</label>
                    <input type="text" style="width:60%" class="input_search" v-model="model.f_orgname"
                           condition="ui.f_orgname = '{}'" placeholder="燃气公司标志">
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">客户类型</label>
                    <v-select :value.sync="model.f_user_type"
                              @change="$parent.$parent.userTypeChange()"
                              :options='$parent.$parent.usertypes' placeholder='请选择' v-model="model.f_user_type"
                              condition="f_user_type = '{}'"
                              close-on-select></v-select>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">用气性质</label>
                    <v-select :value.sync="model.f_gasproperties" v-model="model.f_gasproperties"
                              :options='$parent.$parent.gasproperties' placeholder='请选择'
                              condition="f_gasproperties = '{}'"
                              close-on-select></v-select>
                  </div>
                  <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>
                    <export-excel :data="$parent.$parent.getCondition" :field="$parent.$parent.getExportField"
                                  :header="$parent.$parent.other" sqlurl="api/af-revenue/logic/openapi/exportfile"
                                  sql-name="enterpriseGasQuery" :choose-col="true"
                                  template-name='企业收费查询'></export-excel>
                    <print-data :sum-field="$parent.$parent.getExportField" :model="$parent.model"
                                :field="$parent.$parent.getExportField" :defaultfield="$parent.$parent.defaultfield"
                                titletable="企业收费查询"></print-data>
                    <div style="float: right" class="button_spacing"
                         :class="{ 'button_shrink_top': $parent.$parent.criteriaShow, 'button_shrink_bottom': !$parent.$parent.criteriaShow }"
                         @click="$parent.$parent.hidden()"></div>
                  </div>
                </div>
                <div class="row" v-show="$parent.$parent.criteriaShow">
                  <res-select-group :initres="$parent.$parent.initres"
                                    :show-component="['company']"
                                    @re-res="$parent.$parent.getRes"></res-select-group>
                  <div class="col-sm-2 form-group">
                    <label for="startDate" class="font_normal_body">抄表日期</label>
                    <datepicker id="startDate" placeholder="开始日期" style="width:60%" v-model="model.startDate"
                                :value.sync="model.startDate" :format="'yyyy-MM-dd'" :show-reset-button="true"
                                condition="h.f_input_date >= '{} 00:00:00'">
                    </datepicker>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label for="endDate" class="font_normal_body">抄表日期</label>
                    <datepicker id="endDate" placeholder="结束日期" style="width:60%" v-model="model.endDate"
                                :value.sync="model.endDate" :format="'yyyy-MM-dd'" :show-reset-button="true"
                                condition="h.f_input_date <= '{} 23:59:59'">
                    </datepicker>
                  </div>
                </div>
              </div>
            </criteria>

            <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy"
                       :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>
                </tr>
              </template>
              <template partial='body'>
                <td style="text-align: center;">
                  <nobr>
                    {{ $index }}
                  </nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>
                    {{ row.f_paper_name }}
                  </nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>
                    {{ row.f_taxpayer_id }}
                  </nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>
                    {{ row.f_orgname }}
                  </nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>
                    <span @click="$parent.$parent.$parent.showmsg(row)"><a>{{ row.f_userinfo_code }}</a></span>
                  </nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>
                    {{ row.f_oughtamount }}
                  </nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>
                    {{ row.f_oughtfee }}
                  </nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>
                    {{ row.f_whether_pay }}
                  </nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>
                    {{ row.f_input_date }}
                  </nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>
                    {{ row.f_address_phone }}
                  </nobr>
                </td>
                <td style="text-align: center;">
                  <nobr>
                    {{ row.f_gasproperties }}
                  </nobr>
                </td>
              </template>
              <template partial='foot'>
              </template>
            </data-grid>
          </criteria-paged>
        </div>
        <div class="flex" v-if="show">
          <user-info-detail-manage-new :f_userinfo_id="rowdata.f_userinfo_id"
                                       @cancel-main="cancel"></user-info-detail-manage-new>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {PagedList} from 'vue-client'
import exportConfig from './config/exportConfig'


let readySomething = async function (self) {
  self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString()
  self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString()
  self.defaultfield = [...self.defaultfield, ...self.config.defaultPrint]
}

export default {
  title: '用气查询',
  data() {
    return {
      other: [],
      footer: [],
      model: new PagedList('api/af-revenue/sql/enterpriseGasQuery', 20,
        {startDate: 'this.model.startDate', endDate: 'this.model.endDate'}),
      criteriaShow: false,
      orgCondtionStr: '',
      modelval: [],
      printshow: false,
      all: false,
      fields: {},
      thead: '',
      tfoot: '',
      initres: {
        org: [this.$login.f.orgid],
        dep: [],
        user: [],
      },
      whetherPay: [{label: '全部', value: ''},
        {label: '是', value: '是'},
        {label: '否', value: '否'}],
      gasproperties: [],
      show: false,
      rowdata: {},
      //默认打印列
      defaultfield: [],
      config: {
        defaultPrint: []
      },
    }
  },
  ready() {

    readySomething(this).then(() => {
      this.$emit('ready')
    }).catch((error) => {
      this.$emit('error', error)
    })
  },
  methods: {
    getotherfooter() {
      // this.$refs.paged.$refs.cri.$refs.exports.otherData = [];
      // this.$refs.paged.$refs.cri.$refs.exports.footerData = [];
      this.other = [];
      this.footer = [];
      let exportdata = this.getCondition;
      let otherInData = [];
      otherInData.push(`导出时间: ${this.$login.toStandardTimeString()}`);
      // let footerData = [], exportfield = this.getExportField;
      // 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()
    },
    cancel() {
      this.show = false
    },
    userTypeChange() {
      this.gasproperties = []
      if (this.$refs.paged.$refs.cri.model !== null) {
        this.$refs.paged.$refs.cri.model.f_gasproperties = ''
        this.gasproperties = this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_user_type)
      } else {
        this.gasproperties = [{label: '全部', value: ''}]
      }
    },
    showmsg(obj) {
      this.rowdata = obj
      this.show = true
    },
    selfSearch(args) {
      if (!this.orgCondtionStr) {
        args.condition = `${args.condition}` + " and f_orgid = " + this.$login.f.orgid
      } else {
        args.condition = `${args.condition}` + this.orgCondtionStr
      }
      this.model.search(args.condition, args.model)
    },
    clear() {
      Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
        this.$refs.paged.$refs.cri.model[key] = []
      })
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    async getRes(condition) {
      this.orgCondtionStr = condition

    },
    print() {
      this.$refs.print.PrintAsFile()
      this.printshow = false
    },
    close() {
      this.printshow = false
      this.all = false
    },
    // 对选择的列进行排序
    sortModelval() {
      let sortModel = []
      Object.keys(this.fields).forEach((key) => {
        if (this.modelval.includes(key)) {
          sortModel.push(key)
        }
      })
      this.modelval = sortModel
      console.log('选择的打印的字段', this.modelval)
    },
    async initSlice(val) {
      if (val) {
        let getAllArea = await this.$resetpost('/rs/search', {
          source: 'this.getParentByType($organization$).getAllChildrens().where(row.getType() == $zone$)',
          userid: this.$login.f.id
        }, {resolveMsg: null, rejectMsg: '获取片区出错！！！'})
        let arr = getAllArea.data.filter((res) => {
          return res.parentid == val
        })
        this.bookSlice = []
        console.log('过滤之后的片区-------------------', arr)
        arr.forEach((res) => {
          this.bookSlice.push({label: res.name, value: res.name})
        })
      }
    }
  },
  watch: {
  },
  computed: {
    getCondition() {
      return {
        condition: `${this.$refs.paged.$refs.cri.condition}`,
        startDate: this.$refs.paged.$refs.cri.model.startDate,
        endDate: this.$refs.paged.$refs.cri.model.endDate,
      }
    },
    getExportField() {
      return exportConfig.enterpriseGasConfig
    },
    usertypes() {
      return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('用户类型')]
    }
  }
}

</script>

