<template>
  <div class="flex-row" v-if="!showdetail">
    <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 form-group">
                <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 form-group">
                <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 class="col-sm-2 form-group">
                <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="f_address like '%{}%'" v-el:xq v-next-el='address' v-el:area
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">&nbsp;&nbsp;&nbsp;表号&nbsp;&nbsp;&nbsp;</label>
                <input @keyup.enter="search" style="width:60%" type="text" class="input_search"
                       v-model="model.f_meternumber" placeholder='表号'
                       condition="f_meternumber like '%{}%'" v-next-el='meternumber' v-el:meternumber
                >
              </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_getAllLoseQuery" 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 form-group">
              <label class="font_normal_body">&nbsp;&nbsp;&nbsp;公司&nbsp;&nbsp;&nbsp;</label>
              <right-tree @re-res="$parent.$parent.getorg" width="60%"
                          :initresid='$parent.$parent.org'></right-tree>
            </div>
            <div class="col-sm-2 form-group">
              <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="f_user_type = '{}'"
                        close-on-select>
              </v-select>
            </div>
            <div class="col-sm-2 form-group">
              <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="f_gasproperties = '{}'"
                        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_meter_brand"
                        v-model="model.f_meter_brand"
                        :options='$parent.$parent.meterbrands' placeholder='请选择'
                        condition="f_meter_brand = '{}'"
                        close-on-select></v-select>
            </div>
            <!--<div class="col-sm-2 form-group">-->
            <!--<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 form-group">
              <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 form-group">
              <label class="font_normal_body">结束时间</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 form-group  flex-row" style="white-space: nowrap">
              <label class="font_normal_body">最长失联</label>
              <div class="row">
                <input type="text" style="width:27%" class="input_search" v-model="model.max_interval_day1"
                       condition="max_interval_day >= {} " placeholder="">
                <label class="font_normal_body"> &nbsp;≤ x ≤ </label>
                <input type="text" style="width:27%" class="input_search" v-model="model.max_interval_day2"
                       condition="max_interval_day <= {} " placeholder="">
              </div>
            </div>


            <div class="col-sm-2 form-group  flex-row" style="white-space: nowrap">
              <label class="font_normal_body">合计失联</label>
              <div class="row">
                <input type="text" style="width:27%" class="input_search" v-model="model.SLdays1"
                       condition="SLdays >= {} " placeholder="">
                <label class="font_normal_body">&nbsp; ≤ x ≤ </label>
                <input type="text" style="width:27%" class="input_search" v-model="model.SLdays2"
                       condition="SLdays <= {} " placeholder="">
              </div>
            </div>

            <!--<div class="col-sm-2 form-group">-->
            <!--<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 form-group">-->
            <!--<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 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">{{$index+1}}</td>
          <!--<td style="text-align:center">{{row.f_userfiles_id}}</td>-->
          <td style="text-align: center;"><nobr>
            <span @click="$parent.$parent.$parent.showmsg(row)"><a>{{row.f_userinfo_code}}</a></span>
          </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">{{row.f_user_type}}</td>
          <td style="text-align:center">{{row.f_gasproperties}}</td>
          <td style="text-align:center"><nobr>{{row.f_meternumber}}</nobr></td>
          <td style="text-align:center"><nobr>{{row.f_startuse_date}}</nobr></td>

          <td style="text-align:center">{{row.ybdays}}</td>
          <td style="text-align:center">{{row.sbdays}}</td>
          <td style="text-align:center">
            <nobr>{{row.max_interval_day}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.sldays}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_meter_brand}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_orgname}}</nobr>
          </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>
  </div>
  <div  class="basic-main" v-if="showdetail">
    <user-info-detail-manage :f_userinfo_id="rowdata.f_userinfo_id" @cancel-main="cancel"></user-info-detail-manage>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'
  import UserGasEcharts from './UserGasEcharts'
  import * as Util from '../../../Util'
  import plugin from 'system-clients/src/plugins/GetLoginInfoService'

  let readySomething = async function (self) {

    await self.$MagLoadParams.loadParam()
    self.initParams()
    let year = new Date().getFullYear()
    self.$refs.paged.$refs.cri.model.startDate =  year+'-01-01 00:00:00'
    // self.$refs.paged.$refs.cri.model.startDate = Util.toStandardDateString() + ' 00:00:00'
    self.$refs.paged.$refs.cri.model.endDate = Util.toStandardDateString() + ' 23:59:59'
    self.$refs.paged.$refs.cri.search()
  }
  export default {
    title: '失联分析',
    props: ['data'],
    components: {UserGasEcharts},
    data() {
      return {
        model: new PagedList('rs/sql/webmeter_getAllLoseQuery', 20, {
          startDate: 'this.model.startDate',
          endDate: 'this.model.endDate'
        }),
        getfield:{
          "f_userinfo_code":"客户编号","f_user_name":"客户名称",
          "f_address":"客户地址","f_user_type":"客户类型","f_gasproperties":"用气性质",
          "f_meternumber":"表号",

          "f_startuse_date":"启用日期",
          "ybdays":"应报天数",
          "sbdays":"实报天数",
          "max_interval_day":"最长失联天数","sldays":"累计失联天数",
          "f_meter_brand":"气表厂家","f_orgname":"组织机构"},
        reportStr: null,
        show: false,
        showdetail:false,
        rowdata:{},
        startDate: '',
        endDate: '',
        criteriaShow:false,
        outlets: [],
        operator: [],
        meterbrands:[],
        filename: '',
        orgCondtionStr: ` and f_orgid = ${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_orgid'},
          {label: '最长失联天数', value: 'max_days_type'},
          {label: '合计失联天数', value: 'all_days_type'}
        ],
        org:[this.$login.f.orgid]

      }
    },
    ready() {
      readySomething(this)
    },
    methods: {
      hidden(){
        this.criteriaShow = !this.criteriaShow
      },
      clickshow() {
        this.searchshow = !this.searchshow
      },
      showmsg(obj){
        this.rowdata=obj
        this.showdetail=true
      },
      cancel() {
        this.showdetail = false
      },
      initParams () {
        let arr = []
        this.$MagGetSaleParam.getGasbrand().forEach((item) => {
          let temp = {}
          if(item.value.f_meter_type==='物联网表'){
            temp.label = item.label
            temp.value = item.value.f_meter_brand
            arr.push(temp )
          }

        })
        this.meterbrands = [{label: '全部', value: ''}, ...arr]
      },
      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("时间区间的开始和结束时间不能为空！")
        }
        args.condition = this.$refs.paged.$refs.cri.condition + `${this.orgCondtionStr}`
        this.model.search(args.condition, args.model)
      },
      getorg(obj) {
        if (obj.resids.length>0) {
          this.orgCondtionStr = " and f_orgid in " + plugin.convertToIn(obj.resids)
        }else
        {
          this.orgCondtionStr = " and f_orgid = " + this.$login.f.orgid
        }
      },
      // 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() {
        let condition=this.$refs.paged.$refs.cri.condition + this.orgCondtionStr
        return {
            condition: condition  ,
            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>
