<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" partial>
          <div class="row">
            <div class="col-sm-2 form-group">
              <label style="width:35%" class="font_normal_body">&nbsp;&nbsp;&nbsp;表号&nbsp;&nbsp;&nbsp;</label>
              <input style="width:60%" type="text" class="input_search"
                     v-model="model.f_meternumber" placeholder='表号'
                     @keyup.enter="search"
                     condition="f_meternumber like '%{}%'"
                     v-next-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_userid = '{}'" v-next-el='f_userinfo_code' v-el:meternumber
              >
            </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.username" placeholder='客户名称'
                     condition="username like '%{}%'" v-next-el='userid' v-el:username>
            </div>
            <div class="span" 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"
                            sqlurl="rs/logic/exportfile" sql-name="selectSignAnalysisList" template-name='标记分析'
                            :choose-col="true"></export-excel>
              <!--                  <button class="button_search button_spacing" @click="$parent.$parent.showEcharts()">显示图表</button>-->
              <button class="button_export button_spacing" style="width: max-content" @click="$parent.$parent.showEform()">显示汇总</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.address" placeholder='地址'
                     condition="address like '%{}%'" v-el:xq v-next-el='address' v-el:area
              >
            </div>
            <div class="col-sm-2 form-group">
              <label style="width:35%" class="font_normal_body">余额&nbsp;&nbsp;大于</label>
            <input style="width:60%" type="number" class="input_search"
                   v-model="model.f_balance_amount_sta" placeholder='账户余额'
                   condition="f_balance_amount>{}"
                   @keyup.enter="search"
                   v-el:xq v-next-el='f_day' v-el:area
            >
          </div>
          <div class="col-sm-2 form-group">
            <label style="width:35%" class="font_normal_body">小于</label>
            <input style="width:60%" type="number" class="input_search"
                   v-model="model.f_balance_amount_end"placeholder='账户余额'
                   condition="f_balance_amount < {}"
                   @keyup.enter="search"
                   v-el:xq v-next-el='f_day' v-el:area
            >
          </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="[]"
                          condition="f_hand_date >= '{}'"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          :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="endDate" placeholder="结束日期"
                          v-model="model.endDate"
                          :value.sync="model.endDate"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd HH:mm:ss'"
                          condition="f_hand_date <= '{}'"
                          :show-reset-button="reset">
              </datepicker>
            </div>
            <div class="col-sm-2 form-group">
              <label style="width:35%" class="font_normal_body">气表品牌</label>
              <v-select :value.sync="model.f_balance_amount"
                        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 style="width:35%" class="font_normal_body">未抄表天数&nbsp;></label>
              <input style="width:60%" type="number" class="input_search"
                     v-model="model.f_day" placeholder='未抄表天数'
                     condition="DateDiff(dd,f_hand_date,getdate())>{}"
                     @keyup.enter="search"
                     v-el:xq v-next-el='f_day' v-el:area
              >
            </div>
            <div class="col-sm-2 form-group">
              <label style="width:35%" class="font_normal_body">电池电量&nbsp;&nbsp;大于</label>
              <input style="width:60%" type="number" class="input_search"
                     v-model="model.f_batterylevel_sta" placeholder='电池电量'
                     condition="f_electricity>{}"
                     @keyup.enter="search"
                     v-el:xq v-next-el='f_day' v-el:area
              >
            </div>
            <div class="col-sm-2 form-group">
              <label style="width:35%" class="font_normal_body">小于</label>
              <input style="width:60%" type="number" class="input_search"
                     v-model="model.f_batterylevel_end" placeholder='电池电量'
                     condition="f_electricity < {}"
                     @keyup.enter="search"
                     v-el:xq v-next-el='f_day' v-el:area
              >
            </div>
          </div>

        </div>
      </criteria>

      <data-grid id="usergasall" :model="model" partial='list' class="list_area table_sy"  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>
            <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>
            <!--<span @click="$parent.$parent.$parent.showmsg(row)"><a>{{row.f_userid}}</a></span>-->
            <!--<span @click="$parent.$parent.$parent.dealmsg(row)"><a>{{row.f_userid}}</a></span>-->
            {{row.f_userid}}
          </nobr> </td>
          <td style="text-align:center"><nobr>{{row.f_username}}</nobr></td>
          <td style="text-align:center"><nobr>{{row.f_districtname}}</nobr></td>
          <td>
            <nobr>{{row.f_address}}</nobr>
          </td>
          <td style="text-align:center">{{row.f_balance_amount}}</td>
          <td style="text-align:center">{{row.f_phone}}</td>
          <td style="text-align:center"><nobr>{{row.f_meternumber}}</nobr></td>
          <td style="text-align:center">
            <nobr>{{row.f_gaswatchbrand}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_hand_date}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.lastinputdate}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_electricity}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_signal}}</nobr>
          </td>

          <td style="text-align:center">
            <nobr>{{row.f_magneticinterference}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_valvestate}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_snr}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_userstate}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_upload_type}}</nobr>
          </td>
          <td style="text-align:center">
            <nobr>{{row.f_filiale}}</nobr>
          </td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
  <div style="height: 40px;width: 100%;" v-show="echarts">
    <div style="display: inline-block;">
      <button class="button_search button_spacing" @click="notShowEcharts()">隐藏图表</button>
    </div>
    <!--      图显示模板-->

  </div>
  <div style="width: 100%;height: 90%;" v-show="echarts">
    <sign-analysis-echarts  :condition="condition" :startdate="startDate"
                            :enddate="endDate" :echarts="echarts"></sign-analysis-echarts>
  </div>
    <!--<div style="height: 40px;width: 100%;" v-show="isActiveTotalForm">-->
        <!--<div style="display: inline-block;">-->
          <!--<button class="button_search button_spacing" @click="notShowEform()">隐藏汇总</button>-->
        <!--</div>-->
          <!--汇总显示模板-->
    <!--<div class="mystyle row" style="display: inline-block;">-->
      <!--<label class="font_normal_body">汇总统计项</label>-->
      <!--<v-select style="width:60%" id="signtype" v-model="signtype"-->
                <!--placeholder='分组项'-->
                <!--value-single="true"-->
                <!--:value.sync="signtype"-->
                <!--:options='getSignType'-->
                <!--close-on-select></v-select>-->
    <!--</div>-->
  <!--</div>-->
  <div style="width: 100%;height: 90%;" v-show="isActiveTotalForm">
    <sign-analysis-eform :signtype="signtype[0]" :condition="condition"></sign-analysis-eform>
  </div>
</template>

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

  let readySomething = async function (self) {
   await self.$MagLoadParams.loadParam()
   self.initParams()
  }
  export default {
    title: '标记分析',
    props: ['data'],
    components: {signAnalysisEcharts},
    data() {
      return {
        model: new PagedList('rs/sql/getExceptionList', 20, {
          startDate: 'this.model.startDate',
          endDate: 'this.model.endDate'
        }),
        groupNameByDate: [],
        getGroupNameByDate: [
          {label: '年份', value: 'year'},
          {label: '月份', value: 'month'},
          {label: '周', value: 'week'}
        ],
        orgid:[this.$login.f.orgid],
        criteriaShow:false,
        orgCondtionStr: '(' + this.$login.f.orgid + ')',
        reportStr: null,
        show: false,
        outlets: [],
        f_meter_brand:'',
        operator: [],
        filename: '',
        echarts: false,
        searchshow: false,
        startDate: '',
        endDate: '',
        isActiveTotalForm: false,
        reportStr: null,
        show: false,
        startDate: '',
        endDate: '',
        // meterbrands: [],
        f_filiale:[],
        orgid:[this.$login.f.orgid],
        orgCondtionStr: '(' + this.$login.f.orgid + ')',
        f_error_type:'',
        groupname: ['year'],
        getgroupname: [
          {label: '年份', value: 'year'},
          {label: '月份', value: 'month'},
          {label: '周', value: 'week'},
          {label: '日', value: 'day'}
        ],
        showdetail:false,
        rowdata: {},
        GetErrorLevel: [],
        GetErrorType: [],
        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
        },
        condition: '1=1',
        signtype:['type1'],
        getfield:{
          "f_userid" :"客户编号",
          "username":"客户名称",
          "f_residential_area"  :"小区",
          "address":"客户地址",
          "f_balance_amount"  :"账户余额",
          "f_user_phone":"联系电话",
          "f_meternumber" :"表号",
          "f_gaswatchbrand" :"气表品牌",
          "f_hand_date" :"抄表日期",
          "f_insert_date":"最后一次通讯时间",
          "f_electricity":"电池电量",
          "f_signal":"信号强度",
          "f_magneticInterference":"磁干扰异常",
          "f_valveState":"阀门状态",
          "f_usestate":"用户状态",
          "f_snr":"信噪比",
          "f_upload_type":"上报类型",
          "f_filiale":"分公司"
        },
        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() {
       readySomething(this)
         this.$refs.paged.$refs.cri.model.startDate = Util.toStandardDateString() + ' 00:00:00.000'
          this.$refs.paged.$refs.cri.model.endDate = Util.toStandardDateString() + ' 23:59:59.000'
         console.log("type:"+this.$refs.paged.$refs.cri.model.f_error_type)
           // this.getErrorInfo('f_error_level')
          console.log("type:"+this.$refs.paged.$refs.cri.model.f_error_type)
          this.$refs.paged.$refs.cri.search()
    },
    // ready() {
    //   this.$refs.paged.$refs.cri.model.start_f_parameter_date = Util.toStandardDateString() + ' 00:00:00'
    //   this.$refs.paged.$refs.cri.model.end_f_parameter_date = Util.toStandardDateString() + ' 23:59:59'
    //   this.$refs.paged.$refs.cri.search()
    // },
    methods: {
      showmsg(obj){
        this.rowdata=obj
        this.showdetail=true
      },
      cancel() {
        this.showdetail = false
      },
      dealmsg(val) {
        val.model = this.model.model
        this.$emit('deal-msg', val)
      },
      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)
          }
        })
        console.log("====================================",arr);
        // this.meterbrands = [{label: '全部', value: ''}, ...arr]
      },

      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      clickshow() {
        this.searchshow = !this.searchshow
      },
      clickshow() {
        this.searchshow = !this.searchshow
      },
      // getErrorInfo(items){
      //   let self = this
      //   let f_error_level=''
      //   if (items!='f_error_level') {
      //     if(this.$refs.paged.$refs.cri.model.f_error_level){
      //       f_error_level=this.$refs.paged.$refs.cri.model.f_error_level[0]
      //     }
      //   }
      //   let load = new HttpResetClass()
      //   load.load('POST', 'rs/sql/singleTableParam', {
      //     data: {
      //       items:items+' f_type',
      //       tablename:'t_exception',
      //       condition:items=='f_error_level'?'1=1 group by '+items:`f_error_level='${f_error_level}' group by `+items
      //     }
      //   },{warnMsg:null,resolveMsg:null}).then((res) => {
      //     let i = 0
      //     let rows=res.data
      //     let array1=[]
      //     array1.push({label: '全部', value: ''})
      //     console.log("rows========",rows)
      //     for (i = 0; i < rows.length; i++) {
      //       let dr = {label: '全部', value: ''}
      //       dr.label=rows[i].f_type
      //       dr.value=rows[i].f_type
      //       array1.push(dr)
      //       console.log("rows[i]========",rows[i],dr)
      //     }
      //     console.log("array1========",array1)
      //     if (items=='f_error_level'){
      //       self.GetErrorLevel=array1
      //     }else {
      //       self.GetErrorType=array1
      //     }
      //   })
      // },
      search(args) {
        this.startDate = this.$refs.paged.$refs.cri.model.startDate
        this.endDate = this.$refs.paged.$refs.cri.model.endDate
        this.f_error_type=this.$refs.paged.$refs.cri.model.f_error_type
        console.log('1231321312312321')
        /* if (this.endDate == '' || this.startDate == '') {
        return this.$showMessage("时间区间的开始和结束时间不能为空！")
        }*/
        this.condition = this.$refs.paged.$refs.cri.condition

        args.condition = this.condition
        this.model.search(args.condition, args.model)
      },
      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')
          }
        })
      },
      // 查询开关
      seachchange() {
        this.searchshow = !this.searchshow
      },
      // 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
        this.f_error_type=this.$refs.paged.$refs.cri.model.f_error_type
        console.log('1231321312312321')
        /* if (this.endDate == '' || this.startDate == '') {
        return this.$showMessage("时间区间的开始和结束时间不能为空！")
        }*/
        this.condition = this.$refs.paged.$refs.cri.condition
        args.condition = this.condition
        this.model.search(args.condition, args.model)
      },
      // 显示柱状图
      showEcharts() {
        this.echarts = true
        this.isActiveTotalForm=false
      },
      // 不显示柱状图
      notShowEcharts() {
        this.echarts = false
        this.isActiveTotalForm=false
      },
      // 显示汇总
      showEform() {
        this.echarts = false
        this.isActiveTotalForm=true
      },
      // 不显示汇总
      notShowEform() {
        this.echarts = false
        this.isActiveTotalForm=false
      },
      close() {
        this.show = false
      },
      getRes(obj) {
        this.orgCondtionStr = plugins.convertToIn(obj)
      }
    },
    watch: {
      'data'(val) {
        if (val.f_files_path) {
          this.getFileContent(val.f_files_path)
        } else {
          this.reportStr = null
        }
      }
    },
    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}`
      //   }
      //
      // },
      getCondition() {
        let condition = this.$refs.paged.$refs.cri.condition
        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('用户类型')]
      },
      meterbrands() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表品牌')]
      },
      valveStatus() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')]
      },
    }
  }
</script>
<style>
  .mystyle {
    float: right;
    padding-right: 10%;
  }

  .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>
