<template>
  <div class="flex bg-white p-10  datapanel" v-show="(!echarts)&&(!isActiveTotalForm)">
    <criteria-paged :model="model" :pager='true' v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.search' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row" width="100%">

            <div class="col-sm-3 form-group form-input-group">
              <label class="control-label">表&nbsp;钢&nbsp;号&nbsp;</label>
              <input type="text" class="form-control" v-model="model.f_meternumber" placeholder='表钢号'
                     condition="uf.f_meternumber like '%{}%'" v-next-el='meternumber' v-el:meternumber
              >
            </div>
            <div v-if="$parent.$parent.searchshow" class="form-horizontal select-overspread container-fluid auto">
              <div class="col-sm-3 form-group form-input-group">
                <label class="control-label">组织机构</label>
                <right-tree :userid.sync='$parent.$parent.obj.userid' :source.sync='$parent.$parent.obj.source'
                            :multiple="true"
                            @re-res="$parent.$parent.getRes"></right-tree>
              </div>
              <div class="col-sm-3 form-group form-input-group">
                <label class="control-label">用户类型</label>
                <v-select
                  v-model="model.f_user_type"
                  value-single="true"
                  placeholder='用户类型'
                  :value.sync="model.f_user_type"
                  :options='$parent.$parent.Gasusertype'
                  condition="ui.f_user_type {}"
                  close-on-select>
                </v-select>
              </div>
              <div class="col-sm-3 form-group form-input-group">
                <label class="control-label">用气性质</label>
                <v-select
                  v-model="model.f_gasproperties"
                  placeholder='用气性质'
                  value-single="true"
                  :value.sync="model.f_gasproperties"
                  :options='$parent.$parent.Gasproperties'
                  condition="ui.f_gasproperties {}"
                  close-on-select>
                </v-select>
              </div>
              <div class="col-sm-3 form-group form-input-group">
                <label class="control-label">&nbsp;用&nbsp;户&nbsp;号</label>
                <input type="text" class="form-control" v-model="model.f_userinfo_code" placeholder='用户号'
                       condition="ui.f_userinfo_code like '%{}%'" v-el:xq v-next-el='userinfocode' v-el:username
                >
              </div>
              <div class="col-sm-3 form-group form-input-group">
                <label class="control-label">用户姓名</label>
                <input type="text" class="form-control" v-model="model.f_user_name" placeholder='用户姓名'
                       condition="ui.f_user_name like '%{}%'" v-el:xq v-next-el='username' v-el:username
                >
              </div>
              <div class="col-sm-3 form-group form-input-group">
                <label class="control-label">上报区间</label>
                <datepicker placeholder="开始时间"
                            v-model="model.startDate"
                            :value.sync="model.startDate"
                            condition="m.f_hand_date >= '{}'"
                            :disabled-days-of-Week="[]"
                            :format="'yyyy-MM-dd HH:mm:ss'"

                            :show-reset-button="reset">
                </datepicker>
              </div>
              <div class="col-sm-3 form-group form-input-group">
                <label class="control-label" style="word-break:keep-all;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;</label>
                <datepicker placeholder="结束日期"
                            v-model="model.endDate"
                            :value.sync="model.endDate"
                            condition="m.f_hand_date <= '{}'"
                            :disabled-days-of-Week="[]"
                            :format="'yyyy-MM-dd HH:mm:ss'"
                            :show-reset-button="reset">
                </datepicker>
              </div>
              <div class="col-sm-3 form-group form-input-group">
                <label class="control-label">用气地址</label>
                <input type="text" class="form-control" v-model="model.f_area" placeholder='用气地址'
                       condition="ua.f_address like '%{}%'" v-el:xq v-next-el='address' v-el:area
                >
              </div>
            </div>

            <div class="col-sm-3 form-group ">
              <label class="control-label"></label>
              <button class="btn btn-success" @click="search()">查询</button>
              <label class="control-label"></label>
              <button class="btn btn-default" @click="$parent.$parent.clearmsg">清空</button>
              <label class="control-label" v-if="!$parent.$parent.excelTable">超过十万条限制导出</label>
              <export-excel v-if="$parent.$parent.excelTable"
                            :data="{condition: $parent.$parent.condition,startDate: model.startDate, endDate: model.endDate}"
                            :field="$parent.$parent.getfield"
                            sqlurl="rs/logic/exportfile" sql-name="manage_getReportList"
                            template-name='ReportList'
                            :choose-col="true"></export-excel>

            </div>
            <div v-show="!$parent.$parent.searchshow" @click="$parent.$parent.clickshow"
                 style="position: relative;float: right;margin-right: 1%;">
              <img src="../../../static/webMeter/shousuo.png"><span>展开</span>
            </div>
            <div v-show="$parent.$parent.searchshow" @click="$parent.$parent.clickshow"
                 style="position: relative;float: right;margin-right: 1%;">
              <img src="../../../static/webMeter/shangsheng.png"><span>收缩</span>
            </div>

          </div>
        </div>
      </criteria>
      <data-grid id="lostuserlist"  class="list_area table_sy" :model="model" partial='list' 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>
          </tr>

        </template>
        <template partial='body'>
          <td style="text-align:center"><nobr>{{row.f_filiale}}</nobr></td>
          <td style="text-align:center">{{row.f_userinfo_code}}</td>
          <td style="text-align:center">{{row.f_user_type}}</td>
          <td style="text-align:center">{{row.f_gasproperties}}</td>
          <td style="text-align:center">{{row.f_user_name}}</td>
          <td style="text-align:center">{{row.f_address}}</td>
          <td style="text-align:center"><nobr>{{row.f_hand_date}}</nobr></td>
          <th style="text-align:center"><nobr>{{row.f_insert_date}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_jval}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_tablebase}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_valvestate}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_upload_type}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.flowmeterpressure}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.flowmetertemperature}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_signal}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_snr}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_batterylevel}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.totalflow}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.operatingmodeflow}}</nobr></th>

        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'
  import * as Util from '../../Util'
  import getLodop from '../../plugins/LodopFuncs'
  import {HttpResetClass} from 'vue-client'

  export default {
    title: '采集查询',
    data() {
      return {
        model: new PagedList('rs/sql/manage_getReportList', 20, {
          startDate: 'this.model.startDate',
          endDate: 'this.model.endDate'
        }),
        reportStr: null,
        show: false,
        startDate: '',
        endDate: '',
        Gasusertype: [],
        Gasproperties: [],
        Gasproperties2: [],
        outlets: [],
        operator: [],
        filename: '',
        echarts: false,
        searchshow: false,
        isActiveTotalForm: false,
        condition: '1=1',
        filialeCodeStr: '',
        excelTable: true,
        getfield: {
          'f_filiale': '组织机构',
          'f_userinfo_code': '用户号',
          'f_user_type': '用户类型',
          'f_gasproperties': '用气性质',
          'f_user_name': '用户姓名',
          'f_address': '用气地址',
          'f_hand_date': '上报日期',
          'f_insert_date': '系统接收时间',
          'f_jval': '表内剩余金额',
          'f_tablebase': '本次抄表底数',
          'f_valvestate': '阀门状态',
          'f_upload_type': '上报类型',
          'flowmetertemperature': '温度',
          'flowmeterpressure': '压力',
          'f_signal': '噪音强度',
          'f_snr': '信噪比',
          'f_batterylevel': '电压',
          'totalflow': '累计流量',
          'operatingmodeflow': '瞬时流量'
        },
        obj: {
          userid: this.$login.f.id,
          source: `tool.getFullTree(this.getRights().where(row.getType() == $organization$))`,
          res: this.$login.f.f_fengongsi,
          resids: this.$login.f.f_orgids
        }
      }
    },
    ready() {
      this.$refs.paged.$refs.cri.model.startDate = Util.toStandardDateString() + ' 00:00:00'
      this.$refs.paged.$refs.cri.model.endDate = Util.toStandardDateString() + ' 23:59:59'
      //初始化用户类型，用气性质下拉框
      this.getTypes()
    },
    methods: {
      clickshow() {
        this.searchshow = !this.searchshow
      },
      search(args) {
        let start = this.$refs.paged.$refs.cri.model.startDate
        let end = this.$refs.paged.$refs.cri.model.endDate
        if (start == null || start == '' || end == null || end == '') {
          return this.$showMessage("上报区间的开始和结束时间不能为空！")
        }
        this.startDate = start
        this.endDate = end
        const filialeCondition = this.filialeCodeStr || this.getDefaultOrgCondition()
        if (filialeCondition) {
          args.condition = `${args.condition} and ${filialeCondition}`
        }
        let str = args.condition
        this.model.search(args.condition, args.model)
        console.log(str + "str")
        this.condition = str
      },
      getRes(obj) {
        this.obj.res = obj.res
        this.obj.resids = obj.resids
        const ids = (obj.resids || '').split(',').map(item => item.trim()).filter(item => item)
        if (ids.length <= 1) {
          this.filialeCodeStr = ids[0] ? `ui.f_filialeids like '${ids[0]}%'` : ''
        } else {
          const parts = ids.map(code => `ui.f_filialeids like '${code}%'`)
          this.filialeCodeStr = `(${parts.join(' or ')})`
        }
      },
      getDefaultOrgCondition () {
        const defaultOrg = this.$login.f.f_orgids || ''
        return defaultOrg ? `ui.f_filialeids like '${defaultOrg}%'` : ''
      },
      clearmsg() {
        this.$refs.paged.$refs.cri.model = {}
      },
      close() {
        this.show = false
      },
      // 显示汇总数据表格
      showTotalForm() {
        this.echarts = false
        this.isActiveTotalForm = true
      },
    },
    watch: {
    },
    computed: {
      Gasusertype() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      Gasproperties() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
      }
    }
  }
</script>
<style>
  .form-input-group label {
    text-align: right;
    width: auto;
  }

  .mystyle {
    float: right;
    padding-right: 10%;
  }

  .mystyle1 {
    padding-top: 10px;

  }

  .mystyle2 {
    width: 100%;
    height: 35px;
    padding-left: 15px;
    float: left;
  }

  .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>
