<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 @sort="sort">
          <criteria partial='criteria' @condition-changed='$parent.selfSearch' 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="开始日期" style="width:60%"
                              v-model="model.startDate"
                              :value.sync="model.startDate"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              :show-reset-button="true"
                              condition="ttr.f_operate_date >= '{}'">
                  </datepicker>
                </div>
                <div class="col-sm-2 form-group">
                  <label for="endDate" class="font_normal_body">结束日期</label>
                  <datepicker id="endDate" placeholder="结束日期" style="width:60%"
                              v-model="model.endDate"
                              :value.sync="model.endDate"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              :show-reset-button="true"
                              condition="ttr.f_operate_date <= '{}'">
                  </datepicker>
                </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.out_userinfo_code"
                         condition="out_userinfo_code = '{}'" placeholder="转出方编号">
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body" title="转入方编号">转入方编号</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.in_userinfo_code"
                         condition="in_userinfo_code = '{}' " placeholder="转入方编号">
                </div>
                <div class="span" style="float:right;">
                  <button class="button_search button_spacing" @click="search()">查询</button>
                  <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</button>
                  <export-excel :data="$parent.$parent.getCondition"
                                :field="$parent.$parent.getfield"
                                sqlurl="api/af-revenue/logic/openapi/exportfile" sql-name="transferRecordQuery" template-name='转移记录查询导出'
                                :choose-col="true"></export-excel>
<!--                  <print-data :sum-field="$parent.$parent.getfield" :model="$parent.model" :field="$parent.$parent.getfield"-->
<!--                               :defaultfield="$parent.$parent.defaultfield"-->
<!--                              titletable="过户记录"-->
<!--                              :sumsmodel="$parent.$parent.sumsmodel"></print-data>-->
                  <div style="float: right"  class="button_spacing" :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"    @click="$parent.$parent.hidden()"></div>
                </div>
              </div>
              <div class="row" v-show="$parent.$parent.criteriaShow">
                <res-select-group :initres="$parent.$parent.initres" :show-component="['company','department','operator']" @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
                <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.out_user_name"
                         placeholder="转出方姓名"
                         condition="out_user_name like '%{}%'">
                </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.in_user_name"
                         condition="in_user_name like '%{}%' " placeholder="转入方姓名">
                </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>
                <th>  <nobr>公司</nobr> </th>
              </tr>
            </template>
            <template partial='body'>
              <td style="text-align: center;">  <nobr>{{row.in_user_name}}</nobr>  </td>
              <td style="text-align: center;">  <nobr>{{row.in_userinfo_code}}</nobr>  </td>
              <td style="text-align: center;">  <nobr>{{row.out_user_name}}</nobr>  </td>
              <td style="text-align: center;">  <nobr>{{row.out_userinfo_code}}</nobr>  </td>
              <td style="text-align: center;">  <nobr>{{row.f_operate_date}}</nobr>  </td>
              <td style="text-align: center;">  <nobr>{{row.f_comments}}</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_orgname}}</nobr>  </td>
            </template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'
  import exportConfig from '../config/exportConfig'

  let readySomething = async function (self) {
    self.$refs.paged.$refs.cri.model.startDate = self.data ? self.data.startDate : self.$login.toStandardDateString() + ' 00:00:00'
    self.$refs.paged.$refs.cri.model.endDate = self.data ? self.data.endDate : self.$login.toStandardDateString() + ' 23:59:59'
  }
  export default {
    props:['data'],
    title: '记录转移查询',
    data() {
      return {
        data: {},
        other:[],
        footer:[],
        show:false,
        rowdata:{},
        model: new PagedList('api/af-revenue/sql/transferRecordQuery', 20, ),
        criteriaShow: false,
        initres: {
          org:[this.$login.f.orgid],
          dep:[],
          user:[],
        },
        orgCondtionStr: '',
        all: false,
        fields: {},
        thead: '',
        tfoot: '',
        showupload:false,
        selected:{},
        sumsmodel: {}
      }
    },
    ready() {
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      search(){
        this.$refs.paged.$refs.cri.search()
      },
      async selfSearch(args) {
        if (this.data) {
          this.$parent.$parent.$parent.data.startDate=this.$refs.paged.$refs.cri.model.startDate
          this.$parent.$parent.$parent.data.endDate=this.$refs.paged.$refs.cri.model.endDate
        }
        args.condition = `${args.condition}` + this.orgCondtionStr
        await this.model.search(args.condition, args.model)
      },
      show() {
        this.criteriaShow = true
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      getRes(obj) {
        this.orgCondtionStr = obj
      }
    },
    watch: { },
    computed: {
      getCondition() {
        return {
          condition: `${this.$refs.paged.$refs.cri.condition}` + this.orgCondtionStr
        }
      },
      getfield() {
        return exportConfig.transferRecordConfig
      }
    }
  }
</script>
