<template>
  <div id='app1' 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-2 form-group">
              <label class="control-label">表&emsp;钢&emsp;号</label>
              <input type="text" class="form-control" v-model="model.f_meternumber" placeholder='表钢号'
                     condition="f_meternumber = '{}'" v-next-el='meternumber' v-el:meternumber
              >
            </div>
            <div v-if="$parent.$parent.searchshow">
              <div class="col-sm-2 form-group">
                <label class="control-label">组织机构</label>
                <right-tree :userid.sync='$parent.$parent.obj.userid' :source.sync='$parent.$parent.obj.source'
                            @re-res="$parent.$parent.getRes"></right-tree>
              </div>
              <div class="col-sm-2 form-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-2 form-group">
                <label class="control-label">客户编号</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='f_userinfo_code' v-el:username
                >
              </div>
              <div class="col-sm-2 form-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 class="col-sm-2 form-group">
                <label class="control-label">用户类型</label>
                <v-select id="f_user_type"
                          v-model="model.f_user_type"
                          placeholder='用户类型'
                          :value.sync="model.f_user_type"
                          :options='$parent.$parent.usertypes'
                          condition="u.f_user_type = '{}'"
                          close-on-select>
                </v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="control-label">用气性质</label>
                <v-select id="f_gasproperties"
                          v-model="model.f_gasproperties"
                          placeholder='用气性质'
                          :value.sync="model.f_gasproperties"
                          :options='$parent.$parent.Gasproperties'
                          condition="u.f_gasproperties = '{}'"
                          close-on-select>
                </v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="control-label">用气属性</label>
                <v-select
                  placeholder='用气属性'
                  :value.sync="model.f_gasproperties2"
                  v-model="model.f_gasproperties2"
                  :options='$parent.$parent.Gasproperties2'
                  close-on-select condition="f_gasproperties2='{}'">
                </v-select>
              </div>

              <div class="col-sm-2 form-group">
                <label class="control-label">异常类型</label>
                <v-select id="f_error_type"
                          v-model="model.f_error_type"
                          placeholder='异常类型'
                          :value.sync="model.f_error_type"
                          :options='$parent.$parent.Geterrtype'
                          condition="f_error_type = '{}'"
                          close-on-select>
                </v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="control-label">上报区间</label>
                <datepicker id="startdate" placeholder="开始时间"
                            v-model="model.startDate"
                            :value.sync="model.startDate"
                            :disabled-days-of-Week="[]"
                            :format="'yyyy-MM-dd HH:mm:ss'"
                            :show-reset-button="reset">
                </datepicker>
              </div>
              <div class="col-sm-2 form-group">
                <label class="control-label" style="word-break:keep-all;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;</label>
                <datepicker id="enddate" placeholder="结束日期"
                            v-model="model.endDate"
                            :value.sync="model.endDate"
                            :disabled-days-of-Week="[]"
                            :format="'yyyy-MM-dd HH:mm:ss'"
                            :show-reset-button="reset">
                </datepicker>
              </div>
            </div>
            <div class="col-sm-2 form-group form-group ">
              <label class="control-label"></label>
              <button class="btn btn-success width-50" @click="search()">查询</button>
              <label class="control-label"></label>
              <button class="btn btn-default width-100" @click="$parent.$parent.clearmsg">清空</button>
              <label class="control-label"></label>
              <button class="btn btn-success width-100" @click="$parent.$parent.SaveAsFile('lostuserlist')">导出</button>
            </div>
            <div class="col-sm-2 form-group form-group ">
              <label class="control-label"></label>
              <button class="btn btn-success width-50" @click="$parent.$parent.showTotalForm()">显示汇总</button>
              <label class="control-label"></label>
              <button class="btn btn-success width-50" @click="$parent.$parent.showEcharts()">显示图表</button>
            </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>

            <!--: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>
      </criteria>
      <data-grid id="lostuserlist" :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>
          </tr>

        </template>
        <template partial='body'>
          <td style="text-align:center">
            <nobr>{{$index+1}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_filiale}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_user_type}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_gasproperties}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_gasproperties2}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_userinfo_code}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_user_name}}</nobr>
          </td>
          <td>
            <nobr>{{row.f_address}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_gas_date}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_meternumber}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_error_level}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_error_type}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_error_msg}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_insert_date}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_error_reason}}</nobr>
          </td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
  <div v-show="echarts" style="height: 40px;width: 100%;">
    <div style="display: inline-block;">
      <button class="btn btn-success width-50" @click="notShowEcharts()">隐藏图表</button>
    </div>
    <!--图显示模板-->
    <div class="mystyle" style="display: inline-block;">
      <label class="control-label">图表统计项</label>
      <v-select id="groupname" v-model="groupname"
                placeholder='分组项'
                value-single="true"
                :value.sync="groupname"
                :options='getgroupname'
                close-on-select></v-select>
    </div>
  </div>
  <div v-show="echarts" style="width: 100%;height: 90%;">
    <new-exception-echarts :condition="condition" :startdate="startDate" :groupname="groupname[0]"
                           :enddate="endDate" :echarts="echarts"></new-exception-echarts>
  </div>
  <div v-show="isActiveTotalForm" style="height: 40px;width: 100%;">
    <button class="btn btn-success width-50" @click="notShowTotalForm()">隐藏汇总</button>
  </div>
  <div v-show="isActiveTotalForm" style="width: 100%;height: 90%;">
    <new-exception-eform :condition="condition" :startdate="startDate"
                         :enddate="endDate"></new-exception-eform>
  </div>
</template>

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

  export default {
    title: '异常分析',
    props: ['data'],
    components: {NewExceptionEcharts, NewExceptionEform},
    data() {
      return {
        model: new PagedList('rs/sql/webmeter_getNewExceQuery', 20, {
          startDate: 'this.model.startDate',
          endDate: 'this.model.endDate'
        }),
        reportStr: null,
        show: false,
        startDate: '',
        endDate: '',
        groupname: ['year'],
        getgroupname: [
          {label: '年份', value: 'year'},
          {label: '月份', value: 'month'},
          {label: '周', value: 'week'},
          {label: '日', value: 'day'}
        ],
        outlets: [],
        operator: [],
        filename: '',
        echarts: false,
        searchshow: false,
        isActiveTotalForm: false,
        condition: '1=1',
        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.getdata()
    },
    methods: {
      clickshow() {
        this.searchshow = !this.searchshow
      },
      search(args) {
        this.startDate = this.$refs.paged.$refs.cri.model.startDate
        this.endDate = this.$refs.paged.$refs.cri.model.endDate
        this.obj.resids = this.obj.resids
        args.condition = `${args.condition} and u.f_filialeids like '${this.obj.resids}%'`
        this.condition = args.condition
        this.model.search(args.condition, args.model)
        // this.condition = this.$refs.paged.$refs.cri.condition
      },
      getdata() {
        this.startDate = this.$refs.paged.$refs.cri.model.startDate
        this.endDate = this.$refs.paged.$refs.cri.model.endDate
        this.$refs.paged.$refs.cri.search()
        this.condition = this.$refs.paged.$refs.cri.condition
      },
      getRes(obj) {
        this.obj.res = obj.res
        this.obj.resids = obj.resids
      },
      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 = {}
      },
      close() {
        this.show = false
      },
      // 显示柱状图
      showEcharts() {
        this.echarts = true
        this.isActiveTotalForm = false
      },
      notShowTotalForm() {
        this.echarts = false
        this.isActiveTotalForm = false
      },
      // 不显示柱状图
      notShowEcharts() {
        this.echarts = false
        this.isActiveTotalForm = false
      },
      // 显示汇总数据表格
      showTotalForm() {
        this.echarts = false
        this.isActiveTotalForm = true
      }
    },
    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 [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      Gasproperties() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
      },
      Geterrtype() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('异常类型')]
      },
      Gasproperties2() {
        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;
    /*background: #00A3F0;*/
    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>
