<template>
  <div id="unit" class="flex-row">
    <div class="basic-main" @keyup.enter="search">
      <div class="flex" v-if="!show">
        <criteria-paged :model="model" v-ref:paged>
          <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
            <div novalidate class="form-inline auto" partial>
              <div class="row">
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">操作人</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_operator"
                         condition="tr.f_operator = '{}' " placeholder="操作人">
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">操作类型</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_operat_type"
                         condition="f_operat_type like '%{}%'" placeholder="操作类型">
                </div>
                <div class="col-sm-4 form-group">
                  <label  class="font_normal_body">操作日期</label>
                  <datepicker id="startDate" placeholder="操作日期" style="width:60%"
                              v-model="model.startDate"
                              :value.sync="model.startDate"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              :show-reset-button="true"
                              condition="tr.f_operate_date >= to_date('{}','yyyy-mm-dd hh24:mi:ss')">
                  </datepicker>

                <label for="startDate" class="font_normal_body">至</label>

                  <datepicker id="endDate" style="width:60%"
                              v-model="model.endDate"
                              :value.sync="model.endDate"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              :show-reset-button="true"
                              condition="tr.f_operate_date <= to_date('{}','yyyy-mm-dd hh24:mi:ss')">
                  </datepicker>
                </div>
                <div class="span" style="float:right;">
                  <button class="button_search button_spacing" @click="search()">查询</button>
                  <export-excel :data="$parent.$parent.getCondition"
                                :field="$parent.$parent.getfield"
                                sqlurl="rs/logic/exportfile" sql-name="GMHgasQuery" template-name='日志查询导出'
                                v-if ="$parent.$parent.jurisdiction.includes('excel导出')"
                                :choose-col="true"></export-excel>

                </div>
              </div>
              <div class="row">
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">房产地址</label>
                  <input class="input_search" condition="f_house_address = '{}'"
                         placeholder='房产地址'
                         style="width:60%" type="text" v-model="model.f_house_address">
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">用途</label>
                  <input class="input_search" condition="f_property_usage = '{}'"
                         placeholder='用途'
                         style="width:60%" type="text" v-model="model.f_property_usage">
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">房型</label>
                  <input class="input_search" condition="f_house_type = '{}'"
                         placeholder='房型'
                         style="width:60%" type="text" v-model="model.f_house_type">
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">是否一户多表</label>
                  <input class="input_search" condition="f_is_multi_meter = '{}'"
                         placeholder='是否一户多表'
                         style="width:60%" type="text" v-model="model.f_is_multi_meter">
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">关联ID</label>
                  <input class="input_search" condition="f_house_id = '{}'"
                         placeholder='关联ID'
                         style="width:60%" type="text" v-model="model.f_house_id">
                </div>
              </div>

            </div>
          </criteria>
          <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid :classname="$parent.classname">
            <template partial='head'>
              <tr>
                <th>
                  <nobr>操作人</nobr>
                </th>
                <th>
                  <nobr>功能描述</nobr>
                </th>
                <th>
                  <nobr>操作时间</nobr>
                </th>
                <th>
                  <nobr>操作类型</nobr>
                </th>
                <th>
                  <nobr>操作原因</nobr>
                </th>
                <th>
                  <nobr>登录/退出</nobr>
                </th>
                <th>
                  <nobr>公司</nobr>
                </th>
                <th>
                  <nobr>部门</nobr>
                </th>

              </tr>
            </template>
            <template partial='body'>
              <td style="text-align: center;">
                <nobr>{{ row.f_operator }}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{ row.f_describe }}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{ row.f_operate_date }}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{ row.f_operat_type }}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{ row.f_comments }}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{ row.type }}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{ row.f_orgname }}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{ row.f_depname }}</nobr>
              </td>
            </template>
            <template partial='foot'></template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>

  </div>
</template>
<script>
  import {HttpResetClass, PagedList} from 'vue-client'
  import defaultPrint from '../config/DefaultPrint'
  import exportConfig from '../config/exportConfig'

  let readySomething = async function (self) {
    self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString() + ' 00:00:00'
    self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString() + ' 23:59:59'
    await self.$MagLoadParams.loadParam()
    self.initParams()
  }
  export default {
    title: '日志查询',
    name: 'AddMaterial',
    data() {
      return {

        model: new PagedList('rs/sql/LogQuery', 30, {}),
        initres: {
          org: [this.$login.f.orgid],
          dep: [],
          user: [],
        },
        gasproperties: [],
        orgCondtionStr: '',
        show: false,
        rowdata: {},
        criteriaShow: false,
        jurisdiction: this.$login.r,
        modelval: [],
        printshow: false,
        showComponent: ['company', 'department', 'operator'],
        all: false,
        fields: {},
        thead: '',
        tfoot: '',
        residentialArea: [],
        //合计数据
        sumsmodel: {},
        defaultfield: [],
        metertype: [{label: '全部', value: ''}, {label: '卡表', value: '卡表'}, {label: '机表', value: '机表'}]
      }
    },
    ready() {
      readySomething(this)
    },
    methods: {
      userTypeChange() {
        this.gasproperties = []
        if (this.$refs.paged.model.model !== null) {
          this.$refs.paged.model.model.f_gasproperties = ''

          console.log(this.$refs.paged.model.model.f_user_type[0])
          this.gasproperties = this.$appdata.getParam(this.$refs.paged.model.model.f_user_type[0])
          // this.gasproperties.push({label: '全部', value: ''})
        } else {
          this.gasproperties = [{label: '全部', value: ''}]
        }
      },
      search() {
        this.$refs.paged.$refs.cri.search()
      },
      cancel() {
        this.show = false
      },
      selfSearch(args) {
        args.condition = `${args.condition}` + this.orgCondtionStr
        this.model.search(args.condition, args.model)
        this.sumsmodel = this.$refs.paged.$refs.grid.model.sums
      },

      show() {
        this.criteriaShow = true
      },

      stamp() {
        this.all = false
        //默认选择要打印的列
        this.modelval = defaultPrint.config
        this.fields = this.getfield
        console.log('所有打印字段', this.fields)
        this.printshow = true
        this.put()
      },
      put() {
        // 对Modelval进行排序
        this.sortModelval()
        this.thead = `<tr><th colspan=${this.modelval.length}>收费查询统计报表</th></tr><tr>`
        for (let key of this.modelval) {
          this.thead += '<th>' + this.fields[key] + '</th>'
        }
        this.thead += '</tr>'
      },
      print() {
        this.$refs.print.PrintAsFile()
        this.printshow = false
      },

      getRes(obj) {
        this.orgCondtionStr = obj
      },
      close() {
        this.printshow = false
        this.all = false
      },
      // 对选择的列进行排序
      sortModelval() {
        let sortModel = []
        Object.keys(this.fields).forEach((key) => {
          if (this.modelval.includes(key)) {
            sortModel.push(key)
          }
        })
        this.modelval = sortModel
        console.log('选择的打印的字段', this.modelval)
      }

    },
    computed: {
      getCondition() {
        return {condition: `${this.$refs.paged.$refs.cri.condition}` + this.orgCondtionStr,startDate:`${this.$refs.paged.$refs.cri.model.startDate}`,
          endDate:  `${this.$refs.paged.$refs.cri.model.endDate}`}
      },
      getfield() {
        return exportConfig.logConfig
      },
      usertypes() {
        return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
    },
    events: {},
    watch: {
      'all'(val) {
        if (val) {
          this.modelval = this.bodyData
        } else {
          this.modelval = defaultPrint.config
          this.put()
        }
      },
      'modelval.length'() {
        this.put()
      },
    }
  }
</script>
<style>
  .datapanel {
    color: #333;
    background-color: white;
    padding: 10px 20px;
    border-radius: 15px;
  }
</style>
