<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' class="search_area" @condition-changed='$parent.search' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">用户编号</label>
              <input type="text" class="input_search" v-model="model.f_userinfo_code"
                     style="width: 60%" placeholder="用户编号"
                     condition="ui.f_userinfo_code='{}'"
              >
            </div>
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">用户名称</label>
              <input type="text" class="input_search" v-model="model.f_user_name"
                     style="width: 60%" placeholder="用户名称"
                     condition="ui.f_user_name like'%{}%'"
              >
            </div>
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">用户地址</label>
              <input type="text" class="input_search" v-model="model.f_address"
                     style="width: 60%" placeholder="用户地址"
                     condition="tua.f_address like '%{}%'"
              >
            </div>
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">建档日期</label>
              <datepicker
                placeholder='建档日期' style="width:60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                :value.sync="model.f_createfile_date"
                v-model="model.f_createfile_date"
                condition="ui.f_createfile_date >= '{} 00:00:00'">
              </datepicker>
            </div>
            <div class="col-sm-4" style="width: 20%">
              <div class="span" style="float: right;margin-top: 8px">
                <!--                <export-excel   :data="{condition: $parent.$parent.model.condition,f_filialeids:$parent.$parent.model.f_filialeids}"-->
                <!--                                :field="$parent.$parent.getfield"-->
                <!--                                sqlurl="api/af-safecheck/logic/exportfile" sql-name="GetCheckPaperByDefect" :template-name='$parent.$parent.excelTitle' :choose-col="true"></export-excel>-->
                <export-excel :data="$parent.$parent.searchData"
                              :field="$parent.$parent.excelHeaders"
                              sqlurl="api/af-safecheck/logic/exportfile" sql-name="UserplanPaper" :template-name="$parent.$parent.excelTitle"></export-excel>

                <button class="button_search button_spacing" @click="search">查询</button>
                <div style="float: right" class="button_spacing"
                     :class="{'button_shrink_left':$parent.$parent.$parent.showItem,'button_shrink_right':!$parent.$parent.$parent.showItem}"
                     @click="$parent.$parent.hiddenr()"></div>
                <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>
          <div class="row" v-if="$parent.$parent.criteriaShow" >
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">&nbsp;公&nbsp;&nbsp;&nbsp;&nbsp;司&nbsp;</label>
              <right-tree :userid.sync='$parent.$parent.userid' style="width: 60%;" :source.sync='$parent.$parent.source' @re-res="$parent.$parent.getRes" ></right-tree>
            </div>
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body" style="margin-right: 2px">用户类型</label>
              <v-select :value.sync="model.f_user_type" v-model='model.f_user_type'
                        :value-single="true" style="width: 60%"
                        class="select_list select"
                        :options='$parent.$parent.user_types' placeholder='用户类型'
                        close-on-select
                        condition="tuf.f_user_type='{}'"></v-select>
            </div>
            <div class="col-sm-4" style="width: 20%">
              <label class="font_normal_body">派发年份</label>
              <input type="text" class="input_search" v-model="model.f_plan_year"
                     style="width: 60%" placeholder="派发年份"
              >
            </div>

          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy">
        <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;white-space:nowrap;">{{row.f_userinfo_code}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_user_name}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_address}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_user_phone}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_idnumber}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_createfile_date}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_orgname}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.n}}</td>
        </template>
      </data-grid>
    </criteria-paged>

  </div>
</template>
<script>
import {PagedList} from 'vue-client'
import * as Util from '../Util'

export default {
  title: '用户信息',
  data() {
    let model = new PagedList('api/af-safecheck/sql/UserplanPaper', 20, {
      f_filialeid: 'this.f_filialeids',
      f_plan_year:'this.f_plan_year'
    })
    model.f_filialeids = '(' + this.$login.f.orgid + ')'
    model.f_plan_year = ''
    return {
      excelTitle:'用户派发情况导出',

      excelHeaders: {
        'f_userinfo_code': '用户编号',
        'f_user_name': '用户姓名',
        'f_address': '用户地址',
        'f_user_phone': '用户电话',
        'f_idnumber': '证件号码',
        'f_createfile_date': '建档日期',
        'f_orgname': '公司机构',
        'n': '计划下发次数'
      },
      searchData: {
        condition: "1=1",
        f_filialeid: `('${this.$login.f.orgid}')`,
        f_plan_year : ''
      },
      user_types:[{label:'全部',value:''},{label:'民用',value:'民用'},{label:'非民用',value:'非民用'}],
      f_filialeids:'(' + this.$login.f.orgid + ')',
      userid: this.$login.f.id,
      f: this.$login.f,
      model: model,
      criteriaShow: false,
      source: `tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() == $organization$))`,
    }
  },
  methods: {

    hiddenr() {
      this.$parent.showItem = !this.$parent.showItem
    },

    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    search(args) {
      if (args.model.f_plan_year){
        this.model.f_plan_year = args.model.f_plan_year
        this.searchData.f_plan_year = args.model.f_plan_year
      }
      this.searchData.condition=args.condition
      this.model.search(args.condition, args.model)
    },
    getRes(obj) {
      this.model.f_filialeids = this.$login.convertToIn(obj.resids);
      this.searchData.f_filialeid=this.$login.convertToIn(obj.resids);
      console.log(this.f_filialeids)
      console.log('11111111111'+JSON.stringify(this.model))
      console.log('11111111111'+JSON.stringify(this.obj))
    },
  },
  computed: {
    selected() {
      return this.$refs.paged.$refs.grid.selected
    }
  }
}
</script>
