<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="f_meternumber like '%{}%'" v-next-el='meternumber' v-el:meternumber
              >
            </div>
            <div class="col-sm-3 form-group form-input-group" title="参数：异常状态">
              <label class="control-label">异常状态</label>
              <v-select
                placeholder='异常状态'
                :value.sync="model.f_price_state"
                v-model="model.f_price_state"
                :options='$parent.$parent.price_state'
                close-on-select
                condition="f_price_state='{}'">
              </v-select>
            </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="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="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="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="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>
                <input type="text" class="form-control" v-model="model.f_area" placeholder='用气地址'
                       condition="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}"
                            :field="$parent.$parent.getfield"
                            sqlurl="rs/logic/exportfile" sql-name="manage_gasPriceList"
                            template-name='gasPriceList'
                            :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>


            <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">{{row.f_meter_brand}}</td>

          <th style="text-align:center"><nobr>{{row.f_calculation}}</nobr></th>
          <td style="text-align:center"><nobr>{{row.f_meternumber}}</nobr></td>

          <th style="text-align:center"><nobr>{{row.f_hand_date}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.oughtamount}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_last_jval}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_jval}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_oughtfee}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.h_price}}</nobr></th>

          <th style="text-align:center"><nobr>{{row.f_price_type}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_price}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_price2}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_price3}}</nobr></th>


          <th style="text-align:center"><nobr>{{row.f_price_state}}</nobr></th>
          <th style="text-align:center"><nobr>{{row.f_valvestate}}</nobr></th>


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

<script>
  import {PagedList} from 'vue-client'

  export default {
    title: '气价监控查询',
    data() {
      return {
        model: new PagedList('rs/sql/manage_gasPriceList', 20),
        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_meter_brand': '气表品牌',
          'f_calculation': '结算方式',
          'f_meternumber': '表钢号',
          'f_hand_date': '最后抄表时间',
          'oughtamount': '最后上报气量',
          'f_last_jval': '表端上报上期余额',
          'f_jval': '表端上报本期余额',
          'f_oughtfee': '扣减金额',
          'h_price': '计算单价',
          'f_price_type': '气价类型',
          'f_price': '系统一阶单价',
          'f_price2': '系统二阶单价',
          'f_price3': '系统三阶单价',
          'f_price_state': '异常状态',
          'f_valvestate': '阀门状态'
        },
        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) {
        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)
        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] ? `f_filialeids like '${ids[0]}%'` : ''
        } else {
          const parts = ids.map(code => `f_filialeids like '${code}%'`)
          this.filialeCodeStr = `(${parts.join(' or ')})`
        }
      },
      getDefaultOrgCondition () {
        const defaultOrg = this.$login.f.f_orgids || ''
        return defaultOrg ? `f_filialeids like '${defaultOrg}%'` : ''
      },
      clearmsg() {
        this.$refs.paged.$refs.cri.model = {}
      },
      close() {
        this.show = false
      },
      // 显示汇总数据表格
      showTotalForm() {
        this.echarts = false
        this.isActiveTotalForm = true
      },
    },
    watch: {
    },
    computed: {
      price_state () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('异常状态')]
      },
      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>
