<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="u.f_username = '{}'" 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='用户类型'
                          :value.sync="model.f_user_type"
                          :options='$parent.$parent.usertypes'
                          condition="u.f_user_type = '{}'"
                          close-on-select >
                </v-select>
              </div>
              <div class="form-group">
                <input type="text" class="form-control" v-model="model.f_area" placeholder='区域'
                       condition="u.f_area 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="u.f_districtname like '%{}%'" placeholder='小区'
                       :size="model.f_residential_area ? model.f_districtname.length * 2 : 4">
              </div>
              <div class="form-group">
                <v-select v-model="model.f_operate_status"
                          placeholder="阀门状态"
                          :value.sync="model.f_operate_status"
                          :options='$parent.$parent.valveStatus'
                          condition="v.f_operate_status = '{}'"
                          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="u.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>"'
                           :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/getValveStatus"></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>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align:center">{{$index+1}}</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_usertype}}</td>
          <td style="text-align:center">{{row.f_gasmeterstyle}}</td>
          <td style="text-align:center">{{row.f_operate_status}}</td>
          <td style="text-align:center">{{row.f_close_reason}}</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.id}}</td>
          <td style="text-align:center">{{row.yytdepa}}</td>
        </template>
      </data-grid>
    </criteria-paged>
    <div class="span" v-show="echarts">
      <value-echarts :condition="condition"></value-echarts>
    </div>

    <modal :show.sync="show" v-ref:modal small backdrop="false">
      <header slot="modal-header" class="modal-header">
        <h4 class="modal-title">输入文件名称</h4>
      </header>
      <article slot="modal-body" class="modal-body">
        <div class="form-group">
          <input  type="text" class="form-control" v-model="filename" placeholder='保存的文件名'>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button v-show="show" type="button" class="btn btn-default" @click='close'>取消</button>
        <button v-show="show" type="button" class="btn btn-success" @click='confirm(filename)'>确认</button>
      </footer>
    </modal>
  </div>
</template>

<script>
  import { DataModel, HttpResetClass } from 'vue-client'
  import * as Util from '../../stores/Util'
  import co from 'co'
  import ValueEcharts from './ValueEcharts'
  import { PagedList } from 'vue-client'

  export default {
    title: '阀门统计报表',
    props: ['data'],
    components: {ValueEcharts},
    data () {
      return {
        model: new PagedList('rs/sql/getValveStatus', 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.$getParams('用户类型', [{label: '全部', value: ''}])
      },
      f_outlets () {
        return this.$getParams('网点查询用', [{label: '全部', value: ''}])
      },
      valveStatus () {
        return this.$getParams('阀门状态用', [{label: '全部', value: ''}])
      }
    }
  }
</script>
