<template>
  <div id='app' 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">
              <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="p.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="u.f_userinfo_code like '%{}%'" 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.f_username" placeholder='客户名称'
                       condition="u.f_user_name 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.f_address" 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="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="f_gasproperties = '{}'"
                          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.start_f_parameter_date"
                            :value.sync="model.start_f_parameter_date"
                            :disabled-days-of-Week="[]"
                            condition="f.f_install_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.end_f_parameter_date"
                            :value.sync="model.end_f_parameter_date"
                            :disabled-days-of-Week="[]"
                            :format="'yyyy-MM-dd HH:mm:ss'"
                            condition="f.f_install_date <='{}'"
                            :show-reset-button="reset">
                </datepicker>
              </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>
          </tr>


        </template>
        <template partial='body'>
          <td style="text-align:center"><nobr>{{$index+1}}</nobr></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"><nobr>{{row.f_userinfo_code}}</nobr></td>
          <td style="text-align:center"><nobr>{{row.f_user_name}}</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><nobr>{{row.f_address}}</nobr></td>
          <td style="text-align:center"><nobr>{{row.f_install_date}}</nobr></td>
          <td style="text-align:center"><nobr>{{row.type1}}</nobr></td>
          <td style="text-align:center"><nobr>{{row.type2}}</nobr></td>
          <td style="text-align:center"><nobr>{{row.mindate}}</nobr></td>
          <td style="text-align:center"><nobr>{{row.maxdate}}</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">-->
<!--  &lt;!&ndash;    <div style="display: inline-block;">&ndash;&gt;-->
<!--  &lt;!&ndash;      <button class="button_search button_spacing" @click="notShowEform()">隐藏汇总</button>&ndash;&gt;-->
<!--  &lt;!&ndash;    </div>&ndash;&gt;-->
<!--  &lt;!&ndash;      汇总显示模板&ndash;&gt;-->
<!--  <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'
  export default {
    title: '标记分析',
    props: ['data'],
    components: {signAnalysisEcharts},
    data() {
      return {
        model: new PagedList('rs/sql/selectSignAnalysisList', 20),
        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: [],
        operator: [],
        filename: '',
        echarts: false,
        searchshow: false,
        startDate: '',
        endDate: '',
        isActiveTotalForm: false,
        condition: '1=1',

        signtype:['type1'],
        getfield:{"f_orgname":"组织机构","f_meternumber":"表钢号",
          "f_userinfo_code":"客户编号",
          "f_user_name":"客户名称","f_user_type":"客户类型",
          "f_gasproperties":"用气性质",
          "f_address":"地址","f_install_date":"安装时间",
          "type1":"待处理数量",
          "type2":"已处理数量",
          "mindate":"最早上报时间",
          "maxdate":"最晚上报时间"
        },
        getSignType:[
          {label: '频繁磁干扰', value: 'type1'},
          {label: '间断性失联', value: 'type2'},
          {label: '间断性指令失败', value: 'type3'},
          {label: '锂电低电故障', value: 'type4'},
          {label: '频繁报拆表', value: 'type5'},
          {label: '未装电池', value: 'type6'},
          {label: '拆电池了', value: 'type7'},
          {label: '电池低压', value: 'type8'},
          {label: '锂电低电', value: 'type9'},
          {label: '连续失联', value: 'type10'},
          {label: '频繁报过流保护关阀', value: 'type11'},
          {label: '负值故障', value: 'type12'},
          {label: '其他', value: 'type13'}
        ],
        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.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: {
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      // 查询开关
      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.start_f_parameter_date
        this.endDate = this.$refs.paged.$refs.cri.model.end_f_parameter_date
          this.condition = this.$refs.paged.$refs.cri.condition
        console.log("~~~~~~~~~~~~~~~~~~")
        console.log(this.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}`
        }

      },
      usertypes() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      valveStatus() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')]
      },
      // Gasproperties() {
      //   return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
      // },
      Gasproperties () {
        let rs=[]
        if (this.$refs.paged.$refs.cri.model.f_user_type.length===1){
          rs=this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_user_type[0])
        }
        return[{lable:'全部',value:''}, ...rs]
      },
      Getuserstyle() {
        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>
