<template>
  <div id="stand-work-list" class="basic-main" style="height: 98%">
      <criteria-paged :model="model" v-ref:paged>
        <criteria partial='criteria' v-ref:criteria @condition-changed='$parent.search'>
          <div  novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="row" >
              <div class="col-sm-2">
                <label class="font_normal_body">客户编号</label>
                <input @keyup.enter="search" type="text" class="input_search" style="width:60%"
                       v-model="model.f_userinfo_code"
                       placeholder='客户编号'
                       condition="f_userinfo_code like '%{}%'"
                >
              </div>
              <div class="col-sm-2">
                <label class="font_normal_body">客户名称</label>
                <input @keyup.enter="search" type="text" class="input_search" style="width:60%"
                       v-model="model.f_user_name"
                       placeholder='客户名称'
                       condition="f_user_name like '%{}%'"
                >
              </div>
              <div class="col-sm-2">
                <label class="font_normal_body">客户地址</label>
                <input @keyup.enter="search" type="text" class="input_search" style="width:60%"
                       v-model="model.f_address"
                       placeholder='客户地址'
                       :size="model.f_address ? model.f_address.length : 6"
                       condition="f_address like '%{}%'"
                >
              </div>
              <div class="col-sm-2">
                <label class="font_normal_body">&nbsp;&nbsp;&nbsp;表号&nbsp;&nbsp;&nbsp;</label>
                <input @keyup.enter="search" type="text" class="input_search" style="width:60%"
                       v-model="model.f_meternumber"
                       placeholder='表号'
                       condition="f_meternumber like '%{}%'">
              </div>

              <div style="float:right">
                <button class="button_search button_spacing" @click="search()" v-el:cba>查询</button>
                <button class="button_clear button_spacing" @click="$parent.$parent.clearmsg">清空</button>
                <export-excel :data="{condition:$parent.$parent.condition}"
                                   :field="$parent.$parent.getfield"
                                   sqlurl="rs/logic/exportfile" sql-name="manage_getNewMeterBrandAndModel" template-name='表具查询'
                                   v-ref:exports
                                   :choose-col="true"></export-excel>
<!--                <export-excel-->
<!--                  :data="{condition: $parent.$parent.condition}"-->
<!--                  :field="$parent.$parent.getfield"-->
<!--                  sqlurl="rs/logic/saleExport" sql-name="manage_getNewMeterBrandAndModel" template-name='表具查询'-->
<!--                  :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">
              <div class="col-sm-2">
                <label class="font_normal_body">组织机构</label>
                <res-select :initresid="$parent.$parent.org"
                            style="width:60%"
                            @res-select="$parent.$parent.getorg"
                            restype='organization'>
                </res-select>

              </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">客户类型</label>
                  <v-select
                    placeholder='客户类型'
                    value-single="true"
                    style="width:60%"
                    :value.sync="model.f_user_type"
                    v-model="model.f_user_type"
                    :options='$parent.$parent.Gasusertype'
                    close-on-select condition="f_user_type ='{}'">
                  </v-select>
                </div>

                <div class="col-sm-2">
                  <label class="font_normal_body">用气性质</label>
                  <v-select
                    placeholder='用气性质'
                    value-single="true"
                    :value.sync="model.f_gasproperties"
                    style="width:60%"
                    v-model="model.f_gasproperties"
                    :options='$parent.$parent.Gasproperties'
                    close-on-select condition="f_gasproperties ='{}'">
                  </v-select>
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">气表状态</label>
                  <v-select
                    placeholder='气表状态'
                    :value.sync="model.f_table_state"
                    style="width:60%"
                    v-model="model.f_table_state"
                    :options='$parent.$parent.TableStates'
                    close-on-select
                    condition="f_table_state='{}'">
                  </v-select>
                </div>
                <div class="col-sm-2">
                  <label class="font_normal_body">气表品牌</label>
                  <v-select
                    placeholder='气表品牌'

                    :value.sync="model.f_gasbrand"
                    style="width:60%"
                    v-model="model.f_gasbrand"
                    :options='$parent.$parent.meterbrand'
                    close-on-select
                    condition="f_meter_brand='{}'">
                  </v-select>
                </div>

            </div>

          </div>
        </criteria>

        <data-grid id='meterlist' partial='list' class="list_area table_sy"  v-ref:grid :model="model">
          <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;color:#3c763d">
                <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'>
            <tr>
              <td style="text-align:center">
                <nobr>{{$index+1}}</nobr>
              </td>
              <td style="text-align:center">
                <span @click="$parent.$parent.$parent.dealmsg(row)"><a>{{row.f_userinfo_code}}</a></span>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_user_name}}</nobr>
              </td>
              <td>
                <nobr>{{row.f_address}}</nobr>
              </td>
              <td style="text-align:center;color:#3c763d" >
                <nobr>
                  {{row.f_meternumber}}
                </nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_meter_brand}}</nobr>
              </td>

              <td style="text-align:center">
                <nobr>{{row.f_meter_base}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_total_fee}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_balance_amount}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_valvestate}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_signal}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_batterylevel}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_magneticInterference}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_orgname}}</nobr>
              </td>
            </tr>
          </template>
        </data-grid>
      </criteria-paged>
    <table class="table-hover">
      <tr style="position: relative" class="table-bordered">
        <td
          style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;color: #5CB95C;font-weight: bold">
          汇总信息
        </td>
        <td style="display: inline-block;width: auto;border-right: 1px solid #F2F6FA;padding: 0px 10px 0px 10px;font-weight: bold">
          累购金额:&emsp;{{model.sums.f_total_fee}}
        </td>
      </tr>
    </table>
    </div>
</template>
<script>
  import {PagedList} from 'vue-client'
  import plugins from '../../../plugins/GetLoginInfoService'
  let readyGen = async function (self) {
    await self.$MagLoadParams.loadParam()
    self.initQueryParam()
    await self.$getConfig(self, 'HandManager')
    console.log('表具管理config', self.config)
    self.getfield = self.config.excelHeaders
    // self.reflash()
  }
  export default {
    title: '表具查询',
    data() {
      return {
        model: new PagedList('rs/sql/manage_getNewMeterBrandAndModel', 50, {}, {
          f_total_fee: 0
        }),
        row: null,
        meterbrand: [],
        searchshow: false,
        orgcondition:' and f_filialeid = ' + this.$login.f.orgid,
        getfield: {},
        org:[this.$login.f.orgid],
        criteriaShow:false,
        config: {
          excelHeaders: {
            'f_userinfo_code': '客户编号','f_user_name': '客户名称','f_address': '客户地址',
            'f_meternumber': '表号','f_meter_brand': '气表品牌','f_meter_base': '气表底数',
            'f_total_fee': '累购金额','f_balance_amount': '表上余额', 'f_valvestate': '阀门状态',
            'f_signal': '信号强度','f_batterylevel': '电压','f_magneticInterference': '磁干扰',
            'f_orgname': '组织机构'
          }
        },
        condition:'f_filialeid = ' + this.$login.f.orgid,
        WarningType: [
          {label: '全部', value: ''}
        ],
        Warningstyle: [
          {label: '全部', value: ''}
        ],
        Warningstyles: [
          {label: '全部', value: ''}
        ],
        styles: false,
        softVwareersion: [],
        Gasusertype: [],
        Gasproperties:[],
        // Gasproperties: this.$refs.paged.$refs.criteria.model.f_user_type.length === 1 ? this.$appdata.getParam(this.model.f_user_type[0]) : [],
        Gasproperties2: [],
        f_signal_1: '',
        f_signal_2: '',
        str: '',
        isBusy: false,
        f_batterylevel_1: 0,
        f_batterylevel_2: 0
      }
    },
    props: ['searchobj', 'isdeal'],
    ready() {
      //初始化气表品牌下拉框
      //初始化客户类型，用气性质，用气属性，软件版本号下拉框
      readyGen(this)
      this.$refs.paged.$refs.criteria.model.f_table_state=['正常']
      this.$refs.paged.$refs.criteria.search()
    },
    watch: {
      'searchobj'(val) {
        if (this.searchobj != null) {
          this.$refs.paged.$refs.criteria.model.f_meternumber = this.searchobj.f_meternumber
          this.$refs.paged.$refs.criteria.search()
        }
      }
    },
    methods: {
      hidden(){
        this.criteriaShow = !this.criteriaShow
      },
      clearmsg() {
        this.$refs.paged.$refs.criteria.model = {}
      },
      clickshow() {
        this.searchshow = !this.searchshow
      },
      dealmsg(val) {
        val.model = this.model.model
        this.$emit('deal-msg', val)
      },
      search(args) {
        this.isBusy = true
        args.condition = `${args.condition} `+this.orgcondition
        this.condition=args.condition
        this.model.search(args.condition, args.model)
      },
      getorg(obj) {
        if(plugins.convertToIn(obj)!==null&&plugins.convertToIn(obj)!==''){
          this.orgcondition = " and f_filialeid in " + plugins.convertToIn(obj)
        }else{
          this.orgcondition = " and f_filialeid = " + this.$login.f.orgid
        }

      },

      userTypeChange () {
        this.gasproperties = []
        if (this.model.f_user_type.length === 1) {
          if (this.model.f_user_type[0]) {
            this.gasproperties = this.$appdata.getParam(this.model.f_user_type[0])
          } else {
            this.$refs.paged.$refs.criteria.model.f_gasproperties = ''
          }
        }
      },
      initQueryParam () {
        let arr = []
        this.$MagGetSaleParam.getGasbrand().forEach((item) => {
          let temp = {}
          if(item.value.f_meter_type==='物联网表'){
            temp.label = item.label
            temp.value = item.value.f_meter_brand
            arr.push(temp )
          }

        })
        this.meterbrand = [{label: '全部', value: ''}, ...arr]
      }
    },
    computed: {
     /* Warningstyle () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('燃气表型号')]
      },*/
      MeterTypes() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')]
      },
      TableStates() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表状态')]
      },
       Gasproperties() {
         let rs = []
         if (this.model.model.f_user_type) {
           rs = this.$appdata.getParam(this.model.model.f_user_type[0])
         }
         return rs
         // return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
       },
      Gasusertype() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      signtype1() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('标记名称')]
      },
      parameterState() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('标记状态')]
      },
      userfilesState() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('上报状态')]
      },
      /*softVwareersion() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('软件版本号')]
      },*/
      valvestate() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('阀门状态')]
      }
    }
  }
</script>
<style>
  .form-input-group label {
    text-align: right;
    width: auto;
  }

  .datapanel {
    color: #333;
    background-color: white;
    box-shadow: darkgrey 0.5px 0.5px 0.5px 0.5px;
    padding: 10px 30px 10px 30px;
    border-radius: 15px;
  }
</style>

