<template>
  <div class="select-overspread repair-bg auto" style="padding-bottom:5px">
    <validator name="v">
      <div class="panel panel-default auto repair-info-content">
        <div class="panel-body">
          <div class="auto repair-info-content compatible">
            <div class="row auto">
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group">
                <label class="text-justify">用户号</label>
                <input type="text" class="form-control" v-model="YQDZ_YQZH" id="YQDZ_YQZH" v-validate:YQDZ_YQZH="{required:true}">
                <button type="button" name="button" class="btn btn-primary" @click="findUserByYQZH">查找 </button>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify">表刚号</label>
                <input type="text" class="form-control" v-model="RQB_GH" id="RQB_GH" v-validate:RQB_GH="{required:true}">
                <button type="button" name="button" class="btn btn-primary" @click="findUserByGH">查找 </button>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify">用户号</label>
                <input type="text" class="form-control col-xs-4" id="YQDZ_YQZH" v-model="YQDZ_YQZH" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify">表刚号</label>
                <input type="text" class="form-control col-xs-4" id="RQB_GH" v-model="RQB_GH" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify" for="YQDZ_SM">地址全名</label>
                <input type="text" class="form-control" id="YQDZ_SM" v-model=YQDZ_SM disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify" for="JD_NAME">街道、路</label>
                <input type="text" class=form-control id="JD_NAME" v-model="JD_NAME" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-12 col-md-6 form-input-group margin">
                <label class="text-justify" for="XQ_NAME">小区</label>
                <input type="text" class="form-control" id="XQ_NAME" v-model="XQ_NAME" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify" for="KHLX">客户类型</label>
                <input type="text" class="form-control" id="KHLX" v-model="KHLX" disabled=disabled>
            </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify" for="YQDZ_HZ_MC">客户名称</label>
                <input type="text" class="form-control" id="YQDZ_HZ_MC" v-model="YQDZ_HZ_MC" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify" for="YQDZ_LXDH">联系电话</label>
                <input type="text" class="form-control" id="YQDZ_LXDH" v-model="YQDZ_LXDH" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
              <label class="text-justify" for="RQB_RQBLX_ID">表类型</label>
                <input type="text" class="form-control" id="RQB_RQBLX_ID" v-model="RQB_RQBLX_ID" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
              <label class="text-justify" for="RQBLX_MS">表类型说明</label>
                <input type="text" class="form-control" id="RQBLX_MS" v-model="RQBLX_MS" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify" for="RQB_WZ_ID">表型ID</label>
                <input type="text" class="form-control" id="RQB_WZ_ID" v-model="RQB_WZ_ID" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify" for="RQB_ZUIHOU_BJS">最后抄表读数</label>
                <input type="text" class="form-control" id="RQB_ZUIHOU_BJS" v-model="RQB_ZUIHOU_BJS" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify" for="RQB_KH">IC卡号</label>
                <input type="text" class="form-control" id="RQB_KH" v-model="RQB_KH" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
              <label class="text-justify" for="RQB_LJGQL">累计购买量</label>
                <input type="text" class="form-control" id="RQB_LJGQL" v-model="RQB_LJGQL" disabled=disabled>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify" for="f_oldreading">旧表读数</label>
                <input type="text" class="form-control" id="f_oldreading" v-model="f_oldreading">
            </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify" for="f_cmaddgas">补气量</label>
                <input type="text" class="form-control" id="f_cmaddgas" v-model="f_cmaddgas" disabled=disabled>
            </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin">
                <label class="text-justify" for="f_gasflowadjust">调节气量</label>
                <input type="text" class="form-control" id="f_gasflowadjust" v-model="f_gasflowadjust">
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin"
                   :class="{'has-warning':$v.NEW_RQB_GH.required,'has-success':!$v.NEW_RQB_GH.required}">
                <label class="text-justify">新表号</label>
                <input type="text" class="form-control" v-model="NEW_RQB_GH" id="NEW_RQB_GH" v-validate:NEW_RQB_GH="{required:true}">
                <button type="button" name="button" class="btn btn-primary" @click="scan">扫码</button>
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin"
                   :class="{'has-warning':$v.NEW_RQB_WZ.required,'has-success':!$v.NEW_RQB_WZ.required}">
                <label class="text-justify">新表型号</label>
                <input type="text" class="form-control" v-model="NEW_RQB_WZ" id="NEW_RQB_WZ" v-validate:NEW_RQB_WZ="{required:true}">
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin"
                   :class="{'has-warning':$v.NEW_RQB_RQBLX_ID.required,'has-success':!$v.NEW_RQB_RQBLX_ID.required}">
                <label class="text-justify">新表类型</label>
                <input type="text" class="form-control col-xs-8" v-model="NEW_RQB_RQBLX_ID" id="NEW_RQB_RQBLX_ID" v-validate:NEW_RQB_RQBLX_ID="{required:true}">
              </div>
              <div class="col-xs-12 col-sm-6 col-md-6 form-input-group margin"
                   :class="{'has-warning':$v.NEW_RQB_BC.required,'has-success':!$v.NEW_RQB_BC.required}">
                <label class="text-justify">新表厂</label>
                <input type="text" class="form-control" v-model="NEW_RQB_BC" id="NEW_RQB_BC" v-validate:NEW_RQB_BC="{required:true}">
              </div>
              <div style="text-align: center">
                <button type="button" style="font-size: 15px;margin-top: 5px" name="button" class="btn btn-primary" @click="addUserInfo" :disabled="!$v.valid">提交上传 </button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </validator>
  </div>

</template>

<script>
  import Vue from 'vue'

  export default {
    title: '单独换表',
    data() {
      return {
        YQDZ_YQZH:'',
        RQB_GH:'',
        YQDZ_SM:'',
        JD_NAME:'',
        XQ_NAME:'',
        KHLX:'',
        YQDZ_HZ_MC:'',
        YQDZ_LXDH:'',
        RQB_RQBLX_ID:'',
        RQBLX_MS:'',
        RQB_WZ_ID:'',
        RQB_ZUIHOU_BJS:'',
        RQB_KH:'',
        RQB_LJGQL:'',
        NEW_RQB_GH:'',
        NEW_RQB_WZ:'G2.5',
        NEW_RQB_RQBLX_ID:'物联网表',
        NEW_RQB_BC:'维斯达物联网表',
        f_oldreading:'',
        f_cmaddgas:'',
        f_gasflowadjust:'',
      }
    },
    methods: {
      findUserByYQZH(){
        this.$resetpost("chaxun/rs/sql/biaoInfo",{
            data:{
              condition:"YQDZ_YQZH = '"+this.YQDZ_YQZH+"'",orderitem:"YQDZ_YQZH",resolveMsg:null,rejectMsg:null
            }
        }).then((e)=>{
          console.log("ddddddddddddddddddddd",e.data.length)
          if(0===e.data.length){
            HostApp.alert("未查询到相关信息，请仔细核对用户号是否正确")
          }
          this.cleanInfo()
          this.showInfo(e.data[0])
        })
      },
      findUserByGH(){
        this.$resetpost("chaxun/rs/sql/biaoInfo",{
          data:{
            condition:"RQB_GH = '"+this.RQB_GH+"'",orderitem:"RQB_GH",resolveMsg:null,rejectMsg:null
          }
        }).then((e)=>{
           if(0===e.data.length){
             HostApp.alert("未查询到相关信息，请仔细核对表刚号是否正确")
           }
           this.cleanInfo()
          this.showInfo(e.data[0])})
      },
      addUserInfo(){
        this.$showMessage("请确认是否上传！",["confirm","cancel"]).then(
          (res)=> {
            if ("confirm" === res)
              this.$resetpost("shangchuan/rs/logic/newTableInfo", {
                YQDZ_YQZH: this.YQDZ_YQZH,
                RQB_GH: this.RQB_GH,
                JD_NAME: this.JD_NAME,
                XQ_NAME: this.XQ_NAME,
                YQDZ_SM: this.YQDZ_SM,
                KHLX: this.KHLX,
                YQDZ_HZ_MC: this.YQDZ_HZ_MC,
                YQDZ_LXDH: this.YQDZ_LXDH,
                RQB_RQBLX_ID: this.RQB_RQBLX_ID,
                RQBLX_MS: this.RQBLX_MS,
                RQB_WZ_ID: this.RQB_WZ_ID,
                RQB_ZUIHOU_BJS: this.RQB_ZUIHOU_BJS,
                RQB_KH: this.RQB_KH,
                RQB_LJGQL: this.RQB_LJGQL,
                NEW_RQB_GH: this.NEW_RQB_GH,
                NEW_RQB_WZ: this.NEW_RQB_WZ,
                NEW_RQB_RQBLX_ID: this.NEW_RQB_RQBLX_ID,
                NEW_RQB_BC: this.NEW_RQB_BC,
                f_oldreading: this.f_oldreading,
                f_cmaddgas: this.f_cmaddgas,
                f_gasflowadjust: this.f_gasflowadjust,
                operation: "添加"
              }).then((res) => {
                if ("success" == res.data.state) {
                  HostApp.alert("提交成功")
                }
                this.cleanInfo()
              })
          })
      },
      showInfo(t){
        this.YQDZ_YQZH=t.yqdz_yqzh,
        this.JD_NAME=t.jd_name,
        this.XQ_NAME=t.xq_name,
        this.YQDZ_SM=t.yqdz_sm,
        this.KHLX=t.khlx,
        this.YQDZ_HZ_MC=t.yqdz_hz_mc,
        this.YQDZ_LXDH=t.yqdz_lxdh,
        this.RQB_GH=t.rqb_gh,
        this.RQB_RQBLX_ID=t.rqb_rqblx_id,
        this.RQBLX_MS=t.rqblx_ms,
        this.RQB_WZ_ID=t.rqb_wz_id,
        this.RQB_ZUIHOU_BJS=t.rqb_zuihou_bjs,
        this.RQB_KH=t.rqb_kh,
        this.RQB_LJGQL=t.rqb_ljgql
      },
      cleanInfo(){
        this.YQDZ_YQZH="",
        this.JD_NAME="",
        this.XQ_NAME="",
        this.YQDZ_SM="",
        this.KHLX="",
        this.YQDZ_HZ_MC="",
        this.YQDZ_LXDH="",
        this.RQB_GH="",
        this.RQB_RQBLX_ID="",
        this.RQBLX_MS="",
        this.RQB_WZ_ID="",
        this.RQB_ZUIHOU_BJS="",
        this.RQB_KH="",
        this.RQB_LJGQL="",
        this.NEW_RQB_BC="维斯达物联网表",
        this.NEW_RQB_GH="",
        this.NEW_RQB_WZ="G2.5",
        this.NEW_RQB_RQBLX_ID="物联网表",
        this.f_oldreading="",
        this.f_cmaddgas="",
        this.f_gasflowadjust=0
      },
      scan(){
        HostApp.__this__=this,
        HostApp.scanCode({callback:"javascript:HostApp.__this__.getCode();"})
      },
      getCode(){
        var data=HostApp.getCode().data;
        this.NEW_RQB_GH=data
      }
    },
    ready() {
    },
    watch:{
      'f_oldreading'(){
        this.f_cmaddgas=this.RQB_LJGQL-this.f_oldreading
      }
    }
    // computed: {
    //   valid(){
    //     this.savevalid.uservalid = this.$v.valid
    //     return this.$v.valid
    //   }
    // }
  }
</script>
<style lang="less">
  .class-erro {
    color: #a94442;
  }
  .margin{
    margin-top:5px;
  }
</style>

