<template>
  <div id="unit" class="flex-row">
    <div class="basic-main">
      <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 for="startDate" class="font_normal_body">开始日期</label>
                  <datepicker id="startDate" placeholder="开始日期" style="width:60%"
                              v-model="model.startDate"
                              :value.sync="model.startDate"
                              condition="ps.f_operate_date >= '{}'"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              :show-reset-button="true"
                  >
                  </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"
                              condition="ps.f_operate_date <= '{}'"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              :show-reset-button="true"
                  >
                  </datepicker>
                </div>
                <!--<div class="form-group col-sm-2">-->
                  <!--<label class="font_normal_body">选择小区</label>-->
                  <!--<v-select :value.sync="model.f_residential_area" :value-single="true"-->
                            <!--class="select_list select"-->
                            <!--style="width: 60%"-->
                            <!--v-model="model.f_residential_area"-->
                            <!--:options='$parent.$parent.residentialArea' placeholder='选择小区'-->
                            <!--condition="ua.f_residential_area = '{}'"-->
                            <!--close-on-select search="true">-->
                  <!--</v-select>-->
                <!--</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="printSheetQuery"
                                template-name='受理单查询导出'
                                :choose-col="true"></export-excel>
                  <print-data  :model="$parent.model" :field="$parent.$parent.getfield"
                               :defaultfield="$parent.$parent.defaultfield"
                              titletable="受理单查询导出"></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.f_userinfo_code"
                         condition="ui.f_userinfo_code = '{}' " 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="ui.f_user_name like '%{}%' " placeholder="用户姓名">
                </div>
                <div class="form-group col-sm-3">
                  <label class="font_normal_body">打印次数</label>
                  <v-input :value.sync="$parent.f_print_num" :expression.sync = 'model.f_print_num'
                           condition="f_print_num {}" v-model="model.f_print_num"  style="width: 60%"
                           typeof="number"
                           placeholder="打印条数" ></v-input>
                </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="(key,value ) in $parent.$parent.$parent.config.pageFilds" ><nobr>{{value}}</nobr></th>
              </tr>
            </template>
            <template partial='body'>
              <td style="text-align: center;" v-for="(key,value ) in $parent.$parent.$parent.config.pageFilds"><nobr>{{row[key]}}</nobr></td>
            </template>
            <template partial='foot'></template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
</template>

<script>
  import {PagedList, HttpResetClass} from 'vue-client'
  import defaultPrint from '../config/DefaultPrint'
  import exportConfig from "../config/exportConfig";
  import plugins from "../../../plugins/GetLoginInfoService";

  let readySomething = async function (self) {
    self.initParams()
    self.defaultfield = [...self.defaultfield, ...self.config.defaultPrint]
    self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString() + ' 00:00:00'
    self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString() + ' 23:59:59'
  }

  export default {
    title: '受理单打印查询',
    data() {
      let model = new PagedList('api/af-revenue/sql/printSheetQuery', 20, {
        startdate: 'this.model.startDate',
        enddate: 'this.model.endDate'
      })
      model.f_filialeid = this.$login.f.orgid
      return {
        //默认打印列
        defaultfield: [],
        config: {
          pageFilds:{
              'f_userinfo_code': '用户编号', 'f_user_name': '用户姓名', 'f_user_phone': '用户电话',  'f_user_type': '用户类型' ,'f_address':'用户地址',
              'f_operate_date':'操作时间','f_print_time':'打印时间','f_print_num':'打印次数','f_orgname':'组织机构','f_depname':'部门','f_operator':'操作人'
          },
          defaultPrint: ['f_userinfo_code', 'f_user_name', 'f_user_phone','f_user_type','f_address','f_operate_date','f_print_time']
        },
        data: {},
        other: [],
        footer: [],
        meterbrands: [],
        initres: {
          org:[this.$login.f.orgid],
          dep:[],
          user:[]
        },
        model: model,
        criteriaShow: false,
        f_filialeid: this.$login.f.orgid,
        orgid: [this.$login.f.orgid],
        //小区
        residentialArea: [],
        orgCondtionStr: '',
      }
    },
    ready() {
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      // async getaddress() {
      //   console.log('开始获取小区')
      //   let HttpReset = new HttpResetClass()
      //   var data = await HttpReset.load('POST', 'api/af-revenue/sql/manage_getarealist', {
      //     data: {
      //       condition: `1=1 and s.f_filialeid = '${this.$login.f.orgid}'`
      //     }
      //   }, {resolveMsg: null, rejectMsg: '获取小区失败!'})
      //   console.log('小区', data)
      //   let house = [{label: '全部', value: ''}]
      //   for (let row of data.data) {
      //     console.log('开始保存小区')
      //     house.push({label: row.f_residential_area, value: row.f_residential_area})
      //   }
      //   this.residentialArea = house
      // },
      selfSearch(args) {
        args.condition = `${args.condition}` + this.orgCondtionStr
        this.model.search(args.condition, args.model)
      },
      async getRes(condition,obj) {
        console.log(condition,"========")
        this.orgCondtionStr = condition

      },
      clear() {
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = []
        })
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      }
    },
    watch: {

    },
    computed: {

      getCondition() {
        var con = ""
        if (this.orgCondtionStr) {
          con = `${this.$refs.paged.$refs.cri.condition} ` + this.orgCondtionStr
        } else {
          con = `${this.$refs.paged.$refs.cri.condition}`
        }
        return {
          condition: con
        }
      },
      getfield() {
        return this.config.pageFilds
      }
    }

  }
</script>
