<template>
  <div @keyup.enter="search" class="flex-auto" style="flex:1;">
    <criteria-paged :model="model" v-ref:paged>
      <criteria @condition-changed='$parent.selfSearch' partial='criteria' v-ref:cri>
        <div class="form-horizontal select-overspread container-fluid auto" novalidate partial>
          <div class="row">
            <div
              :class="{'col-sm-2':!$parent.$parent.$parent.isdetail, 'col-sm-3':$parent.$parent.$parent.isdetail}"
              class="form-group">
              <label class="font_normal_body">组织机构</label>
              <res-select :initresid='$parent.$parent.initres'
                          @res-select="$parent.$parent.getorg"
                          class="select select_list"
                          restype='organization'
                          style="width: 60%">
              </res-select>
            </div>
           <div class="form-group" :class="{'col-sm-2':!$parent.$parent.$parent.isdetail, 'col-sm-3':$parent.$parent.$parent.isdetail}"
                 v-if="!$parent.$parent.$parent.isdetail">
              <label class="font_normal_body">客户编号</label>
              <input  class="input_search" condition="f_userinfo_code like '%{}%'" placeholder="客户编号" style="width:60%" style="width: 90px"
                      type="text" v-model="model.f_userinfo_code"
              />
            </div>
            <div class="form-group" :class="{'col-sm-2':!$parent.$parent.$parent.isdetail, 'col-sm-3':$parent.$parent.$parent.isdetail}"
                 v-if="!$parent.$parent.$parent.isdetail">
              <label class="font_normal_body">客户名称</label>
              <input  class="input_search" condition="f_user_name = '{}'" placeholder="客户名称" style="width:60%" style="width: 90px"
                      type="text" v-model="model.f_user_name"
              />
            </div>
            <div class="form-group" :class="{'col-sm-2':!$parent.$parent.$parent.isdetail, 'col-sm-3':$parent.$parent.$parent.isdetail}">
              <label class="font_normal_body">录入时间</label>
              <datepicker placeholder="录入开始时间"
                          style="width:60%"
                          class="datepicker"
                          v-model="model.f_start_date"
                          :value.sync="model.f_start_date"
                          :format="'yyyy-MM-dd'"
                          condition="f_operate_date >= '{} 00:00:00'"
              ></datepicker>
            </div>
            <div class="form-group" :class="{'col-sm-2':!$parent.$parent.$parent.isdetail, 'col-sm-3':$parent.$parent.$parent.isdetail}">
              <label class="font_normal_body">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
              <datepicker placeholder="录入结束时间"
                          style="width:60%"
                          class="datepicker"
                          v-model="model.f_end_date"
                          :value.sync="model.f_end_date"
                          :format="'yyyy-MM-dd'"
                          condition="f_operate_date <= '{} 00:00:00'"
              ></datepicker>
            </div>
            <div class="form-group col-sm-3 button-range" style="padding-right: 10px">
              <button @click="$parent.$parent.search()" class="button_search button_spacing" style="width:80px;margin-left:30px;" v-el:cx>查询</button>
<!--              <export-excel-->
<!--                      :data="$parent.$parent.getCondition"-->
<!--                      :field="$parent.$parent.getfield"-->
<!--                      sqlurl="rs/logic/saleExport" progress="saleGetExportProgress" sql-name="sale_getBlackList" template-name='黑名单导出'-->
<!--                      :choose-col="true">-->
<!--              </export-excel>-->
              <div
                :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                @click="$parent.$parent.hidden()" class="button_spacing" style="float: right"></div>
            </div>
          </div>
          <div class="row" v-if="$parent.$parent.criteriaShow">
          </div>

        </div>
      </criteria>
      <data-grid :model="model" class="list_area table_sy" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th style="text-align: center; ">序号</th>
            <th style="text-align: center;">客户编号</th>
            <th style="text-align: center;">客户姓名</th>
            <th style="text-align: center;">客户电话</th>
            <th style="text-align: center;">客户地址</th>
            <th style="text-align: center;">客户类型</th>
            <th style="text-align: center;">表具类型</th>
            <th style="text-align: center;">机表阀门状态</th>
            <th style="text-align: center;">入户时间(最新记录)</th>
            <th style="text-align: center;">用户状态(最新记录)</th>
            <th style="text-align: center;">安检类型(最新记录)</th>
            <th style="text-align: center;">最后增加时间</th>
            <th style="text-align: center;">操作</th>
          </tr>
        </template>
        <template partial='body'>

          <td style="text-align: center;">{{$index+1}}</td>
          <td style="text-align: center;">{{row.f_userinfo_code}}</td>
          <td style="text-align: center;">{{row.f_user_name}}</td>
          <td style="text-align: center;">{{row.f_user_phone}}</td>
          <td style="text-align: center;">{{row.f_address}}</td>
          <td style="text-align: center;">{{row.f_user_type}}</td>
          <td style="text-align: center;">{{row.f_meter_classify}}</td>
          <td style="text-align: center;">{{row.f_bqf_state}}</td>
          <td style="text-align: center;">{{row.f_in_time}}</td>
          <td style="text-align: center;">{{row.f_user_state}}</td>
          <td style="text-align: center;">{{row.f_check_type}}</td>
          <td style="text-align: center;">{{row.f_operate_date}}</td>
          <td style="text-align: center;">
            <button class="button_clear button_spacing width-50" @click.stop="$parent.$parent.$parent.changerecord(row)">添加记录</button>
            <button class="button_clear button_spacing width-50" @click.stop="$parent.$parent.$parent.showrecord(row)">查看记录</button>
          </td>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

  export default {
    data () {
      return {
        initres: [this.$login.f.orgid],
        criteriaShow: false,
        model: new PagedList('rs/sql/getstopairuser', 20),
        // 公司下拉
        curorgid: [this.$login.f.orgid],
        f_orgid: '',
        getfield: {

        },
        f_filialeid:'',
        f_filialeids:''
      }
    },
    props: {
      style: {
        type: String,
        default: 'form-group col-sm-2'
      },
      row: {},
      ispartial: false
    },
    methods: {
      changerecord(row){
          this.$dispatch('selectchange',row)
      },
      showrecord(row){
        this.$dispatch('showrecord',row)
      },
      async getRes (condition, obj) {
        console.log('condition =', condition)
        console.log('obj =', obj)
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      search () {
        this.$refs.paged.$refs.cri.search()
        this.$dispatch('search')
      },
      getorg (val,org2) {
        this.f_orgid = val
        this.f_filialeid = this.$login.convertToIn(val)
        this.f_filialeids = val[0]
      },
      selfSearch (args) {
        if (!this.f_orgid) {
          this.getorg('and f_orgid in' + '(\'' + [this.$login.f.orgid] + '\')')
        }
        console.log('查询。。。', this.f_orgid)
        if (this.f_orgid) {
         // args.condition = `${args.condition} and s.f_filialeid  in ${this.f_orgid}`
          args.condition = `${args.condition} and f_orgid = '${this.f_orgid}' `
        }

        this.model.search(args.condition, args.model)
      },
      add () {
        this.style = 'col-sm-3'
        this.$dispatch('add')
      },
      dblclick (val) {
        console.log(val)
        this.$emit('dblclick', val)
      }

    },
    watch: {
      'model.rows.length' (val) {
        if (val === 1) {
          this.$refs.paged.$refs.grid.select(this.model.rows[0])
        }
      }
    },
    computed: {
      getCondition () {
        return {condition: `${this.$refs.paged.$refs.cri.condition}` + this.f_orgid}
      }
    }
  }
</script>
