<template>
  <div @keyup.enter="search" class="auto basic-main" style="height:95%">
    <criteria-paged :model="model" v-ref:paged>
      <criteria @condition-changed='$parent.selfSearch' partial='criteria' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="form-group col-sm-2" >
              <label class="font_normal_body">组织机构</label>
              <res-select :initresid='$parent.$parent.curorgid'
                          @res-select="$parent.$parent.getorg"
                          class="select select_list"
                          restype='organization'
                          style="width: 60%">
              </res-select>
            </div>
            <div class="form-group col-sm-2">
              <label for="startDate" class="font_normal_body">操作时间</label>
              <datepicker id="startDate" placeholder="开始日期"
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          condition="time >= '{} 00:00:00'"
                          style="width:60%">
              </datepicker>
            </div>
            <div class="form-group col-sm-2">
              <label for="endDate" class="font_normal_body">操作时间</label>
              <datepicker id="endDate" placeholder="结束日期"
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          condition="time <= '{} 23:59:59'"
                          style="width:60%">
              </datepicker>
            </div>
            <div class="col-sm-3 form-group button-range" style="margin-right: 10px;">
              <button @click="search()" class="button_search button_spacing" v-el:cx>查询</button>
              <button @click="$parent.$parent.clear()" class="button_new button_spacing">清空</button>
              <export-excel
                :data="{condition: $parent.$parent.model.condition}"
                :field="$parent.$parent.getfield"
                sqlurl="rs/logic/saleExport" sql-name="sale_getResourceRecord"
                template-name='资源操作记录导出'
                :choose-col="true">
              </export-excel>
              <div
                :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                @click="$parent.$parent.criteriaShow=!$parent.$parent.criteriaShow"
                class="button_spacing"
                style="float: right">
              </div>
            </div>
          </div>
          <div class="row" v-show="$parent.$parent.criteriaShow">
            <div class="col-sm-2 form-group">
              <label class="font_normal_body" for="f_meter_type">操作类型</label>
              <input class="input_search" condition="type like '%{}%'" placeholder='操作类型' style="width:60%"
                     type="text"
                     v-model="model.type">
            </div>
            <div class="col-sm-2 form-group">
              <label class="font_normal_body">操作描述</label>
              <input class="input_search" condition="operate like '%{}%'" placeholder='操作描述' style="width:60%"
                     type="text"
                     v-model="model.operate">
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" class="list_area table_sy" partial='list' v-ref:grid>
        <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>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center">
              <nobr>{{ $index + 1 }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.type }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.operate }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.time }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.f_operator }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.f_depname }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.f_orgid }}</nobr>
            </td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
import {PagedList} from 'vue-client'

let readySomething = async function (self) {
  self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString()
  self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString()
  self.search()
}

export default {
  title: '资源操作记录查询',
  data () {
    return {
      model: new PagedList('rs/sql/sale_getResourceRecord', 20),
      criteriaShow: true,
      orgCondtionStr: '',
      getfield: {
        'type': '操作类型',
        'operate': '操作描述',
        'time': '操作时间',
        'f_operator': '操作人',
        'f_depname': '部门',
        'f_orgname': '组织机构'
      },
      f_orgid: '',
      curorgid: [this.$login.f.orgid]
    }
  },
  ready () {
    readySomething(this)
  },
  methods: {
    // 清空
    clear() {
      Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
        this.$refs.paged.$refs.cri.model[key] = []
      })
    },
    getorg (val) {
      this.f_orgid = this.$login.convertToIn(val)
    },
    selfSearch (args) {
      if (!this.f_orgid) {
        this.getorg([this.$login.f.orgid])
      }
      if (this.f_orgid) {
        args.condition = `${args.condition}` + ` and f_orgid in ${this.f_orgid}`
      }
      this.model.search(args.condition, args.model)
    },
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    hidden () {
      this.criteriaShow = !this.criteriaShow
    }
  },
  watch: {}
}
</script>
