<template>
  <div id='app' class="basic-main" style="height: 100%">
    <criteria-paged :model="model" :pager='false' v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' class="search_area" 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 for="startDate" class="font_normal_body">开始时间</label>
              <datepicker id="startDate" placeholder="开始日期"
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          style="width: 60%;"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd 00:00:00'"
                          @change="$parent.$parent.onStartDateChange">
              </datepicker>
            </div>
            <div class="col-sm-2 form-group">
              <label for="endDate" class="font_normal_body">结束时间</label>
              <datepicker id="endDate" placeholder="结束日期"
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :disabled-days-of-Week="[]"
                          style="width: 60%;"
                          :format="'yyyy-MM-dd 23:59:59'">
              </datepicker>
            </div>
            <div class="col-sm-2 form-group" >
              <label class="font_normal_body">分公司</label>
              <right-tree-safe width="60%" @re-res="$parent.$parent.getRes"></right-tree-safe>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">区域</label>
              <v-select class="select_list select"
                        placeholder='请选择' style="width: 60%"
                        :value.sync="model.f_pcd" v-model="model.f_pcd"
                        :options='$parent.$parent.pcds'
                        filer-key="name"
                        clear-button
                        condition="tud.f_pcd in {}"
                        :multiple="true">
              </v-select>
            </div>
            <div class="form-group col-sm-2"  >
              <label class="font_normal_body">街道</label>
              <input type="text" class="input_search" v-model="model.f_street"
                     style="width: 60%" placeholder="街道" condition="cp.f_street like '%{}%'">
            </div>
            <div class="col-sm-2 form-group" >
              <label class="font_normal_body">用气性质</label>
              <v-select
                class="select_list select"
                placeholder='用气性质' style="width: 60%"
                v-model='model.userType'
                :value.sync="model.userType"
                :options='$parent.$parent.userTypes'
                condition="uf.f_gasproperties = '{}'"
                :value-single="true"
                close-on-select clear-button></v-select>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-4 form-group" style="margin-top: 8px">
              <button class="button_search button_spacing" @click="search">查询</button>
              <report-print class="button_export button_spacing" style="width:28%" id='shexian'></report-print>
              <report-excel class="button_export button_spacing" style="width:28%" id='shexian'></report-excel>
            </div>
          </div>
        </div>
      </criteria>
      <div partial='list' id='shexian' class="list_area" style="overflow-y: scroll">
        <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 }}
            </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, HttpResetClass} from 'vue-client'
import * as Util from '../Util'

export default {
  title: '隐患闭环报表',
  data () {
    let model = new DataModel('rs/report/yinHuanBiHuan', {
      startTime1: 'this.model.startDate1',
      startTime2: 'this.model.startDate',
      endTime: 'this.model.endDate'
    })
    return {
      userTypes: [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')],
      model: model,
      f_filialeid: '',
      pcds: []
    }
  },
  methods: {
    getRes (obj) {
      this.f_filialeid = this.$login.convertToIn(obj.resids)
      this.getPcds(this.f_filialeid)
      this.$refs.paged.$refs.cri.model.f_pcd = []
    },
    getPcds(val) {
      this.pcds = [{label: '全部', value: ''}]
      new HttpResetClass().load("POST", `/rs/sql/safe_singleTable_OrderBy`,
        {data: {items: "*", tablename: "t_pcd", orderitem: "id", condition: `f_orgid in ${val}`}},
        {resolveMsg: null, rejectMsg: null}).then((pcdlist) => {
        pcdlist.data.forEach((result) => {
          this.pcds.push({label: result.f_pcd, value: result.f_pcd})
        })
      })
    },
    selfSearch(args) {
      if(this.f_filialeid){
        args.condition += ` and cp.f_filialeid in ${this.f_filialeid}`
      }
      return this.model.search(args.condition, args.model, args.condValue)
    },
    onStartDateChange(val) {
      console.log('val=', val)
      this.$refs.paged.$refs.cri.model.startDate1 = `${new Date(val).getFullYear() - 4}-01-01 00:00:00`
    }
  },
  ready () {
    this.$refs.paged.$refs.cri.model.startDate = Util.toStartDateString() + ' 00:00:00'
    this.$refs.paged.$refs.cri.model.startDate1 = `${new Date().getFullYear() - 4}-01-01 00:00:00`
    this.$refs.paged.$refs.cri.model.endDate = Util.toEndDateString() + ' 23:59:59'
  },
}
</script>
