<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"
                              :format="'yyyy-MM-dd'"
                              :show-reset-button="true"
                              condition="f_operator_date >= '{} 00:00:00'">
                  </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'"
                              :show-reset-button="true"
                              condition="f_operator_date <= '{} 23:59:59'">
                  </datepicker>
                </div>
                <div class="form-group col-sm-2" >
                  <label class="font_normal_body">错误类型</label>
                  <v-select :value.sync="model.f_operator_type" :value-single="true"
                            class="select_list select"
                            title="参数:抄表错误类型"
                            style="width: 60%"
                            v-model="model.f_operator_type"
                            :options='$parent.$parent.operatortype' placeholder='错误类型'
                            condition = "f_operator_type = '{}'"
                            close-on-select search="true">
                  </v-select>
                </div>
                <div class="form-group col-sm-2" >
                  <label class="font_normal_body">错误原因</label>
                  <v-select :value.sync="model.f_error_type" :value-single="true"
                            class="select_list select"
                            title="参数:错误原因"
                            style="width: 60%"
                            v-model="model.f_error_type"
                            :options='$parent.$parent.errortype' placeholder='错误原因'
                            condition = "f_error_type = '{}'"
                            close-on-select search="true">
                  </v-select>
                </div>
                <div class="form-group col-sm-2" >
                  <label class="font_normal_body">银行名称</label>
                  <v-select :value.sync="model.f_bankname" :value-single="true"
                            class="select_list select"
                            title="参数:抄表错误类型"
                            style="width: 60%"
                            v-model="model.f_bankname"
                            :options='$parent.$parent.bankname' placeholder='银行名称'
                            condition = "f_bankname = '{}'"
                            close-on-select search="true">
                  </v-select>
                </div>
                <div class="col-sm-2 form-group" v-if="false">
                  <label class="font_normal_body">公&ensp;&ensp;司</label>
                  <res-select :initresid="$parent.$parent.orgid"
                              style="width:60%"
                              @res-select="$parent.$parent.getRes"

                              restype='organization'>
                  </res-select>
                </div>
                <div class="form-group col-sm-2" v-if="false">
                  <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 = "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="battcherror" template-name='报错查询'
                                :choose-col="true"></export-excel>
                  <print-data :sum-field="$parent.$parent.getfield" :model="$parent.model" :field="$parent.$parent.getfield"
                               :defaultfield="$parent.$parent.defaultfield"
                              titletable="报错查询"
                              :sumsmodel="$parent.$parent.sumsmodel"></print-data>

                </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>
              </tr>
            </template>
            <template partial='body'>
              <td style="text-align:center">
                <nobr>{{$index+1}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_userinfo_code}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_meternumber}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_operator_date}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_operator_type}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_error_type}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_bankname}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.f_msg}}</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.defaultfield = [...self.defaultfield, ...self.config.defaultPrint]
    self.$refs.paged.$refs.cri.model.startDate = self.$login.toStandardDateString()
    self.$refs.paged.$refs.cri.model.endDate = self.$login.toStandardDateString()
    // await self.$refs.paged.$refs.cri.search()
    await self.$MagLoadParams.loadParam()
    self.initParams()
    self.sumsmodel = self.$refs.paged.$refs.grid.model.sums
  }

  export default {
    title: '错误查询',
    data() {
      return {
        data: {},
        model: new PagedList('api/af-revenue/sql/battcherror', 20),
        criteriaShow: false,
        f_filialeid: this.$login.f.orgid,
        //默认打印列
        defaultfield: [],
        config: {
          defaultPrint: ['f_userinfo_code', 'f_bankname', 'f_error_type']
        },
        orgid:[this.$login.f.orgid],
        //小区
        residentialArea: [],
        orgCondtionStr: '(' + this.$login.f.orgid + ')',
        operatortype:[{label: '全部', value: ''}, ...this.$appdata.getParam('抄表错误类型')?this.$appdata.getParam('抄表错误类型'):[]],
        errortype:[{label: '全部', value: ''}, ...this.$appdata.getParam('错误原因')?this.$appdata.getParam('错误原因'):[]],
        bankname:[{label: '全部', value: ''}, ...this.$appdata.getParam('银行名称')?this.$appdata.getParam('银行名称'):[]],
        //合计数据
      }
    },
    ready() {

      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      selfSearch (args){
       //  console.log(this.f_filialeid,"++++++++",this.$login.f.orgid)
       // if (this.orgCondtionStr){
       //   args.condition = `${args.condition}` + 'and f_orgid in ' + this.orgCondtionStr
       // }else{
       //   args.condition = `${args.condition}` + 'and f_orgid in ' + '(' + this.$login.f.orgid + ')'
       // }
        this.model.search(args.condition, args.model)
      },
      getRes (obj) {
        this.orgCondtionStr = plugins.convertToIn(obj)
      },
      clear() {
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = []
        })
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      }
    },
    computed: {
      getCondition () {
        var con = this.$refs.paged.$refs.cri.condition
        // if (this.orgCondtionStr) {
        //   con = `${this.$refs.paged.$refs.cri.condition} and f_orgid in  (${this.orgCondtionStr})`
        // }
        // else {
        //   con = `${this.$refs.paged.$refs.cri.condition}and f_orgid in ('${this.$login.f.orgid}' )`
        // }
        return {
          condition: con
        }
      },
      getfield() {
        return exportConfig.Wrongquery
      }
    }

  }
</script>
