<template >
  <div id="stand-work-list" class="flex bg-white p-10 datapanel">
    <div class="span">
      <criteria-paged :model="model" v-ref:paged >
        <criteria partial='criteria' v-ref:criteria  @condition-changed='$parent.search'>
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="row" width="100%">
              <div class="col-sm-2 form-group form-input-group" >
                <label class="control-label">表&nbsp;钢&nbsp;号&nbsp;</label>
                <input type="text" class="form-control"
                       placeholder='表钢号'
                       v-model="model.f_meternumber"
                       condition="f_meternumber like '%{}%'"
                >
              </div>

                <div class="col-sm-2 form-group form-input-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 form-input-group">
                  <label class="control-label">用户姓名</label>
                  <input type="text" class="form-control" v-model="model.f_user_name"
                         placeholder='用户姓名'
                         condition="f_user_name like '%{}%'">
                </div>
                <div class="col-sm-2 form-group form-input-group">
                  <label class="control-label">用气地址</label>
                  <input type="text" class="form-control" v-model="model.f_address"
                         placeholder='用气地址'
                         condition="f_address like '%{}%'"
                  >
                </div>
                <div class="col-sm-2 form-group form-input-group" >
                  <label class="control-label">用户类型</label>
                  <v-select placeholder='用户类型' close-on-select
                            v-model="model.f_user_type"
                            :value.sync="model.f_user_type"
                            :options="$parent.$parent.Getusertype"
                            condition="f_user_type = '{}'"
                  >
                  </v-select>
                </div>
                <div class="col-sm-2 form-group form-input-group" >
                  <label class="control-label">用气性质</label>
                  <v-select placeholder='用气性质' close-on-select
                            v-model="model.f_gasproperties"
                            :value.sync="model.f_gasproperties"
                            :options="$parent.$parent.Gasproperties"
                            condition="f_gasproperties = '{}'">
                  </v-select>
                </div>

                <div class="col-sm-2 form-group form-input-group" >
                  <label class="control-label" style="word-break:keep-all;">上报时间</label>
                  <datepicker placeholder="起始时间"
                              :value.sync="model.startDate"
                              v-model="model.startDate"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              condition="f_insert_date >= '{}'"
                  ></datepicker>
                </div>
                <div class="col-sm-2 form-group form-input-group" >
                  <label class="control-label" style="word-break:keep-all;">&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;</label>
                  <datepicker placeholder="结束时间"
                              :value.sync="model.endDate"
                              v-model="model.endDate"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              condition="f_insert_date <= '{}'"
                  ></datepicker>
                </div>
                <div class="col-sm-2 form-group form-input-group" >
                  <label class="control-label" style="word-break:keep-all;">安装时间</label>
                  <datepicker placeholder="起始时间"
                              :value.sync="model.startDate1"
                              v-model="model.startDate1"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              condition="f_input_date >= '{}'"
                  ></datepicker>
                </div>
                <div class="col-sm-2 form-group form-input-group" >
                  <label class="control-label" style="word-break:keep-all;">&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;</label>
                  <datepicker placeholder="结束时间"
                              :value.sync="model.endDate1"
                              v-model="model.endDate1"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              condition="f_input_date >= '{}'"
                  ></datepicker>
                </div>
                <div class="col-sm-2 form-group form-input-group">
                  <label class="control-label">故障状态</label>
                  <v-select placeholder='故障状态'
                            v-model="model.faultstate"
                            multiple
                            :value.sync="model.faultstate"
                            :options="$parent.$parent.FaultStates">
                  </v-select>
                </div>

                <div class="col-sm-2 form-group form-input-group">
                  <label class="control-label">阀门状态</label>
                  <v-select placeholder='阀门状态'  close-on-select
                            v-model="model.f_valvestate"
                            :value.sync="model.f_valvestate"
                            condition="f_valvestate like '%{}%'"
                            :options="$parent.$parent.Valvestates">
                  </v-select>
                </div>
                <div class="col-sm-2 form-group form-input-group">
                  <label class="control-label">上报类型</label>
                  <v-select placeholder='上报类型' close-on-select
                            v-model="model.f_upload_type"
                            :value.sync="model.f_upload_type"
                            :options="$parent.$parent.Getuploadtype"
                            condition="f_upload_type = '{}'"
                  >
                  </v-select>
                </div>
                <div class="col-sm-2 form-group form-input-group">
                  <label class="control-label">用气量区间</label>
                  <input  type="text" class="form-control" v-model="model.start_gas" placeholder='最小气量'
                          condition="f_oughtamount >= '{}'" v-next-el='start_gas' v-el:start_gas>
                </div>
                <div class="col-sm-2 form-group form-input-group">
                  <label class="control-label" style="word-break:keep-all;">&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;</label>
                  <input type="text" class="form-control" v-model="model.end_gas" placeholder='最大气量'
                         condition="f_oughtamount <= '{}'" v-el:xq v-next-el='end_gas' v-el:end_gas
                  >
                </div>
            </div>

            <div class="row" style="float: right">
              <button class="btn btn-success width-100" @click="search()" v-el:cba>查询</button>
              <button class="btn btn-default width-100" @click="$parent.$parent.clearmsg">清空</button>
                <!--<button class="btn btn-success width-100" @click="$parent.$parent.SaveAsFile('webmeterhandplan')">导出</button>-->
            </div>
          </div>
        </criteria>
        <data-grid id="webmeterhandplan" :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>本次用气量(m³)</nobr></th>
              <th style="text-align:center"><nobr>气价(元/m³)</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' partial='list' v-ref:grid>
            <tr>
              <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_user_name}}</nobr></td>
              <td ><nobr>{{row.f_address}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_input_date}}</nobr></td>
              <td style="text-align:center">
                <nobr>
                  <span @click="$parent.$parent.$parent.dealmsg(row)"><a>
                    {{row.f_meternumber}}
                  </a></span>
                </nobr>
              </td>
              <td style="text-align:center"><nobr>{{row.f_meter_brand}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_meter_style}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_balance}}</nobr></td>
              <td style="text-align:center">{{row.f_last_tablebase}}</td>
              <td style="text-align:center">{{row.f_tablebase}}</td>
              <td style="text-align:center">{{row.f_oughtamount}}</td>
              <td style="text-align:center">{{row.f_price}}</td>
              <td style="text-align:center">{{row.f_oughtfee}}</td>
              <td style="text-align:center"><nobr>{{row.f_curbalance}}</nobr></td>
              <td style="text-align:center;width: 170px;"><nobr>{{row.f_upload_type}}</nobr></td>
              <td style="text-align:center;width: 170px;"><nobr>{{row.f_hand_date}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_last_hand_date}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_table_msg}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_last_meter_state_msg}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_insert_date}}</nobr></td>
              <td style="text-align:center"><nobr>{{row.f_software_version}}</nobr></td>

              <td style="text-align:center" >
                <img :title='row.f_signal' v-if="row.f_signal>-80"
                     src="../../../../static/WebMetericon/1.png"
                     height="12" width="24"/>
                <img :title='row.f_signal' v-if="row.f_signal>-100&&row.f_signal<=-80"
                     src="../../../../static/WebMetericon/2.png"
                     height="12" width="24"/>
                <img :title='row.f_signal' v-if="row.f_signal>-120&&row.f_signal<=-100"
                     src="../../../../static/WebMetericon/3.png"
                     height="12" width="24"/>
                <img :title='row.f_signal' v-if="row.f_signal<=-120"
                     src="../../../../static/WebMetericon/4.png"
                     height="12" width="24"/>
              </td>
              <td style="text-align:center" >
                <img :title='row.f_batterylevel' v-if="row.f_batterylevel>=6.00"
                     src="../../../../static/WebMetericon/01.png"
                     height="12" width="24"/>
                <img :title='row.f_batterylevel' v-if="row.f_batterylevel>=5.00&&row.f_batterylevel<6.00"
                     src="../../../../static/WebMetericon/02.png"
                     height="12" width="24"/>
                <img :title='row.f_batterylevel' v-if="row.f_batterylevel>=4.00&&row.f_batterylevel<5.00"
                     src="../../../../static/WebMetericon/03.png"
                     height="12" width="24"/>
                <img :title='row.f_batterylevel' v-if="row.f_batterylevel<4.00"
                     src="../../../../static/WebMetericon/04.png"
                     height="12" width="24"/>
              </td>
              <td style="text-align:center;width: 51px">{{row.f_valvestate==1?'关阀':'开阀'}}</td>
              <td style="text-align:center;width: 51px">
                <img :title='故障' v-if="row.f_magneticinterference==1"
                     src="../../../../static/WebMetericon/guzhang.png"
                     height="12" width="12"/>
                <img :title='正常' v-if="row.f_magneticinterference==0"
                     src="../../../../static/WebMetericon/zhengchang.png"
                     height="12" width="17"/>
              </td>
              <td style="text-align:center;width: 51px">
                <img :title='关阀' v-if="row.f_cycleshutvalue==1"
                     src="../../../../static/WebMetericon/guzhang.png"
                     height="12" width="12"/>
                <img :title='正常' v-if="row.f_cycleshutvalue==0"
                     src="../../../../static/WebMetericon/zhengchang.png"
                     height="12" width="17"/>
              </td>
              <td style="text-align:center;width: 51px">
                <img :title='关阀' v-if="row.f_overcurrentprotection==1"
                     src="../../../../static/WebMetericon/guzhang.png"
                     height="12" width="12"/>
                <img :title='正常' v-if="row.f_overcurrentprotection==0"
                     src="../../../../static/WebMetericon/zhengchang.png"
                     height="12" width="17"/>
              </td>
              <td style="text-align:center;width: 51px">
                <img :title='走气' v-if="row.f_leakageflag==1"
                     src="../../../../static/WebMetericon/guzhang.png"
                     height="12" width="12"/>
                <img :title='正常' v-if="row.f_leakageflag==0"
                     src="../../../../static/WebMetericon/zhengchang.png"
                     height="12" width="17"/>
              </td>
              <td style="text-align:center;width: 51px">
                <img :title='拆表' v-if="row.f_splitalarm==='1'"
                     src="../../../../static/WebMetericon/guzhang.png"
                     height="12" width="12"/>
                <img :title='正常' v-if="row.f_splitalarm==='0'"
                     src="../../../../static/WebMetericon/zhengchang.png"
                     height="12" width="17"/>
              </td>
              <td style="text-align:center;width: 51px">
                <img :title='停止' v-if="row.f_xtipllstopflag==='1'"
                     src="../../../../static/WebMetericon/guzhang.png"
                     height="12" width="12"/>
                <img :title='正常' v-if="row.f_xtipllstopflag==='0'"
                     src="../../../../static/WebMetericon/zhengchang.png"
                     height="12" width="17"/>
              </td>

            </tr>
          </template>
          <template partial='foot'></template>
        </data-grid>
      </criteria-paged>
    </div>
    <!--异常抄表录入-->
    <modal :show.sync="handshow" v-ref:modal backdrop="false">
      <header slot="modal-header" class="modal-header">
        <button type="button" class="close" @click="handchange()"><span>&times;</span></button>
        <h4 class="modal-title">表号{{handExce.exceobj.f_meternumber}}</h4>
      </header>
      <article slot="modal-body" class="modal-body">
        <div class="col-sm-12">
          <label class="control-label">上报异常类型</label>
          <textarea name="name" rows="2" style="width: 100%"
                    class="ver-textarea" class="form-control"
                    placeholder='上报异常类型'
                    v-model='handExce.f_error_type'></textarea>
        </div>
        <div class="col-sm-12 form-group form-fix-width">
          <label class="control-label">异常描述</label>
          <textarea name="name" rows="2" style="width: 100%"
                    placeholder='上报异常类型'
                    class="ver-textarea" class="form-control"
                    v-model='handExce.f_error_msg'></textarea>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button v-show="handshow" type="button" class="btn btn-default" @click='handchange()'>取消</button>
        <button v-show="handshow" type="button" class="btn btn-success" @click='saveException'>确认</button>
      </footer>
    </modal>
  </div>
</template>

<script>
  import {PagedList} from 'vue-client'

  export default {
    title: '数据采集',
    data() {
      return {
        model: new PagedList('rs/sql/dataCollectionQuery', 50),
        row: null,
        //搜索显示开关
        searchshow: false,
        //抄表录入开关
        handshow: false,
        isdeal:true,
        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,
        },
        handExce: {
          //异常对象
          exceobj:{},
          //异常类型
          f_error_type:"",
          //异常描述
          f_error_msg:'',
        },
        show: false,
      }
    },
    props: ['searchobj','isdeal'
    ],
    ready() {

    },
    methods: {
      //跳转处理页面
      dealmsg(val) {
        val.model=this.model.model
        this.$emit('deal-msg', val)
      },
      //查询开关
      seachchange() {
        this.searchshow= !this.searchshow
      },
      //异常开关
      handchange(val) {
        if(val){
          console.log("开启弹窗")
          this.handExce.exceobj=val
        }else{
          console.log("返回置空")
          this.handExce={}
        }
        this.handshow= !this.handshow
      },
      //保存输入
      saveException() {
        //准备数据
        var Exejson={

        }
        //抄表记录id
        Exejson.data_id=this.handExce.exceobj.id
        //异常表档案ID
        Exejson.f_user_id=this.handExce.exceobj.f_user_id
        //异常户档案ID
        Exejson.f_userinfo_id=this.handExce.exceobj.f_userinfo_id
        //异常表号
        Exejson.f_meternumber=this.handExce.exceobj.f_meternumber
        //分公司
        Exejson.f_filiale=this.handExce.exceobj.f_filiale
        //分公司编号
        Exejson.f_filialeids=this.handExce.exceobj.f_filialeids
        //营业网点
        Exejson.f_outlets=this.handExce.exceobj.f_outlets
        //组织机构
        Exejson.f_orgstr=this.handExce.exceobj.f_orgstr
        //异常类型
        Exejson.f_error_type=this.handExce.f_error_type
        //异常说明
        Exejson.f_error_msg=this.handExce.f_error_msg
        console.log("提交异常数据")
        console.log(Exejson)
        try {
          this.$resetpost('rs/entity/t_exception', Exejson, {resolveMsg: null, rejectMsg: null}).then((req) => {
            console.log(val)
            this.handExce={}
            console.log("提交成功")
          }).then(()=>{
            this.$showMessage("异常保存成功！")
          })
        } catch (e) {
          this.handExce={}
          console.log("提交失败")
          this.$showMessage("异常保存失败！")
        }
        this.handshow= false
      },
      DealSignal(val){
        console.log(val.model.f_signal)
        if(val.model&&val.model.f_signal) {
          if (val.model.f_signal == '信号正常') {
            val.condition = val.condition + " and " + "f_signal>-100 "
          }
          if (val.model.f_signal == '信号异常') {
            val.condition = val.condition + " and " + "f_signal<-100 "
          }
        }
        return val
      },
      DealFaults(val){
        if (val.model&&val.model.faultstate){
          console.log(val.model.faultstate)
          val.model.faultstate.forEach((item) =>{
            if (item=='磁干扰'){
              val.condition=val.condition+" and "+"f_magneticInterference=1 "
            }
            if (item=='周期关阀'){
              val.condition=val.condition+" and "+"f_cycleShutValue=1 "
            }
            if (item=='过流保护关阀'){
              val.condition=val.condition+" and "+"f_overCurrentProtection=1 "
            }
            if (item=='关阀走气'){
              val.condition=val.condition+" and "+"f_leakageFlag=1 "
            }
            if(item=='拆表报警'){
              val.condition=val.condition+" and "+"f_SplitAlarm=1 "
            }
          })
        }
        return val
      },
      // 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.criteria.model = {}
      },
      search (args) {
        // 处理故障类型
        args=this.DealFaults(args)
        // 处理信号
        args=this.DealSignal(args)
        args.condition =  `${args.condition} and f_filialeids like '${this.obj.resids}%'`
        this.model.search(args.condition, args.model)
      },
      getRes(obj) {
        this.obj.res = obj.res
        this.obj.resids = obj.resids
      },
    },

    watch: {
      // 监听查询对象
      'searchobj' (val) {
        if (this.searchobj != null) {
          this.$refs.paged.$refs.criteria.model.f_meternumber = this.searchobj.f_meternumber
          /*          this.$refs.paged.$refs.criteria.model.startDate = this.searchobj.model.startDate
                    this.$refs.paged.$refs.criteria.model.endDate = this.searchobj.model.endDate*/
          this.$refs.paged.$refs.criteria.search()
        }
      }
    },
    computed: {
      // 上报异常类型
      Gasproperties () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
      },
      Getusertype () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      Getuploadtype () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('上报类型')]
      },
      // 阀门状态
      Valvestates () {
        return [{label: '全部', value: '%%'}, {label: '关阀', value: '1'}, {label: '开阀', value: '0'}]
      },
      // 故障状态
      FaultStates () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('故障状态')]
      }
    }
  }
</script>
<style>
  .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>
