<template>
  <div id="unit" class="flex-row">
    <div class="basic-main" @keyup.enter="search">
      <div class="flex">
        <criteria-paged :model="model" v-ref:paged>
          <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 class="font_normal_body">客户编号</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_userinfo_id"
                         condition="f_userinfo_id = '{}' " 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_user_name"
                         condition=" f_user_name like '%{}%'" placeholder='客户名称'>
                </div>
<!--                <div class="col-sm-2">-->
<!--                  <label class="font_normal_body">组织机构</label>-->
<!--                  <res-select :initresid="$parent.$parent.org"-->
<!--                              style="width:60%"-->
<!--                              @res-select="$parent.$parent.getorg"-->
<!--                              restype='organization'>-->
<!--                  </res-select>-->

<!--                </div>-->
                <div class="col-sm-2">
                  <label class="font_normal_body">&emsp;公司&emsp;</label>
                  <right-tree @re-res="$parent.$parent.getorg"
                              :initresid='$parent.$parent.org'></right-tree>
                </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>
                  <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>
          </criteria>

          <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
            <template partial='head'>
              <tr>
                <th v-for="row in $parent.$parent.$parent.headData">
                  <nobr>{{row}}</nobr>
                </th>
              </tr>
            </template>
            <template partial='body'>
              <tr v-for="row in $parent.$parent.$parent.model.rows">
                <td style="text-align: center;" v-for="item in $parent.$parent.$parent.config.fieldMapping">
                  <nobr>{{row[item]}}</nobr>
                </td>
              </tr>
            </template>
            <template partial='foot'></template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'
  import tableConfig from './../../sale/config/tableConfig'
  import plugins from '../../../plugins/GetLoginInfoService'
  import plugin from 'system-clients/src/plugins/GetLoginInfoService'

  let readySomething = async function (self) {
    // self.defaultfield = [...self.defaultfield, ...self.config.defaultPrint]
  }
  export default {
    title: '上报数据查询',
    data() {
      return {
        model: new PagedList('rs/sql/manage_getReportDataQuery', 20, {}),
        criteriaShow: false,
        config: {
          fieldMapping: {
            f_userinfo_id: '客户编号',
            f_user_name: '客户名称'
          }
        },
        headData: [],
        bodyData: [],
        orgCondtionStr: " and f_filialeid in (" + this.$login.f.orgid+")",
        resshow:['company'],
        org:[this.$login.f.orgid],

      }
    },
    created () {
     this.config.fieldMapping=tableConfig.ReportDataQuery
      console.log("========================")
      console.log(this.config.fieldMapping)
      var item="用户编号"
      console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
      console.log(this.config.fieldMapping[item])
      this.headData=Object.keys(this.config.fieldMapping)
      // for(var i=0;i<this.config.fieldMapping;i++){
      //   this.headData.push(this.config.fieldMapping[i])
      // }

    },
    ready() {
      this.$refs.paged.$refs.cri.search()
    },
    methods: {
      search() {
        this.$refs.paged.$refs.cri.search()
      },
      async selfSearch(args) {
        args.condition = `${args.condition}` + this.orgCondtionStr
        await this.model.search(args.condition, args.model)
        // 查询到数据进行处理
        // if (this.model.rows.length > 0) {
        //   this.bodyData =  Object.keys(this.model.rows[0])
        // }
      },
      getorg(obj) {
        if (obj.resids.length>0) {
          this.orgCondtionStr = " and f_filialeid in " + plugin.convertToIn(obj.resids)
        }else
        {
          this.orgCondtionStr = " and f_filialeid = " + this.$login.f.orgid
        }
      },
      // getorg(obj) {
      //   // if(plugins.convertToIn(obj)!==null&&plugins.convertToIn(obj)!==''){
      //   //   this.orgCondtionStr = " and f_filialeid in " + plugins.convertToIn(obj)
      //   // }else{
      //   //   this.orgCondtionStr = " and f_filialeid = " + this.$login.f.orgid
      //   // }
      //   // this.orgname = obj.res
      // },
      clear() {
        //清空部门和人员
        this.$refs.paged.$refs.cri.$refs.sel.$children[1].selectres = []
        this.$refs.paged.$refs.cri.$refs.sel.$children[2].selectres = []
        //部门和人员变为全选
        this.$refs.paged.$refs.cri.$refs.sel.$children[1].$children[0].isSelectAll = false
        this.$refs.paged.$refs.cri.$refs.sel.$children[2].$children[0].isSelectAll = false
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = ''
        })
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },

      // getRes(obj) {
      //   this.orgCondtionStr = obj
      // }
    },
    watch: {
    },
    computed: {
    }
  }
</script>
