<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" for="startDate">开始日期:</label>
              <datepicker id="startDate" placeholder="开始日期" style="width: 60%"
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-2 form-group" >
              <label  class="font_normal_body" for="endDate">结束日期:</label>
              <datepicker id="endDate" placeholder="结束日期" style="width: 60%"
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <res-select-group :show-component="$parent.$parent.resshow"
                              :selectin="true" :initres="$parent.$parent.initres"
                              :cascade =true @re-res="$parent.$parent.getRes" v-ref:sel>
            </res-select-group>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body" title="参数：报表1收费类型">收费类型</label>
              <v-select :value.sync="$parent.$parent.f_charge_type"
                        v-ref:f_charge_type
                        v-model="$parent.$parent.f_charge_type"
                        :options='$parent.$parent.chargeTypes'
                        placeholder='请选择'
                        :multiple="true">
              </v-select>
            </div>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body" title="参数：报表1用气性质">用气性质</label>
              <v-select :value.sync="$parent.$parent.f_gasproperties"
                        v-ref:gasproperties
                        v-model="$parent.$parent.f_gasproperties"
                        :options='$parent.$parent.gasproperties'
                        placeholder='请选择'
                        :multiple="true">
              </v-select>
            </div>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body" title="参数：付款方式">收费方式</label>
              <v-select :value.sync="$parent.$parent.f_payment"
                        v-ref:payment
                        v-model="$parent.$parent.f_payment"
                        :options='$parent.$parent.payments'
                        placeholder='请选择'
                        :multiple="true">
              </v-select>
            </div>
          </div>
          <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>
      </criteria>
      <div  partial='list' v-el:handcollect id='gasprice' style="overflow-y: scroll">
        <table class='tableprint' style="margin: 0px auto">
          <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}}}-->
              打印时间：{{$parent.printTime}}
              <!--收费员：{{// $parent.operatorname}}-->
            </th>
          </tr>
          <tr>
            <th :colspan='$parent.spans' style="font-weight: normal; text-align: center;">
              <div>
                <span style="font-weight: normal;text-align: center;margin:5px 15px" v-show="$parent.orgname">公司：{{$parent.orgname}}</span>
                <span v-show="$parent.depname"> 部门：{{$parent.depname}}</span>
                <span style="font-weight: normal;text-align: center;margin:5px 15px" v-show="$parent.operatorname">人员：{{$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>
  </div>
</template>

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

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: '',
      f_charge_type: '',
      f_gasproperties: '',
      f_payment: '',
      criteriaShow: false,
      operatorname: '',
      orgCondtionStr: '1=1',
      model: new DataModel('api/af-revenue/report/dayReport', {
        startDate: 'this.model.startDate',
        endDate: 'this.model.endDate',
        f_orgid: 'this.model.f_orgid',
        f_charge_type: 'this.model.f_charge_type',
        f_gasproperties: 'this.model.f_gasproperties',
        f_payment: 'this.model.f_payment'
      }),
      reportStr: null,
      resshow: ['company', 'department', 'operator'],
      spans: 0,
      initres: {
        org: [this.$login.f.orgid],
        dep: [],
        user: []
      }
    }
  },
  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'
    console.log(this.$login.f)
  },
  methods: {
    searchData () {
      this.$refs.paged.$refs.criteria.search()
    },
    appendCondition (data) {
      let stringValue = '('
      for (let i = 0; i < data.length; i++) {
        if (data[i]) {
          if (i === data.length - 1) {
            stringValue = stringValue + "'" + data[i] + "'"
          } else {
            stringValue = stringValue + "'" + data[i] + "',"
          }
        }
      }
      stringValue = stringValue + ')'
      return stringValue
    },
    selfSearch (args) {
      if (this.f_charge_type.length > 0) {
        this.$refs.paged.$refs.criteria.model.f_charge_type = this.appendCondition(this.f_charge_type)
      } else {
        this.$refs.paged.$refs.criteria.model.f_charge_type = ''
      }
      if (this.f_gasproperties.length > 0) {
        this.$refs.paged.$refs.criteria.model.f_gasproperties = this.appendCondition(this.f_gasproperties)
      } else {
        this.$refs.paged.$refs.criteria.model.f_gasproperties = ''
      }
      if (this.f_payment.length > 0) {
        this.$refs.paged.$refs.criteria.model.f_payment = this.appendCondition(this.f_payment)
      } else {
        this.$refs.paged.$refs.criteria.model.f_payment = ''
      }
      this.printTime = this.$login.toStandardTimeString()
      let orgcondition = '1=1'
      let orgstr = this.orgCondtionStr
      orgcondition = orgcondition + orgstr
      this.$refs.paged.$refs.criteria.model.f_orgid = orgcondition
      this.$refs.paged.search(args)
    },
    hidden () {
      this.criteriaShow = !this.criteriaShow
    },
    getRes (condition, obj) {
      this.orgCondtionStr = condition
      this.orgname = obj.orgnames[0]
      this.depname = obj.depnames[0]
      this.operatorname = obj.operatornames[0]
    },
    getdep (obj, val) {
      this.depname = val[0]
      this.userresid = obj
      this.f_depid = obj
    },
    getuser (obj, val) {
      this.operatorname = val[0]
      this.f_operatorid = obj
    }
  },
  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: {
    payments () {
      return this.$appdata.getParam('付款方式')
    },
    gasproperties () {
      return this.$appdata.getParam('报表1用气性质')
    },
    chargeTypes () {
      return this.$appdata.getParam('报表1收费类型')
    }
  }
}
</script>
<style scoped>
.noborder{
  border: none;
}
</style>
