<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 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="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="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.f_userinfo_code"
                         condition="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="f_user_name = '{}'" 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="NFCRechargeRecord"
                                template-name='NFC充值记录导出'
                                :choose-col="true"></export-excel>

                  <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="$parent.$parent.showComponent" @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">用户类型</label>
                  <v-select :value.sync="model.f_user_type"
                            :options='$parent.$parent.usertypes' placeholder='请选择' v-model="model.f_user_type"
                            condition="f_user_type = '{}'"
                            close-on-select></v-select>
                </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_card_id"
                         condition="f_card_id = '{}'" placeholder='写卡账号'>
                </div>


              </div>
            </div>
          </criteria>

          <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
            <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>
                <th>
                  <nobr>写卡金额</nobr>
                </th>
              </tr>
            </template>
            <template partial='body'>
              <td style="text-align: center;">
                <nobr>{{row.id}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_userinfo_code}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_user_name}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_user_type}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_type}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_operate_date}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_write_date}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_card_id}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_write_card}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_write_money}}</nobr>
              </td>
            </template>
            <template partial='foot'></template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
</template>

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

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: 'NFC充值记录',
  data() {
    return {
      other:[],
      footer:[],
      config: {
        defaultPrint: ['f_userinfo_code', 'f_user_name','f_address', 'f_user_type', 'f_gasproperties','f_oldprice','f_newprice','oldprice_performdate','newprice_performdate','f_operate_date','f_operator','f_depname']
      },
      //f_price_name:[],
      gasproperties:[],
      data: {},
      initres: {
        org:[this.$login.f.orgid],
        dep:[],
        user:[]
      },
      showComponent:['company'],
      model: new PagedList('api/af-revenue/sql/NFCRechargeRecord', 20, {}, ),
      criteriaShow: false,
      orgCondtionStr: '',
      //合计数据
      defaultfield: [],
      sumsmodel: {},
      selected:{},
      f_filialeid: this.$login.f.f_orgid
    }
  },
  ready() {
    readySomething(this).then(() => {
      this.$emit('ready')
    }).catch((error) => {
      this.$emit('error', error)
    })

  },
  methods: {
    search(){
      this.$refs.paged.$refs.cri.search()
    },
    selfSearch(args) {
      //小区查询条件
      if (this.data) {
        this.$parent.$parent.$parent.data.operateDate=this.$refs.paged.$refs.cri.model.operateDate
        this.$parent.$parent.$parent.data.performDate=this.$refs.paged.$refs.cri.model.performDate
      }
      let f_orgstr = this.orgCondtionStr
      args.condition = `${args.condition} ` + f_orgstr
      this.model.search(args.condition, args.model)
      this.sumsmodel = this.$refs.paged.$refs.grid.model.sums;

    },
    clear() {
      //清空部门和人员
      this.$refs.paged.$refs.cri.$refs.sel.$children[1].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] = []
      })

    },
    dealmsg(val) {
      val.model = this.model.model
      this.$dispatch('deal-msg', val)
    },
    show() {
      this.criteriaShow = true
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    getRes(condition,obj) {
      this.orgCondtionStr = condition
      this.orgname = obj.orgnames[0]
      this.depname = obj.depnames[0]
    },

  },
  events:{

  },
  watch: {

    'orgCondtionStr'(val) {
      let res = val.match(/'(.*?)'/)
      console.log('正则提取:',res && res[1])
      if (res) {
        this.f_filialeid = res[1]
      }
    }
  },
  computed: {
    usertypes() {
      return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('用户类型')]
    },
    getCondition() {
      return {
        operateDate: this.$refs.paged.$refs.cri.model.operateDate,
        performDate: this.$refs.paged.$refs.cri.model.performDate,
        condition: `${this.$refs.paged.$refs.cri.condition}` + this.orgCondtionStr}
    },
    getfield() {
      return exportConfig.nfcRecordQuery
    }
  }
}
</script>
