<template>
  <div class="basic-main" style="height: 100%">
    <criteria-paged :model="model" :pager='false' v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:criteria>
        <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>
              <v-select :value.sync="model.f_gasproperties"
                        :multiple="true"
                        v-model="model.f_gasproperties"
                        :options='$parent.$parent.gasPropertyTypes'
                        placeholder='请选择'
                        condition=" s.f_gasproperties in {}">
              </v-select>
            </div>
            <res-select-group :show-component="['company']" :initres="$parent.$parent.initres"  @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
            <div class="span" style = "float:right;">
              <button class="button_search" @click="$parent.$parent.searchData()">查询</button>
              <report-print id='gasprice' top='3cm' left='0' width='100%' height='100%' :preview="true"></report-print>
              <report-excel id='gasprice'></report-excel>
            </div>
          </div>
        </div>
      </criteria>
      <div  partial='list' v-el:handcollect id='gasprice' style="overflow-y: scroll">
        <table class='tableprint' style="margin: 0px auto"  v-if="!$parent.data.f_files_path">
          <thead>
          <tr>
            <th :colspan='$parent.spans' style="font-weight: normal; text-align: left;">
              <h3 style="text-align: center">用户详情统计表</h3>
            </th>
          </tr>
          <tr>
            <th :colspan='$parent.spans' style="font-weight: normal; text-align: center;">
<!--              开始时间：{{model.model.startDate}}&nbsp;&nbsp;&nbsp;-->
<!--              结束时间：{{ model.model.endDate }}&nbsp;&nbsp;<br/>-->
<!--              打印时间：{{{$parent.printTime}}}-->
            </th>
          </tr>
          <tr>
            <th :colspan='$parent.spans' style="font-weight: normal; text-align: center;">
              <div>
                <span v-show="$parent.orgname.trim()!=''">公司：{{$parent.orgname}}</span>
                <span v-show="$parent.depname.trim()!=''"> 部门：{{$parent.depname}}</span>
                <span v-show="$parent.operatorname.trim()!=''">人员：{{$parent.operatorname}}</span>
              </div>
            </th>
          </tr>
          </thead>
          <tr>
            <td :colspan='$parent.spans'  class="noborder">
              {{{ model.data.substring(26,model.data.length-8) }}}
            </td>
          </tr>
          <tfoot>
          <tr style="text-align: left">
            <th :colspan='Math.floor($parent.spans/3)'>财务审核：</th>
            <th :colspan='Math.floor($parent.spans/3)'>收款审核：</th>
            <th :colspan='Math.floor($parent.spans/3)'>收款员：</th>
          </tr>
          </tfoot>
        </table>
        {{{ $parent.reportStr}}}
      </div>
    </criteria-paged>
    <modal :show.sync="show" v-ref:modal small backdrop="false">
      <header slot="modal-header" class="modal-header">
        <h4 class="modal-title">输入文件名称</h4>
      </header>
      <article slot="modal-body" class="modal-body">
        <div class="form-group">
          <input  type="text" class="form-control" v-model="filename" placeholder='保存的文件名'>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button v-show="show" type="button" class="btn btn-default" @click='close'>取消</button>
        <button v-show="show" type="button" class="btn btn-success" @click='confirm(filename)'>确认</button>
      </footer>
    </modal>
  </div>
</template>

<script>
import { DataModel } from 'vue-client'

export default {
  title: '用户详情统计表',
  props: ['data'],
  data () {
    return {
      printTime: this.$login.toStandardTimeString(),
      depresid: [],
      userresid: [],
      f_orgid: this.$login.f.orgid,
      f_depid: this.$login.f.depids,
      f_operatorid: this.$login.f.id,
      operatorid: [],
      depid: [],
      orgname: '',
      depname: '',
      initres: {
        org: [this.$login.f.orgid],
        dep: [],
        user: []
      },
      orgCondtionStr: '1=1',
      operatorname: '',
      model: new DataModel('api/af-revenue/report/tc_userSummaryReport', {startDate: 'this.model.startDate', endDate: 'this.model.endDate',
        f_orgid: 'this.model.f_orgid'}),
      reportStr: null,
      spans: 0
    }
  },
  ready () {
    // this.$refs.paged.$refs.criteria.model.startDate = this.$login.toStandardDateString() + ' 00:00:00'
    // this.$refs.paged.$refs.criteria.model.endDate = this.$login.toStandardDateString() + ' 23:59:59'
    // this.$refs.paged.$refs.criteria.search()
    console.log(this.$login.f)
  },
  methods: {
    getRes (condition, obj) {
      this.orgCondtionStr = condition.replace('f_orgid', 'ui.f_orgid')
      this.orgCondtionStr = this.orgCondtionStr.replace('f_depid', 'ui.f_depid')
      this.orgCondtionStr = this.orgCondtionStr.replace('f_operatorid', 'ui.f_operatorid')
      this.orgname = obj.orgnames[0]
      this.depname = obj.depnames[0]
    },
    searchData () {
      this.$refs.paged.$refs.criteria.search()
    },
    selfSearch (args) {
      this.$refs.paged.$refs.criteria.model.f_orgid = args.condition + this.orgCondtionStr
      this.$refs.paged.search(args)
    }
  },
  watch: {
    'model.data' (val) {
      let len=0
      let a=val.split('</tr>')
      for(let i=0;i<a.length;i++){
        if(a[i].split('</td>').length-1>len){
          len=a[i].split('</td>').length-1
        }
      }
      this.spans = len
    }
  },
  computed: {
    gasPropertyTypes () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
    }
  }
}
</script>
<style scoped>
.noborder{
  border: none;
}
</style>
