<template>
  <div class="flex-row binary" id="unit">
    <div class="basic-main" @keyup.enter="search1">
      <div class="flex">
        <div class="flex" style="flex:1;" v-show="!echarts">
          <criteria-paged :model="model" :pager='true' v-ref:paged>
            <criteria @condition-changed='$parent.search' partial='criteria' v-ref:cri>
              <div class="form-horizontal select-overspread container-fluid auto" novalidate partial>
                <div class="row" width="100%">
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">表&ensp;钢&ensp;号</label>
                    <input   style="width:60%" class="input_search" condition="uf.f_meternumber like '%{}%'" placeholder='表钢号' type="text"
                           v-el:meternumber v-model="model.f_meternumber" v-next-el='meternumber'
                    >
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">组织机构</label>
                    <res-select :initresid="$parent.$parent.orgid"
                                @res-select="$parent.$parent.getRes"
                                restype='organization' style="width: 60%">
                    </res-select>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">客户编号</label>
                    <input   style="width:60%" class="input_search" condition="u.f_userinfo_code   like '%{}%'" placeholder='客户编号' type="text"
                           v-el:meternumber v-model="model.f_userinfo_code" v-next-el='f_userinfo_code'
                    >
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">客户名称</label>
                    <input   style="width:60%" class="input_search" condition="u.f_user_name like '%{}%'" placeholder='客户名称' type="text"
                           v-el:username v-model="model.f_username" v-next-el='userid'>
                  </div>
                  <div class="span" style="float:right;">
                    <button @click="search()" class="button_search button_spacing">查询</button>
                    <button @click="$parent.$parent.clearmsg" class="button_clear button_spacing">清空</button>
                    <export-excel :data="$parent.$parent.getCondition" class="button_export button_spacing"
                                  :field="$parent.$parent.getfield"
                                  sqlurl="rs/logic/exportfile" sql-name="webmeter_getNewInstructChanceList" template-name='指令分析'
                                  :choose-col="true"></export-excel>
<!--                    <button @click="$parent.$parent.showEcharts()" class="button_export button_spacing">显示图表</button>-->
                    <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 form-group">
                    <label class="font_normal_body">客户地址</label>
                    <input   style="width:60%" class="input_search" condition="a.f_address like '%{}%'" placeholder='地址' type="text"
                           v-el:area v-el:xq v-model="model.f_address" v-next-el='address'
                    >
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">用户分类</label>
                    <v-select :value.sync="model.f_user_type"
                              @change="$parent.$parent.userTypeChange"
                              :options='$parent.$parent.usertypes' placeholder='请选择' v-model="model.f_user_type"
                              condition="uf.f_user_type = '{}'"
                              close-on-select></v-select>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">用户类型</label>
                    <v-select :value.sync="model.f_user_mold"
                              @change="$parent.$parent.userMoldChange"
                              :options='$parent.$parent.usermold' placeholder='请选择' v-model="model.f_user_mold"
                              condition="uf.f_user_mold = '{}'"
                              close-on-select></v-select>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body">用气性质</label>
                    <v-select :value.sync="model.f_gasproperties" v-model="model.f_gasproperties"
                              :options='$parent.$parent.gasproperties' placeholder='请选择'
                              condition="uf.f_gasproperties = '{}'"
                              close-on-select></v-select>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body" style="word-break:keep-all;">上报时间</label>
                    <datepicker :format="'yyyy-MM-dd HH:mm:ss'"
                                :value.sync="model.startDate"
                                style="width:60%"
                                placeholder="起始时间"
                                v-model="model.startDate"
                    ></datepicker>
                  </div>
                  <div class="col-sm-2 form-group">
                    <label class="font_normal_body" style="word-break:keep-all;">&emsp;&ensp;至&emsp;</label>
                    <datepicker :format="'yyyy-MM-dd HH:mm:ss'"
                                :value.sync="model.endDate"
                                placeholder="结束时间"
                                style="width:60%"
                                v-model="model.endDate"
                    ></datepicker>
                  </div>

                </div>
              </div>
            </criteria>
            <data-grid :model="model" id="reportgas" partial='list' class="list_area table_sy" v-ref:grid>
              <template partial='head'>
                <tr>
                  <th style="text-align:center">序号</th>
                  <th style="text-align:center">
                    <nobr>上报日期</nobr>
                  </th>
                  <th style="text-align:center" title="在用户数:表具状态为正常的用户数">
                    <nobr>在用户数</nobr>
                  </th>
                  <th style="text-align:center" title="停用户数:表具状态为停用的用户数">
                    <nobr>停用户数</nobr>
                  </th>

                  <th style="text-align:center" title="指令下发成功表具数">
                    <nobr>指令下发成功表具数</nobr>
                  </th>
                  <th style="text-align:center" title="指令下发总表具数">
                    <nobr>指令下发总表具数</nobr>
                  </th>
                  <th style="text-align:center" title="表具指令成功率=指令上报成功表具数/指令上报总表具数">
                    <nobr>表具指令成功率</nobr>
                  </th>
                  <th style="text-align:center" title="成功指令数">
                    <nobr>成功指令数</nobr>
                  </th>
                  <th style="text-align:center" title="总指令数">
                    <nobr>总指令数</nobr>
                  </th>
                  <th style="text-align:center" title="指令成功率=成功指令数/总指令数">
                    <nobr>指令成功率</nobr>
                  </th>
                  <th style="text-align:center" title="综合指令成功率=指令下发总表具数/在用户数">
                    <nobr>综合指令成功率</nobr>
                  </th>
                </tr>
              </template>
              <template partial='body' partial='list' v-ref:grid>
                <tr>
                  <td style="text-align:center">{{$index + 1}}</td>
                  <td style="text-align:center;width: 170px;">
                    <nobr>{{row.f_insert_date}}</nobr>
                  </td>
                  <td style="text-align:center">{{row.zaiyong}}</td>
                  <th style="text-align:center">{{row.tingyong}}</th>

                  <td style="text-align:center">{{row.c0}}</td>
                  <th style="text-align:center">{{row.c}}</th>
                  <th style="text-align:center">{{row.f_bv1}}</th>
                  <td style="text-align:center">
                    <nobr>{{row.success}}</nobr>
                  </td>
                  <td style="text-align:center">
                    <nobr>{{row.c1}}</nobr>
                  </td>
                  <td style="text-align:center">
                    <nobr>{{row.f_bv2}}</nobr>
                  </td>
                  <td style="text-align:center">
                    <nobr>{{row.f_bv0}}</nobr>
                  </td>
                </tr>
              </template>
              <template partial='foot'></template>
            </data-grid>
          </criteria-paged>
        </div>
        <div style="height: 40px;width: 100%;" v-show="echarts">
          <button @click="showEcharts()" class="button_search button_spacing">隐藏图表</button>
        </div>
        <!--      图显示模板-->
        <div class="span " style="width: 100%;" v-show="echarts">
          <user-instruct-echarts-list :condition="condition" :echarts="echarts"
                                      :enddate="endDate" :startdate="startDate"></user-instruct-echarts-list>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  import {PagedList} from 'vue-client'
  import * as Util from '../../../Util'
  import getLodop from '../../../plugins/LodopFuncs'
  import UserInstructEchartsList from './UserInstructEchartsList'
  import plugins from '../../../plugins/GetLoginInfoService'

  export default {
    title: '指令分析',
    props: ['data'],
    components: {UserInstructEchartsList},
    data() {
      return {
        model: new PagedList('rs/sql/webmeter_getNewInstructChanceList', 100, {
          startDate: 'this.model.startDate',
          endDate: 'this.model.endDate'
        }),
        condition: '1=1',
        startDate: '',
        endDate: '',
        getfield:{"f_insert_date":"上报日期","zaiyong":"在用户数",
          "tingyong":"停用户数",
          "c0":"指令下发成功表具数","c":"指令下发总表具数",
          "f_bv1":"表具指令成功率",
          "success":"成功指令数","c1":"总指令数",
          "f_bv2":"指令成功率",
          "f_bv0":"综合指令成功率"
        },
        criteriaShow: false,
        echarts: false,
        gasproperties:[],
        usermold:[],
        searchshow: false,
        orgCondtionStr: '(' + this.$login.f.orgid + ')',
        orgid: [this.$login.f.orgid]
      }
    },
    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.getdata()
    },
    methods: {
      userTypeChange () {
        this.usermold=[]
        this.f_gasproperties=[]
        if(this.$refs.paged.$refs.cri.model !== null) {
          this.$refs.paged.$refs.cri.model.f_gasproperties=''
          this.$refs.paged.$refs.cri.model.f_user_mold=''
          this.usermold = this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_user_type[0])
        }
        else{
          this.usermold =[{label: '全部', value: ''}]
        }
      },
      userMoldChange () {
        this.gasproperties=[]
        if(this.$refs.paged.$refs.cri.model !==null) {
          this.$refs.paged.$refs.cri.model.f_gasproperties=''
          if (this.$refs.paged.$refs.cri.model.f_user_mold[0] ==='居民'){
            this.gasproperties = this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_user_type[0] + this.$refs.paged.$refs.cri.model.f_user_mold[0])
            return
          }
          this.gasproperties = this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_user_mold[0])
        }
        else{
          this.gasproperties =[{label: '全部', value: ''}]
        }
      },
      search1(){
        this.$refs.paged.$refs.cri.search()
      },
      // 查询开关
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      getdata() {
        this.startDate = this.$refs.paged.$refs.cri.model.startDate
        this.endDate = this.$refs.paged.$refs.cri.model.endDate
        if (this.orgCondtionStr)
          this.condition = this.$refs.paged.$refs.cri.condition + 'and uf.f_orgid in ' + this.orgCondtionStr
        this.$refs.paged.$refs.cri.search()
      },
      // 显示柱状图
      showEcharts() {
        this.echarts = !this.echarts
      },
      close() {
        this.show = false
      },
      // SaveAsFile(str) {
      //   this.$showMessage('您是否需要导出本页数据？', ['confirm', 'cancel']).then((res) => {
      //     if (res === 'confirm') {
      //       let style = '<style>' +
      //         'td {border-width: 1px;padding: 2px;border-style: solid; border-color:black; border-collapse:collapse;} .tdright{text-align: right;}  .tdcenter{text-align: center;}</style>';
      //       let strHtml = style + document.getElementById(str).innerHTML;
      //       console.log(strHtml);
      //       let LODOP = getLodop();
      //       LODOP.PRINT_INIT('');
      //       LODOP.ADD_PRINT_TABLE(5, 5, '99%', '100%', strHtml);
      //       LODOP.SAVE_TO_FILE('抄表统计.xls')
      //     }
      //   })
      // },
      clearmsg() {
        this.$refs.paged.$refs.cri.model = {}
      },
      search(args) {
        this.startDate = this.$refs.paged.$refs.cri.model.startDate
        this.endDate = this.$refs.paged.$refs.cri.model.endDate
        if (this.endDate == '' || this.startDate == '') {
          return this.$showMessage("时间区间的开始和结束时间不能为空！")
        }
        if (this.orgCondtionStr)
          args.condition = `${args.condition}` + 'and uf.f_orgid in ' + this.orgCondtionStr
        this.condition = args.condition
        this.model.search(args.condition, args.model)
      },
      getRes(obj) {
        this.orgCondtionStr = plugins.convertToIn(obj)
      }
    },
    computed: {
      getCondition() {
        var con=""
        if (this.orgCondtionStr) {
          con= `${this.$refs.paged.$refs.cri.condition} and u.f_orgid in  ${this.orgCondtionStr}`
        }
        else{
          con= `${this.$refs.paged.$refs.cri.condition} `
        }
        return {
          condition: con  ,
          startDate:`${this.$refs.paged.$refs.cri.model.startDate}`,
          endDate:`${this.$refs.paged.$refs.cri.model.endDate}`
        }

      },
      usertypes() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      Getuserstyle() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气类型')]
      }
    }
  }
</script>
<style>
  .mystyle {
    margin-left: 80px;
  }

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