<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_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 like '%{}%'" placeholder='客户名称'>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">&nbsp;&nbsp;&nbsp;表号&nbsp;&nbsp;&nbsp;</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.meternumber"
                         condition="f_meternumber = '{}' " placeholder="表号">
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">气表品牌</label>
                  <v-select :value.sync="model.f_meter_brand"
                            v-model="model.f_meter_brand"
                            @change='$parent.$parent.getmeterstyle'
                            :options='$parent.$parent.meterbrands' placeholder='请选择'
                            condition="f_meter_brand = '{}'"
                            close-on-select></v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">气表型号</label>
                  <v-select style="width:60%"
                            placeholder='气表型号'
                            :value.sync="model.f_meter_style"
                            v-model="model.f_meter_style"
                            :options='$parent.$parent.metertype'
                            close-on-select
                            condition="f_meter_style='{}'">
                  </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="rs/logic/exportfile" sql-name="getReportDataQuery" template-name='上报数据查询'  :choose-col="true"
                                class="button_export button_spacing"></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 v-show="$parent.$parent.criteriaShow">
                <res-select-group :initres="$parent.$parent.initres" @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
              </div>
            </div>
          </criteria>

          <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
            <template partial='head'>
              <tr>
                <th style="text-align:center"><nobr>用户编号</nobr></th>
                <th style="text-align:center"><nobr>用户名称</nobr></th>
                <th style="text-align:center"><nobr>表号</nobr></th>
                <th style="text-align:center"><nobr>本次抄表底数</nobr></th>
                <th style="text-align:center"><nobr>上次抄表底数</nobr></th>
                <th style="text-align:center"><nobr>表计剩余余额</nobr></th>
                <th style="text-align:center"><nobr>抄表日期</nobr></th>

                <th style="text-align:center"><nobr>上次抄表日期</nobr></th>
                <th style="text-align:center"><nobr>开户日期</nobr></th>
                <th style="text-align:center"><nobr>软件版本号</nobr></th>
                <th style="text-align:center"><nobr>表状态信息</nobr></th>
                <th style="text-align:center"><nobr>上次表状态信息</nobr></th>

                <th style="text-align:center"><nobr>插入日期</nobr></th>
                <th style="text-align:center"><nobr>上次插入日期</nobr></th>
                <th style="text-align:center"><nobr>是否结算</nobr></th>

                <th style="text-align:center"><nobr>超用气量</nobr></th>
                <th style="text-align:center"><nobr>电量等级</nobr></th>

                <th style="text-align:center"><nobr>购气次数</nobr></th>
                <th style="text-align:center"><nobr>单价</nobr></th>
                <th style="text-align:center"><nobr>信号强度</nobr></th>
                <th style="text-align:center"><nobr>信噪比</nobr></th>
                <th style="text-align:center"><nobr>电压</nobr></th>

                <th style="text-align:center"><nobr>阀门强制状态</nobr></th>
                <th style="text-align:center"><nobr>阀门状态</nobr></th>
                <th style="text-align:center"><nobr>计量类型</nobr></th>
                <th style="text-align:center"><nobr>上报类型</nobr></th>
                <th style="text-align:center"><nobr>金额状态</nobr></th>

                <th style="text-align:center"><nobr>电压状态</nobr></th>
                <th style="text-align:center"><nobr>磁干扰异常</nobr></th>
                <th style="text-align:center"><nobr>表内剩余金额</nobr></th>
                <th style="text-align:center"><nobr>表内累计充值金额</nobr></th>
                <th style="text-align:center"><nobr>补偿状态</nobr></th>

                <th style="text-align:center"><nobr>分公司</nobr></th>
              </tr>
            </template>

            <template partial='body'>
              <td style="text-align: left;"><nobr>{{row.f_userinfo_code}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_user_name}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_meternumber}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_tablebase}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_last_tablebase}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_jval}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_hand_date}}</nobr></td>

              <td style="text-align: left;"><nobr>{{row.f_last_hand_date}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_gas_date}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_software_version}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_table_msg}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_last_meter_state_msg}}</nobr></td>

              <td style="text-align: left;"><nobr>{{row.f_insert_date}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_last_insertdate}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_whether_clear}}</nobr></td>

              <td style="text-align: left;"><nobr>{{row.f_super_gas}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_electricity}}</nobr></td>

              <td style="text-align: left;"><nobr>{{row.f_times}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_price}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_signal}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_snr}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_batteryLevel}}</nobr></td>

              <td style="text-align: left;"><nobr>{{row.f_networkShutValve}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_valveState}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_wmprepaytype}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_upload_type}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_moneyState}}</nobr></td>

              <td style="text-align: left;"><nobr>{{row.f_LowLithiumBattery}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_magneticInterference}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_meterBalanceAmt}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_meterDebitAmt}}</nobr></td>
              <td style="text-align: left;"><nobr>{{row.f_compensateState}}</nobr></td>

              <td style="text-align: left;"><nobr>{{row.f_filiale}}</nobr></td>
            </template>
            <template partial='foot'></template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'
  import exportConfig from '../../sale/config/exportConfig'
  let readySomething = async function (self) {

    await self.$MagLoadParams.loadParam()
    self.initParams()
  }
  export default {
    title: '上报数据查询',
    data() {
      return {
        model: new PagedList('rs/sql/getReportDataQuery', 20, {}),
        criteriaShow: false,
        config: {
          fieldMapping: {
            f_userinfo_id: '客户编号',
            f_user_name: '客户名称'
          }
        },
        meterbrands: [],
        metertype:[],
        headData: [],
        bodyData: [],
        orgCondtionStr: '',
        initres: {
          dep: [],
          user: [],
        }
      }
    },
    async created () {
      await this.$getConfig(this,'ReportDataQuery')
    },
    ready() {
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      search() {
        this.$refs.paged.$refs.cri.search()
      },
      async selfSearch(args) {
        args.condition = `${args.condition}`
        await this.model.search(args.condition, args.model)
        // 查询到数据进行处理
        if (this.model.rows.length > 0) {
          this.bodyData = this.headData = Object.keys(this.model.rows[0])
        }
      },
      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] = ''
        })
      },
      initParams() {
        // 初始化气表品牌
        let brandArr = []
          this.$MagGetSaleParam.getGasbrand().forEach((item) => {
          if(item.value.f_meter_type=='物联网表'){
            let temp = {}
            temp.label = item.label
            temp.value = item.value.f_meter_brand
            brandArr.push(temp)
          }

        })
        this.meterbrands = [{label: '全部', value: ''}, ...brandArr]
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      getmeterstyle(){
        this.metertype=[]
        this.metertype.push({label:'全部',value:''})
        this.$MagGetSaleParam.getGasbrand().forEach((item) => {

          if(item.label==this.$refs.paged.$refs.cri.model.f_meter_brand){

            item.value.gasmodel.forEach((model) => {
              let temp = {}

              temp.label = model.label
              temp.value = model.value.f_meter_style
              this.metertype.push(temp)
            })


          }

        })
      },
      getRes(condition, obj) {

        this.orgCondtionStr = condition
        // this.orgname = obj.orgnames[0]
        // this.depname = obj.depnames[0]
      },
    },
    watch: {
    },
    computed: {
      getfield() {

        return exportConfig.ReportDataQueryConfig
      },
      getCondition() {

        return {
          condition: `${this.$refs.paged.$refs.cri.condition}`
        }

      },
    }
  }
</script>
