<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>
        <p class="bg-info text-center" style="padding: 8px;">咸阳其他收费汇总</p>
        <div class="form-group" v-if="!$parent.$parent.data.f_files_path"></div>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="col-sm-4">
              <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-4">
              <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>
            <div class="col-sm-4">
              <label class="font_normal_body">&emsp;&emsp;公司:</label>
              <right-tree @re-res="$parent.$parent.getRes"></right-tree>
            </div>
            <div class="col-sm-4" style="float:right;">
              <label class="font_normal_body">&nbsp;&nbsp;&nbsp;&emsp;&emsp;&nbsp;&nbsp;&nbsp;</label>
              <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'
                            v-if="$parent.$parent.jurisdiction.includes('excel导出')"
              ></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">
          <thead>
          <tr>
            <th colspan='17' style="font-weight: normal; text-align: left;">
              <h3 style="text-align: center">线上预约汇总</h3>
            </th>
          </tr>
          <tr>
            <th colspan='17' style="font-weight: normal; text-align: center;">
              开始时间：{{model.model.startDate}}&nbsp;&nbsp;&nbsp;
              结束时间：{{ model.model.endDate }}
            </th>
          </tr>
          <tr>
            <th colspan='17' style="font-weight: normal; text-align: center;">
              打印时间：{{{$parent.printTime}}}
            </th>
          </tr>
          <tr>
            <th colspan='17' 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='17'>
              {{{ model.data.substring(26,model.data.length-8) }}}
            </td>
          </tr>
        </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,
      jurisdiction: this.$login.r,
      operatorid: [],
      depid: [],
      orgname: '',
      depname: '',
      operatorname: '',
      f_inputtor: [],
      f_user_type: '',
      orgCondtionStr: '1=1',
      model: new DataModel('rs/report/orderCenter', {
        startDate: 'this.model.startDate',
        endDate: 'this.model.endDate',
        f_orgid: 'this.model.f_orgid'
      }),
      reportStr: null
    }
  },
  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: {
    searchData() {
      this.$refs.paged.$refs.criteria.search()
    },
    selfSearch(args) {
      console.log(args.condition + 'yyyqqq')
      this.printTime = this.$login.toStandardTimeString()
      let orgCondition = '1=1'
      if (this.f_orgid[0]) {
        let id = this.f_orgid.toString()
        let ids = id.split(',')
        console.log('几个公司:' + ids.length)
        let orgids = ''
        let f_orgids = ''
        if (ids.length === 1) {
          f_orgids += "'" + ids[0] + "'"
        } else {
          for (let i = 0; i < ids.length; i++) {
            console.log('id = ' + ids[i])
            orgids += "'" + ids[i] + "',"
          }
          f_orgids = orgids.substring(0, orgids.length - 1)
        }

        orgCondition += " and f_orgstr in ( " + f_orgids + " ) "
        console.log('f_orgids:' + f_orgids)
      }
      this.$refs.paged.$refs.criteria.model.f_orgid = orgCondition
      this.$refs.paged.search(args)
    },
    getRes(obj) {
      this.orgname = obj.res[0]
      this.depresid = obj.resids
      this.f_orgid = obj.resids
      this.userresid = obj.resids
    },
    getdep(obj, val) {
      this.depname = val[0]
      this.f_depid = obj
    },
    getuser(obj, val) {
      this.operatorname = val[0]
      this.f_operatorid = obj
    },
    // 根据文件路径获取储存的报表内容
    getFileContent(path) {
      this.$resetpost('rs/logic/getReportFileContent', {f_files_path: path}, {
        resolveMsg: null,
        rejectMsg: null
      }).then((res) => {
        this.reportStr = res.data.filecontent
        this.model.state = '正确'
      })
    },
    close() {
      this.show = false
    }
  },
  watch: {
    'data'(val) {
      if (val.f_files_path) {
        this.getFileContent(val.f_files_path)
      } else {
        this.reportStr = null
      }
    }
  },
  computed: {}
}
</script>
<style scoped>
.noborder {
  border: none;
}
</style>
