<template>
  <div id='app1' class="basic-main" 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" novalidate partial>
          <div class="row" >
            <!--<div class="form-group">-->
            <!--<input @keyup.enter="search"   style="width:60%"  type="text" class="input_search" 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 : 8">-->
            <!--</div>-->
            <div class="col-sm-2">
              <label class="font_normal_body">表&nbsp;钢&nbsp;号&nbsp;</label>
              <input @keyup.enter="search"   style="width:60%" type="text" class="input_search" v-model="model.f_meternumber" placeholder='表钢号'
                     condition="u.f_meternumber like '%{}%'" v-next-el='meternumber' v-el:meternumber
              >
            </div>
            <div class="col-sm-2">
              <label class="font_normal_body">组织机构</label>
              <res-select :initresid="$parent.$parent.orgid"
                          style="width:60%"
                          @res-select="$parent.$parent.getRes"
                          restype='organization'>
              </res-select>
            </div>
            <div class="col-sm-2">
              <label class="font_normal_body">客户编号</label>
              <input @keyup.enter="search"   style="width:60%" type="text" class="input_search" 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-2">
              <label class="font_normal_body">客户名称</label>
              <input @keyup.enter="search"   style="width:60%" type="text" class="input_search" v-model="model.f_user_name" placeholder='客户名称'
                      condition="f_user_name like '%{}%'" v-el:xq v-next-el='username' v-el:username
              >
            </div>


            <div style="float:right">
              <button class="button_search button_spacing" @click="search()">查询</button>
              <button class="button_clear button_spacing" @click="$parent.$parent.clearmsg">清空</button>
              <export-excel :data="$parent.$parent.getCondition" class="button_export button_spacing"
                            :field="$parent.$parent.getfield"  :sumname="$parent.$parent.sumName"
                            sqlurl="rs/logic/exportfile" sql-name="webmeter_getNewLoseQuery" template-name='失联分析'
                            :choose-col="true"></export-excel>
<!--              <button class="button_export button_spacing" @click="$parent.$parent.SaveAsFile('lostuserlist')">导出</button>-->
              <button class="button_export button_spacing" style="width: max-content" @click="$parent.$parent.showTotalForm()">显示汇总</button>
<!--              <button class="button_search button_spacing" @click="$parent.$parent.showEcharts()">显示图表</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">
              <label class="font_normal_body">客户地址</label>
              <input @keyup.enter="search"   style="width:60%" type="text" class="input_search" v-model="model.f_area" placeholder='地址'
                      condition="a.f_address like '%{}%'" v-el:xq v-next-el='address' v-el:area
              >
            </div>
            <div class="col-sm-2">
              <label class="font_normal_body">客户类型</label>
              <v-select style="width:60%" 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">
              <label class="font_normal_body">用气性质</label>
              <v-select style="width:60%" 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">-->
                <!--<label class="font_normal_body">最新状态</label>-->
                <!-- <v-select style="width:60%" id="f_state"-->
                          <!--v-model="model.f_state"-->
                          <!--placeholder='最新状态'-->
                          <!--:value.sync="model.f_state"-->
                          <!--:options='$parent.$parent.getstate'-->
                          <!--condition="f_state = '{}'"-->
                          <!--close-on-select>-->
                <!--</v-select>-->
              <!--</div>-->
            <div class="col-sm-2">
                <label class="font_normal_body">上报区间</label>
                <datepicker  style="width:60%" 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">
                <label class="font_normal_body" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;</label>
                <datepicker  style="width:60%" 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 class="col-sm-2">
                <label class="font_normal_body">安装日期</label>
                <datepicker  style="width:60%" id="start" placeholder="开始时间"
                            v-model="model.startdate"
                            :value.sync="model.startdate"
                            :disabled-days-of-Week="[]"
                            :format="'yyyy-MM-dd HH:mm:ss'"
                            condition="u.f_gas_date >= '{}'"
                            :show-reset-button="reset">
                </datepicker>
              </div>
            <div class="col-sm-2">
                <label class="font_normal_body" style="word-break:keep-all;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;</label>
                <datepicker  style="width:60%" id="end" placeholder="结束日期"
                            v-model="model.enddate"
                            :value.sync="model.enddate"
                            :disabled-days-of-Week="[]"
                            :format="'yyyy-MM-dd HH:mm:ss'"
                            condition="u.f_gas_date <= '{}'"
                            :show-reset-button="reset">
                </datepicker>
              </div>
            <div class="col-sm-2">
                <label class="font_normal_body">最长失联</label>
                <input @keyup.enter="search"   style="width:60%" type="text" class="input_search" v-model="model.max_days1" placeholder='天数大于等于'
                       condition="max_days >= {}" v-next-el='max_days' v-el:max_days
                >
              </div>
            <div class="col-sm-2">
                <label class="font_normal_body" style="word-break:keep-all;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;</label>
                <input @keyup.enter="search"   style="width:60%" type="text" class="input_search" v-model="model.max_days2" placeholder='天数小于等于'
                       condition="max_days <= {}" v-next-el='max_days' v-el:max_days
                >
              </div>
            <div class="col-sm-2">
                <label class="font_normal_body">合计失联</label>
                <input @keyup.enter="search"   style="width:60%" type="text" class="input_search" v-model="model.all_days1" placeholder='天数大于等于'
                       condition="all_days >= {}" v-next-el='all_days' v-el:all_days
                >
              </div>
            <div class="col-sm-2">
                <label class="font_normal_body" style="word-break:keep-all;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;</label>
                <input @keyup.enter="search"   style="width:60%" type="text" class="input_search" v-model="model.all_days2" placeholder='天数小于等于'
                       condition="all_days <= {}" v-next-el='all_days' v-el:all_days
                >
              </div>
              <!--<div class="col-sm-2">-->
                <!--<label class="font_normal_body">最新失联</label>-->
                <!--<input @keyup.enter="search"   style="width:60%" type="text" class="input_search" v-model="model.new_days1" placeholder='天数大于等于'-->
                       <!--condition="new_days >= {}" v-next-el='new_days' v-el:new_days-->
                <!--&gt;-->
              <!--</div>-->
              <!--<div class="col-sm-2">-->
                <!--<label class="font_normal_body" style="word-break:keep-all;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;</label>-->
                <!--<input @keyup.enter="search"   style="width:60%" type="text" class="input_search" v-model="model.new_days2" placeholder='天数小于等于'-->
                       <!--condition="new_days <= {}" v-next-el='new_days' v-el:new_days-->
                <!--&gt;-->
              <!--</div>-->

          </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>
      </criteria>
      <data-grid id="lostuserlist" :model="model" partial='list' v-ref:grid class="list_area table_sy">
        <template partial='head'>
          <tr>
            <th style="text-align:center">
              <nobr>序号</nobr>
            </th>
            <th style="text-align:center">
              <nobr>组织机构</nobr>
            </th>
            <!--<th rowspan="2" 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" title="指查询时间区间内，连续失联最长的天数">
              <nobr>最长失联天数</nobr>
            </th>
            <th style="text-align:center" title="指查询时间区间内，共计失联的总天数">
              <nobr>合计失联天数</nobr>
            </th>
            <th style="text-align:center">
              <nobr>最长失联类型</nobr>
            </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">
              <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'>
          <td style="text-align:center">{{$index+1}}</td>
          <!--<td style="text-align:center">{{row.f_userfiles_id}}</td>-->
          <td style="text-align:center"><nobr>{{row.f_orgname}}</nobr></td>
          <td style="text-align:center"><nobr>{{row.f_meternumber}}</nobr></td>
          <td style="text-align:center">{{row.f_userinfo_code}}</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">{{row.f_user_type}}</td>
          <td style="text-align:center">{{row.f_gasproperties}}</td>
          <td style="text-align:center">{{row.max_days}}</td>
          <td style="text-align:center">{{row.all_days}}</td>
          <td style="text-align:center">
            <nobr>{{row.max_days_type}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.all_days_type}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.min_insert_date}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.max_insert_date}}</nobr>
          </td>
          <td style="text-align:center">{{row.c}}</td>
          <!--<td style="text-align:center">{{row.new_days}}</td>-->
          <!--<td style="text-align:center">{{row.f_state}}</td>-->

        </template>
      </data-grid>
    </criteria-paged>
  </div>
  <div v-show="echarts" style="height: 40px;width: 100%;">
    <div style="display: inline-block;">
      <button class="button_search button_spacing" @click="notShowEcharts()">隐藏图表</button>
    </div>
    <div class="mystyle" style="display: inline-block;">
      <label class="font_normal_body">图表统计项</label>
       <v-select style="width:60%" id="Groupname" v-model="groupname"
                placeholder='分组项'
                value-single="true"
                :value.sync="groupname"
                :options='getgroupname'
                close-on-select></v-select>
    </div>
  </div>
  <div class="span" v-show="echarts" style="width: 100%;height: 90%;">
    <lost-contact-echarts :groupname="groupname[0]" :condition="condition" :startdate="startDate"
                          :enddate="endDate" :echarts="echarts"></lost-contact-echarts>
  </div>
<!--  <div v-show="isActiveTotalForm" style="height: 40px;width: 100%;">-->
<!--    <button class="button_search button_spacing" @click="notShowTotalForm()">隐藏汇总</button>-->
<!--  </div>-->
  <div class="span" v-show="isActiveTotalForm" style="width: 100%;height: 90%;">
    <lost-contact-eform :condition="condition" :startdate="startDate"
                        :enddate="endDate"></lost-contact-eform>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'
  import UserGasEcharts from './UserGasEcharts'
  import * as Util from '../../../Util'
  import getLodop from '../../../plugins/LodopFuncs'
  import plugins from '../../../plugins/GetLoginInfoService'
  export default {
    title: '失联分析',
    props: ['data'],
    components: {UserGasEcharts},
    data() {
      return {
        model: new PagedList('rs/sql/webmeter_getNewLoseQuery', 20, {
          startDate: 'this.model.startDate',
          endDate: 'this.model.endDate'
        }),
        getfield:{"f_orgname":"组织机构","f_meternumber":"表钢号",
          "f_userinfo_code":"客户编号","f_user_name":"客户名称",
          "f_address":"客户地址",
          "f_gas_date":"安装日期","f_user_type":"客户类型",
          "f_gasproperties":"用气性质","max_days":"最长失联天数",
          "all_days":"合计失联天数",
          "max_days_type":"最长失联类型","all_days_type":"合计失联类型",
          "min_insert_date":"期初上报日期","max_insert_date":"期末上报日期",
          "c":"期间上报次数"},
        reportStr: null,
        show: false,
        startDate: '',
        endDate: '',
        criteriaShow:false,
        outlets: [],
        operator: [],
        filename: '',
        orgCondtionStr: '(' + this.$login.f.orgid + ')',
        echarts: false,
        orgid:[this.$login.f.orgid],
        searchshow: false,
        isActiveTotalForm: false,
        condition: '1=1',
        groupname: ['max_days_type'],
        getgroupname: [
          {label: '客户类型', value: 'f_user_type'},
          {label: '用气性质', value: 'f_gasproperties'},
          {label: '分公司', value: 'f_orgname'},
          {label: '最长失联天数', value: 'max_days_type'},
          {label: '合计失联天数', value: 'all_days_type'}
        ],
        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_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.$refs.paged.$refs.cri.search()
    },
    methods: {
      hidden(){
        this.criteriaShow = !this.criteriaShow
      },
      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
        if (this.endDate == '' || this.startDate == '') {
          return this.$showMessage("时间区间的开始和结束时间不能为空！")
        }
        if (this.orgCondtionStr){
          this.condition = this.$refs.paged.$refs.cri.condition + `and u.f_orgid in ${this.orgCondtionStr}`
        }
        else
          this.condition = this.$refs.paged.$refs.cri.condition
        args.condition = this.condition
        this.model.search(args.condition, args.model)
      },
      getRes(obj) {
        this.orgCondtionStr = plugins.convertToIn(obj)
      },
      // 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("客户类型")
      // },
      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('用户类型')]
      },
      Gasproperties() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
      },
      f_outlets() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('网点查询用')]
      },
      valveStatus() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')]
      },
      getstate() {
        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>
