<template>
  <div id='app' class="flex" >
    <criteria-paged :model="model" :pager='true' v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:cri>
        <div novalidate class="form-inline auto " partial >
          <p class="bg-info text-center" style="padding: 8px;">用户用气量报表</p>
          <div class="flex-row auto" style="justify-content: space-between">
            <div class="form-group" >
              <div class="form-group">
                <input  type="text" class="form-control" v-model="model.f_username" placeholder='用户姓名'
                        condition="f_user_name = '{}'" v-next-el='userid' v-el:username
                        :size="model.f_user_name ? model.f_user_name.length * 2 : 4">
              </div>
              <div class="form-group">
                <v-select id="f_user_type"
                          v-model="model.f_usertype"
                          placeholder='f_username'
                          :value.sync="model.f_user_type"
                          :options='$parent.$parent.usertypes'
                          condition="f_user_type = '{}'"
                          close-on-select >
                </v-select>
              </div>
              <div class="form-group">
              <datepicker id="startDate" placeholder="用气开始日期"
                          v-model="model.startDate"
                          :value.sync="model.startDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd 00:00:00'"
                          condition= "f_delivery_date >= '{}'"
                          :show-reset-button="reset">
              </datepicker>
              </div>
                <div class="form-group">
              <datepicker id="endDate" placeholder="用气结束日期"
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd 23:59:59'"
                          condition= "f_delivery_date <= '{}'"
                          :show-reset-button="reset">
              </datepicker>
                </div>
              <div class="form-group">
                <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
                       :size="model.f_area ? model.f_area.length * 2 : 2">
              </div>
              <div class="form-group">
                <input type="text" class="form-control" v-model="model.f_districtname"
                       condition="f_address like '%{}%'" placeholder='小区'
                       :size="model.f_residential_area ? model.f_districtname.length * 2 : 4">
              </div>
              <div class="form-group">
                <v-select v-model="model.f_gasmeterstyle"
                          placeholder="表具类型"
                          :value.sync="model.f_gasmeterstyle"
                          :options='$parent.$parent.valveStatus'
                          condition="f_meter_type = '{}'"
                          close-on-select >
                </v-select>
              </div>
              <div class="form-group">
                <v-select :value.sync="model.yytdepa" v-model='model.yytdepa'
                          :options='$parent.$parent.f_outlets' placeholder='营业网点'
                          close-on-select
                          condition="f_filiale = '{}'"></v-select>
              </div>
              <button class="btn btn-success" @click="$parent.$parent.getdata()">查询</button>
              <button class="btn btn-success" @click="$parent.$parent.confirmReport()">保存报表</button>
            </div>
            <span></span>
            <div class="form-group">
              <button class="btn btn-default" v-if="!$parent.$parent.echarts" @click="$parent.$parent.showEcharts()">显示图表</button>
              <button class="btn btn-default" v-if="$parent.$parent.echarts" @click="$parent.$parent.showEcharts()">隐藏图表</button>
              <print-table :model='$parent.model'
                           :top='40' :left='60' :right='40' :bottom='60'
                           :thead='"<th>序号</th>\n"+
                          "<th>档案编号</th>" +
                            " <th>档案标识</th>"+
                              "<th>用户名称</th>"+
                             "<th>表号</th"+
                                "<th>表具类型</th>"+
                                "<th>用户类型</th>"+
                                  "<th>区域</th>"+
                                  "<th>小区</th>"+
                                  "<th>地址</th>"+
                                "<th>用气气量</th>"+
                                   "<th>用气金额</th>"
                                   +"<th>用气价格</th>"
                                   +"<th>时间</th>"
                                   +"<th>所属机构</th>"'
                           :fields='["$index+1","f_username","f_meternumber","f_usertype","f_save_money","f_operate_status","f_close_reason","f_area","f_districtname","f_address","id","yytdepa"]'>
              </print-table>
              <export-excel :data="{orderitem: 'lastinputdate desc', condition: '1=1'}"
                            :field="{f_username: '用户姓名', f_meternumber: '表号',f_usertype:'用户类型',f_save_money:'剩余金额',
                            f_operate_status:'状态',f_close_reason:'关阀原因',f_area:'区域',f_districtname:'小区', f_address: '地址',id:'档案编号',yytdepa:'所属机构'}"
                            sqlurl="rs/sql/getUserGas"></export-excel>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th  style="text-align:center">序号</th>
            <th  style="text-align:center">档案编号</th>
            <th  style="text-align:center">档案标识</th>
            <th  style="text-align:center">用户名称</th>
            <th  style="text-align:center">表号</th>
            <th  style="text-align:center">表具类型</th>
            <th  style="text-align:center">用户类型</th>
            <th  style="text-align:center">区域</th>
            <th  style="text-align:center">小区</th>
            <th  style="text-align:center">地址</th>
            <th  style="text-align:center">用气气量</th>
            <th  style="text-align:center">用气金额</th>
            <th  style="text-align:center">用气价格</th>
            <th  style="text-align:center">时间</th>
            <th  style="text-align:center">所属机构</th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align:center">{{$index+1}}</td>
          <td style="text-align:center">{{row.f_userinfoid}}</td>
          <td style="text-align:center">{{row.f_huhao}}</td>
          <td style="text-align:center">{{row.f_username}}</td>
          <td style="text-align:center">{{row.f_meternumber}}</td>
          <td style="text-align:center">{{row.f_gasmeterstyle}}</td>
          <td style="text-align:center">{{row.f_usertype}}</td>
          <td style="text-align:center">{{row.f_area}}</td>
          <td style="text-align:center">{{row.f_districtname}}</td>
          <td style="text-align:center">{{row.f_address}}</td>
          <td style="text-align:center">{{row.f_pregas}}</td>
          <td style="text-align:center">{{row.f_preamount}}</td>
          <td style="text-align:center">{{row.f_gasprice}}</td>
          <td style="text-align:center">{{row.f_deliverydate}}</td>
          <td style="text-align:center">{{row.f_sgnetwork}}</td>
        </template>
      </data-grid>
    </criteria-paged>
    <div class="span" v-show="echarts">
      <user-gas-echarts :condition="condition"></user-gas-echarts>
    </div>

  </div>
</template>

<script>
  import ValueEcharts from './ValueEcharts'
  import { PagedList } from 'vue-client'
  import UserGasEcharts from "./UserGasEcharts";
  import AppData from "../../stores/AppData"

  export default {
    title: '用户用气量报表',
    props: ['data'],
    components: {UserGasEcharts, ValueEcharts},
    data () {
      return {
        model: new PagedList('rs/sql/getUserGas', 20),
        reportStr: null,
        show: false,
        outlets: [],
        operator: [],
        filename: '',
        echarts: true,
        condition: '1=1'
      }
    },
    ready () {
      this.getdata()
    },
    methods: {
      getdata () {
        this.$refs.paged.$refs.cri.search()
        this.condition = this.$refs.paged.$refs.cri.condition
      },
      showEcharts () {
        this.echarts = !this.echarts
      },
      close () {
        this.show = false
      },

    },
    watch: {
      'data' (val) {
        if (val.f_files_path) {
          this.getFileContent(val.f_files_path)
        } else {
          this.reportStr = null
        }
      }
    },
    computed: {
      // usertypes () {
      //   return this.$appdate.getParams("用户类型")
      // },
      usertypes () {
        return AppData.getParam('用户类型')
      },
      // usertypes () {
      //   return this.$getParams('用户类型', [{label: '全部', value: ''}])
      // },
      f_outlets () {
        return this.$getParams('网点查询用', [{label: '全部', value: ''}])
      },
      valveStatus () {
        return this.$getParams('表具类型', [{label: '全部', value: ''}])
      }
    }
  }
</script>
