<template>
  <div id='app' class="basic-main">
    <criteria-paged :model="model" v-ref:paged :pager='false'>
      <criteria partial='criteria'  v-ref:criteria @condition-changed='search'>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="col-sm-4 form-group">
            <label class="font_normal_body">组织机构:</label>
            <right-tree :userid.sync='$parent.$parent.userid1' :source.sync='$parent.$parent.source1' @re-res="$parent.$parent.getRes" id="schildrenorgstyle"></right-tree>
            </div>
            <div class="col-sm-4 form-group">
            <label class="font_normal_body">&nbsp;&nbsp;&nbsp;置换员:</label>
            <v-select :value.sync="model.f_order_man" v-model="model.f_order_man" :value-single="true"
                      :options='$parent.$parent.repairers' placeholder='请选择置换员'
                      close-on-select></v-select>
            </div>
            <div class="col-sm-4 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 00:00:00'"
                        :show-reset-button="reset">
            </datepicker>
            </div>
            <div class="col-sm-4 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 23:59:59'"
                        :show-reset-button="reset">
            </datepicker>
            </div>
            <div class="span" style="float:right;">
              <button class="button_search" @click="$parent.$parent.selfsearch()">查询</button>
              <report-print id='shexian' top='1cm' left='1cm' width='100%' height='100%'></report-print>
              <report-excel id='shexian'></report-excel>
            </div>
          </div>
        </div>
      </criteria>
      <div partial='list' id='shexian'>
        <table class='tableprint' style="margin: 0px auto">
            <thead>
            <tr>
              <th colspan='5' style="font-weight: normal; text-align: left;">
                <h3 style="text-align: center">置换通气报表</h3>
              </th>
            </tr>
            <tr>
              <th colspan='5' style="font-weight: normal; text-align: center;">
                开始时间：{{model.model.startDate}}&nbsp;&nbsp;&nbsp;
                结束时间：{{ model.model.endDate }}&nbsp;&nbsp;
              </th>
            </tr>
            </thead>
            <tr>
            <th  colspan='5' style="font-weight: normal;">
              {{{ model.data.substring(26,model.data.length-8) }}}
            </th>
          </tr>
        </table>
      </div>
    </criteria-paged>
  </div>
</template>

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

  export default {
    title: '置换通气报表',
    data () {
      let model =  new DataModel('rs/report/zhihuanservice',{})
      model.f_subcompany = ''
      model.condition = '1=1'
      return {
        filialeNameStr:'',
        filialeCodeStr:'',
        userid: this.$login.f.id,
        source: `tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() == $organization$))`,
        source2:'this.getAllChildrens().where(row.getAttributes().get($rolestr$) == $置换员$))',
        userid2:'',
        model:model,
        f_filiale_id:'',
        repairers:[] //置换员数组
      }
    },
    methods: {
      selfsearch(args){
        let  condition = '1=1'
        condition += this.$refs.paged.$refs.criteria.model.startDate ? `and tb.f_created_date > '${this.$refs.paged.$refs.criteria.model.startDate}'` : ''
        condition += this.$refs.paged.$refs.criteria.model.endDate ? `and tb.f_created_date < '${this.$refs.paged.$refs.criteria.model.endDate}'` : ''
        condition += this.$refs.paged.$refs.criteria.model.f_order_man ? `and tb.f_order_man = '${this.$refs.paged.$refs.criteria.model.f_order_man}'` : ''
        condition += this.f_filiale_id ? `and tb.f_filiale_id = '${this.f_filiale_id}'` : ''
        this.$refs.paged.$refs.criteria.model.condition = condition
        this.model.search(condition)
      },

      // 获取组织结构
      getRes(obj) {
        // 获取到分公司ID传给 this.f_filiale_id
        this.f_filiale_id = obj.resids[0]?obj.resids[0]:this.$login.f.orgid
        console.log(this.f_filiale_id,'+++++++++=')
        //再根据公司获取置换员
        this.getEmp(this.f_filiale_id)
        let fengongsi=obj.res.toString().split('.')
        console.log(fengongsi,'se')
        console.log(fengongsi[fengongsi.length-1],'se')
        this.model.f_subcompany = obj.res
        console.log(this.model,'se')
      },
      getEmp (filiale) {
        this.repairers = []
        var source = "tool.getChildrenOfResName($置换员$).where(row.getString($orgid$)==$"+ filiale+"$)"
        var val = {source: source, userid: filiale}
        let http = new HttpResetClass()
        http.load('POST', '/rs/search', {data: val}, {resolveMsg: null, rejectMsg: null}).then((res) => {
          res.data.forEach((item) => {
          this.repairers.push({label: item.name, value: item.name})
      })
      })
      }
    },
    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'
    },
    computed: {
      selected() {
        return this.$refs.grid.selected
      }
      // outlets () {
      //   return [{label: '全部', value: ''}, ...AppData.getParam('营业网点')]
      // },
      // operator () {
      //   return [{label: '全部', value: ''}, ...AppData.getParam('操作员')]
      // }
    }
  }
</script>
