<template>
  <div class="auto app-text" style="margin-top: 5px;">
    <header class="head">
      抄表信息
    </header>
    <div class="panel" style="padding: 10px 10px 5px 10px;">
      <div class="panel-body panel-self">
        <div  class="row auto app-row col-xs-12  col-sm-6 col-md-6">
          <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">上次抄表日期</p>
          <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left font">{{ model.f_last_hand_date }}</p>
        </div>
        <div  class="row auto app-row col-xs-12  col-sm-6 col-md-6">
          <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">上次基表底数</p>
          <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left font">{{ model.f_last_tablebase }}</p>
        </div>
        <div  class="row auto app-row col-xs-12  col-sm-6 col-md-6">
          <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">上次剩余气量</p>
          <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left font">{{ model.f_last_lcd }}</p>
        </div>
        <div  class="row auto app-row col-xs-12  col-sm-6 col-md-6">
          <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">上次剩余金额</p>
          <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left font">{{ parseInt(model.f_iclastmoney) }}</p>
        </div>
        <div class="row auto app-row col-xs-12 col-sm-12 col-md-12 bg-white ">
          <label for="f_sumgas" class="panel-title col-xs-4 col-sm-2 col-md-2 text-left font">总购气量</label>
          <div class="col-xs-6  col-sm-4 col-md-4 ">
            <input type="number" id="f_sumgas" class="form-control font " v-model="model.f_sumgas" >
          </div>
          <div class="col-sm-2 col-xs-2 col-sm-offset-1 col-md-2 col-md-offset-1">
            <button type="button" name="button" class="btn btn-primary" @click="getSumGas(model.card_id)"
            >详情
            </button>
          </div>
        </div>
        <div  class="row auto app-row col-xs-12  col-sm-6 col-md-6">
          <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">期间购气:</p>
          <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left font">{{ model.f_sumgas_moment }}</p>
        </div>
        <div  class="row auto app-row col-xs-12  col-sm-6 col-md-6">
          <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">上次未充:</p>
          <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left font">{{ model.f_nogasvalue }}</p>
        </div>
        <div  class="row auto app-row col-xs-12  col-sm-6 col-md-6">
          <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">本次已充:</p>
          <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left font">{{ model.f_hascharge}}</p>
        </div>
        <div  class="row auto app-row col-xs-12  col-sm-6 col-md-6">
          <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">本次未充:</p>
          <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left font">{{ model.f_hasnotcharge}}</p>
        </div>
        <div class="col-xs-12  col-sm-12 col-md-12" v-if="!(model.f_weekcheck==='1'||model.f_weekcheck==='true'||model.f_weekcheck==='是')">
          <div class="row auto app-row col-xs-12 col-sm-12 col-md-12 bg-white ">
          <div class="auto col-xs-12 col-sm-4 col-md-4 bg-white app-row ">
            <label for="f_new_tablebase" class="panel-title col-xs-4 col-sm-6 col-md-6 text-left font">基表底数</label>
            <div class="col-xs-8  col-sm-6 col-md-6 ">
              <input type="number" id="f_new_tablebase" class="form-control font" v-el:f_new_tablebase v-next-el="f_new_lcd" @blur="getMeterMessage()" v-model="model.f_new_tablebase" >
            </div>
          </div>
          <div class="auto col-xs-12 col-sm-4 col-md-4 bg-white app-row ">
            <label for="f_tablesnapsgas" class="panel-title col-xs-4 col-sm-6 col-md-6 text-left font">基表走气量</label>
            <div class="col-xs-8  col-sm-6 col-md-6  ">
              <input type="number" id="f_tablesnapsgas" class="form-control font " v-model="model.f_tablesnapsgas" readonly>
            </div>
          </div>
          <div class="auto col-xs-12 col-sm-4 col-md-4 bg-white app-row ">
            <label for="f_meter_repair" class="panel-title col-xs-4 col-sm-6 col-md-6 text-left font">表维修</label>
            <div class="col-xs-8  col-sm-6 col-md-6  ">
              <input type="number" id="f_meter_repair" class="form-control font " v-model="model.f_meter_repair" readonly>
            </div>
          </div>
          </div>
          <div class="row auto app-row col-xs-12 col-sm-12 col-md-12 bg-white ">
          <div class="auto col-xs-12 col-sm-4 col-md-4 bg-white app-row " v-if="model.f_meter_classify!=='机表'">
            <label for="f_new_tablebase" class="panel-title col-xs-4 col-sm-6 col-md-6 text-left font">卡剩余气量</label>
            <div class="col-xs-8  col-sm-6 col-md-6 ">
              <input type="number" id="f_new_lcd" class="form-control font " @blur="getCardMessage()" v-el:f_new_lcd v-next-el="f_insflow" v-model="model.f_new_lcd" >
            </div>
          </div>
          <div class="auto col-xs-12 col-sm-4 col-md-4 bg-white app-row " v-if="model.f_meter_classify!=='机表'">
            <label for="f_icsnapsgas" class="panel-title col-xs-4 col-sm-6 col-md-6 text-left font">IC卡扣气量</label>
            <div class="col-xs-8  col-sm-6 col-md-6 ">
              <input type="text" id="f_icsnapsgas" class="form-control font " v-model="model.f_icsnapsgas" readonly>
            </div>
          </div>
          <div class="auto col-xs-12 col-sm-4 col-md-4 bg-white app-row " v-if="model.f_meter_classify!=='机表'">
            <label for="f_card_repair" class="panel-title col-xs-4 col-sm-6 col-md-6 text-left font">卡维修</label>
            <div class="col-xs-8  col-sm-6 col-md-6  ">
              <input type="text" id="f_card_repair" class="form-control font " v-model="model.f_card_repair" readonly>
            </div>
          </div>
          </div>
            <div class="row auto app-row col-xs-12 col-sm-12 col-md-12 bg-white ">
          <div class="auto col-xs-12 col-sm-4 col-md-4 bg-white app-row " v-if="model.f_meter_classify!=='机表'">
            <label for="f_curbalance" class="panel-title col-xs-4 col-sm-6 col-md-6 text-left font">卡剩余金额</label>
            <div class="col-xs-8  col-sm-6 col-md-6 ">
              <input type="text" id="f_curbalance" class="form-control font " @blur="getMoneyMessage()" v-model="model.f_curbalance"  >
            </div>
          </div>

          <div class="auto col-xs-12 col-sm-4 col-md-4 bg-white app-row " v-if="model.f_meter_classify!=='机表'">
            <label for="f_datacomparison" class="panel-title col-xs-4 col-sm-6 col-md-6 text-left font">数据对比</label>
            <div class="col-xs-8  col-sm-6 col-md-6 ">
              <input type="text" id="f_datacomparison" class="form-control font " v-model="model.f_datacomparison" readonly>
            </div>
          </div>
          <div  class="bg-white auto app-row col-xs-12  col-sm-4 col-md-4" v-if="model.f_meter_classify!=='机表'">
            <p class="panel-title col-xs-4 col-sm-6 col-md-6 text-left font">抄表状态</p>
            <!--<p class="panel-title col-xs-8 col-sm-6 col-md-6 text-left font">{{ model.f_result_state}}</p>-->
            <div class="col-xs-8  col-sm-6 col-md-6 ">
              <input type="text" id="f_datacomparison" class="form-control font " v-model="model.f_result_state" readonly>
            </div>
          </div>
              <div   class="row auto bg-white app-row col-xs-12  col-sm-12 col-md-12" >
                <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">IC卡累计</p>
                <div class="col-xs-8  col-sm-8 col-md-8 ">
                  <input type="text" id="" class="form-control font " v-model="model.f_checkic1" @blur="checkbyic1()">
                </div>
              </div>
<!--              <div   class="row auto bg-white app-row col-xs-12  col-sm-12 col-md-12" v-if="showic1">-->
<!--                <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">本期IC卡底数</p>-->
<!--                <div class="col-xs-8  col-sm-8 col-md-8 ">-->
<!--                  <input type="text" id="" class="form-control font " v-model="model.f_checkicbase" >-->
<!--                </div>-->
<!--              </div>-->
            </div>
          <div class="auto col-xs-12 col-sm-6 col-md-6 bg-white app-row ">
            <label for="f_insflow" class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">瞬时流量</label>
            <div class="col-xs-8  col-sm-8 col-md-8 ">
              <input type="number" id="f_insflow" class="form-control font " v-model="model.f_insflow" v-el:f_insflow v-next-el="f_temperature">
            </div>
          </div>

          <div class="auto col-xs-12 col-sm-6 col-md-6 bg-white app-row ">
            <label for="f_temperature" class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">温度</label>
            <div class="col-xs-8  col-sm-8 col-md-8 ">
              <input type="number" id="f_temperature" class="form-control font " v-model="model.f_temperature" v-el:f_temperature v-next-el="f_pressure">
            </div>
          </div>

          <div class="auto col-xs-12 col-sm-6 col-md-6 bg-white app-row ">
            <label for="f_pressure" class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">压力</label>
            <div class="col-xs-8  col-sm-8 col-md-8 ">
              <input type="number" id="f_pressure" class="form-control font " v-model="model.f_pressure" v-el:f_pressure v-next-el="f_condition">
            </div>
          </div>
          <div class="auto col-xs-12 col-sm-6 col-md-6 bg-white app-row ">
            <label for="f_condition" class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">工况</label>
            <div class="col-xs-8  col-sm-8 col-md-8 ">
              <input type="number" id="f_condition" class="form-control font " v-model="model.f_condition" v-el:f_condition v-next-el="f_condition">
            </div>
          </div>
          <div class="auto  col-xs-12 col-sm-12 col-md-12 bg-white  app-row" style="padding: 0.5em">

            <p class="panel-title col-xs-4  col-sm-2 col-md-2 text-left font">换表</p>
            <div class="col-xs-4 col-sm-2 col-md-2">
              <input type="radio" name="f_if_change" id="f_if_change" value="是" v-model="model.f_if_change" > 是
            </div>
            <div class="col-xs-4 col-sm-2 col-md-2">
              <input type="radio" name="f_if_change" id="f_if_change" value="否" v-model="model.f_if_change" checked> 否
            </div>
          </div>
        </div>

        <div class="check-info row auto app-row col-xs-12  col-sm-12 col-md-12" v-if="model.f_weekcheck==='1'||model.f_weekcheck==='true'||model.f_weekcheck==='是'">

          <div class="auto col-xs-12 col-sm-12 col-md-12 bg-white ">
            <div class="col-xs-12 col-sm-6 col-md-6">
              <label for="f_weekchecksn" class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">替换表表号</label>
              <div class="col-xs-8  col-sm-8 col-md-8 ">
                <input type="text" id="f_weekchecksn" class="form-control font " v-model="model.f_weekchecksn" v-el:f_weekchecksn v-next-el="f_weekcheckdishu">
              </div>
            </div>
          </div>
          <div  class="auto col-xs-12 col-sm-6 col-md-6 bg-white app-row ">
            <label for="f_weekchecknum" class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">替换表上次安装读数</label>
            <div class="col-xs-8  col-sm-8 col-md-8 ">
              <input type="text" id="f_weekchecknum" class="form-control font " v-model="model.f_weekchecknum" disabled>
            </div>
          </div>

          <div  class="auto col-xs-12 col-sm-6 col-md-6 bg-white app-row ">
            <label for="f_weekcheckicnum" class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">IC卡上次安装剩余气量</label>
            <div class="col-xs-8  col-sm-8 col-md-8 ">
              <input type="text" id="f_weekcheckicnum" class="form-control font " v-model="model.f_weekcheckicnum" disabled>
            </div>
          </div>

          <div  class="auto col-xs-12 col-sm-6 col-md-6 bg-white app-row ">
            <label for="f_weekcheckdishu" class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">替换表底数</label>
            <div class="col-xs-8  col-sm-8 col-md-8 ">
              <input type="text" id="f_weekcheckdishu" class="form-control font " @blur="getWeekMeterMessage()" v-el:f_weekcheckdishu v-next-el="f_weekcheckicdishu" v-model="model.f_weekcheckdishu" >
            </div>
          </div>

          <div  class="auto col-xs-12 col-sm-6 col-md-6 bg-white app-row ">
            <label for="f_insflow" class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">走气量</label>
            <div class="col-xs-8  col-sm-8 col-md-8 ">
              <input type="text" id="f_insflow" class="form-control font " v-model="model.f_weektablesnapsgas" readonly>
            </div>
          </div>

          <div  class="auto col-xs-12 col-sm-6 col-md-6 bg-white app-row ">
            <label for="f_temperature" class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">卡剩余气量</label>
            <div class="col-xs-8  col-sm-8 col-md-8 ">
              <input type="text" id="f_weekcheckicdishu" class="form-control font " @blur="getWeekCardMessage()" v-model="model.f_weekcheckicdishu"  v-el:f_weekcheckicdishu v-next-el="f_remark">
            </div>
          </div>

          <div  class="auto col-xs-12 col-sm-6 col-md-6 bg-white app-row ">
            <label for="f_pressure" class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">扣气量</label>
            <div class="col-xs-8  col-sm-8 col-md-8 ">
              <input type="text" id="f_pressure" class="form-control font " v-model="model.f_weekicsnapsgas" >
            </div>
          </div>
          <div  class="row auto bg-white app-row col-xs-12  col-sm-4 col-md-4" v-if="model.f_meter_classify!=='机表'">
            <p class="panel-title col-xs-4 col-sm-6 col-md-6 text-left font">抄表状态</p>
            <p class="panel-title col-xs-8 col-sm-6 col-md-6 text-left font">{{ model.f_check_result_state}}</p>
          </div>
          <div   class="row auto bg-white app-row col-xs-12  col-sm-12 col-md-12" v-if="showic">
            <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">周检表IC卡累计</p>
            <div class="col-xs-8  col-sm-8 col-md-8 ">
              <input type="text" id="" class="form-control font " v-model="model.f_checkic" @blur="checkbyic()">
            </div>
          </div>
        </div>

        <div class=" row auto app-row col-xs-12 col-sm-12 col-md-12 bg-white ">
          <label for="f_mark" class="panel-title col-xs-4 col-sm-2 col-md-2 text-left font">备注</label>
          <div class="col-xs-8  col-sm-10 col-md-10 ">
            <input type="text" id="f_card_id" class="form-control font " v-model="model.f_remark" v-el:f_remark>
          </div>
        </div>
        <div class="row auto col-xs-12 col-sm-12 col-md-12 mt-20">
          <!--<img-area :model="model.imgs"></img-area>-->
          <picture-area  :model="model.imgs"></picture-area>
        </div>
        <div class="row auto mt-20"  v-if="!data.hidden">
          <div class="col-xs-2 col-sm-2 col-md-2  col-xs-offset-2 col-sm-offset-2 col-md-offset-2">
            <button type="button" class="btn btn-lg btn-color btn-font"  @click="save()">保存</button>
          </div>
          <div class="col-xs-2 col-sm-2 col-md-2 col-xs-offset-1 col-sm-offset-1 col-md-offset-1" >
            <button type="button" class="btn btn-color btn-font btn-lg"  @click="commit()">提交</button>
          </div>
          <div v-if="model.f_result_state==='异常'" class="col-xs-2 col-sm-2 col-md-2 col-xs-offset-1 col-sm-offset-1 col-md-offset-1" >
            <button type="button" class="btn btn-warning btn-font btn-lg"  @click="torepair()">转维修</button>
          </div>
        </div>
        <!--<div class="row auto" style="margin: 30px 0 60px 0;">-->
          <!--<p class="text-warning">&nbsp;&nbsp;提示：表底数输入燃气表黑色部分数字</p>-->
        <!--</div>-->
      </div>
    </div>
  </div>
</template>
<script>
  import * as Util from '../Util'
  import Vue from 'vue'
  import co from 'co'
  let repairGen= function * (self, condition) {
    let data ={}
    data = Object.assign({},data,self.model)
    if(self.model.f_inputtor){
      data.f_operator_name = self.model.f_inputtor
    }
    console.log(JSON.stringify(data))
    delete data.id
    data.f_phone = data.f_user_phone
    data.f_contact_phone = data.f_user_phone
    let res =   self.$resetpost(`${self.$androidUtil.getProxyUrl()}/rs/saveSaleEntity/t_handrepair`,data,{resolveMsg:null,rejectMsg:null})
      .then((res) => {
        self.commit()
      })

  }
  export default {
    title: '手机单户抄表',
    data () {
      return {
        showic1:false,
        showic:false,
        model: {
          failure:'[{"f_failure_type":"卡表故障","failurecase":["气量不符"]}]',
          f_operator_name:'',
          f_order_type:'抄表维修',
          f_workorder_type:'维修单',
          f_issue:'否',
          f_if_change:'否',
          f_check_result_state:'',
            imgInfo: '',
          imgName: '',
          f_result_state:'',
          f_weekcheckicnum:'',
          f_checkic:'',
          f_checkic1:'',
          f_checkicbase:'',
          f_real_balance:'',
          f_weekchecksn:'',
          f_weekchecknum:'',
          f_weekcheckdishu:'',
          f_insflow:'',
          f_weekcheckicdishu:'',
          f_oughtamount: 0,
          f_new_lcd:0,
          f_curbalance:0,
          f_meter_repair:0,
          f_card_repair:0,
          f_new_tablebase:0,
          f_tablesnapsgas:0,
          f_icsnapsgas:0,
          imgs:[]
        }
      }
    },
    props: {
      data: {
        type: Object,
        default: function () {
          return {
          }
        }
      },
      showmessage:true,
      type: {
        type: String,
        default: 'save'
      }
    },
    watch:{
      'model.f_result_state'(val){
        if(val && val==='异常'){
          this.showic1 = true
        }
      },
      'model.f_check_result_state'(val){
        if(val && val==='异常'){
          this.showic = true
        }
      },
      'data.f_download'(val){
        // console.log('变化' + JSON.stringify(data))
        // window.alert(123)
        if(this.data.f_download){
          // this.$showMessage('数据更新成功,请核对数据重新计算')
          this.data.f_new_lcd = this.model.f_new_lcd,
            this.data.f_tablebase = this.model.f_new_tablebase,
            this.data.f_weekcheckdishu = this.model.f_weekcheckdishu,
            this.data.f_weekcheckicdishu = this.model.f_weekcheckicdishu
        }


        // this.model = Object.assign({}, this.model, this.data)
        this.updatedata()
      }

    },
    ready () {
      // 抄表按钮可以点击
      console.log(this.model)
      this.flag = true
      this.updatedata()
    },
    methods: {
      checkbyic(){
        this.model.f_check_result_state = Math.abs(parseInt(this.model.f_checkic)-parseInt(this.model.f_weekcheckdishu))<=this.model.f_tablewitherrorvalue?'正常':'异常'
      },
      checkbyic1(){
        this.model.f_result_state = Math.abs(parseInt(this.model.f_checkic1)-parseInt(this.model.f_new_tablebase))<=this.model.f_tablewitherrorvalue?'正常':'异常'
      },
    updatedata(){
        this.model = Object.assign({}, this.model, this.data)
        if(this.type === 'save') {
            this.model.f_sumgas = this.data.f_sumgas ? this.data.f_sumgas : 0,
            this.model.f_nogasvalue = this.data.f_nogasvalue ? this.data.f_nogasvalue : 0,
            this.model.f_hasnotcharge = this.data.f_hasnotcharge ? this.data.f_hasnotcharge : 0,
            this.model.f_hascharge = this.data.f_hascharge ? this.data.f_hascharge : 0,
            this.model.f_last_lcd = this.data.f_last_lcd ? this.data.f_last_lcd : 0,
            this.model.f_new_tablebase = this.data.f_tablebase ? this.data.f_tablebase : 0,
            this.model.f_new_lcd = this.data.f_new_lcd ? this.data.f_new_lcd : 0,
            this.model.f_tablesnapsgas = this.data.f_tablesnapsgas ? this.data.f_tablesnapsgas : 0,
            this.model.f_meter_repair = this.data.f_meter_repair ? this.data.f_meter_repair : 0,
            this.model.f_card_repair = this.data.f_card_repair ? this.data.f_card_repair : 0,
            this.model.f_icsnapsgas = this.data.f_icsnapsgas ? this.data.f_icsnapsgas : 0,
            this.model.f_result_state = this.data.f_result_state ? this.data.f_result_state : '正常',
            this.model.f_sumgas_moment = this.data.f_sumgas_moment ? this.data.f_sumgas_moment : 0,
            this.model.f_curbalance = this.data.f_curbalance ? this.data.f_curbalance : 0,
            this.model.f_datacomparison = this.data.f_datacomparison ? this.data.f_datacomparison : 0
            this.model.f_if_change = this.data.f_if_change ? this.data.f_if_change : '否'
            console.log(this.model)
        }
      },
    //获取累购
      getSumGas(){
        this.$goto('hand-sell-history', {model: this.model,showmessage:this.showmessage,temp:'phone-handplan-info'}, 'list')
      },
      getMoneyMessage(){
        if (this.model.f_curbalance === '' || this.model.f_curbalance === undefined) {
          this.$showMessage('请检查你录入的金额')
          return
        }
        this.model.f_new_lcd = parseInt(this.model.f_curbalance / this.model.f_price)
        this.model.f_pregas = this.model.f_pregas?this.model.f_pregas:0
        this.model.f_sumgas_moment = this.model.f_sumgas_moment?this.model.f_sumgas_moment:0
        let res = this.$androidUtil.bzLogic('gasComputation', this.model,{rejectMsg: null, resolve: null})
        this.model.f_hasnotcharge = parseInt(res.hasnotCharge)
        this.model.f_hascharge = (parseInt(this.model.f_sumgas_moment)+ parseInt(this.model.f_nogasvalue) - parseInt(this.model.f_hasnotcharge))
        console.log('本期已充'+this.model.f_hascharge)
        this.model.f_last_lcd= this.model.f_last_lcd?this.model.f_last_lcd:0
        this.model.f_icsnapsgas = (parseInt(this.model.f_last_lcd)+ parseInt(this.model.f_hascharge)+parseInt(this.model.f_card_repair)- parseInt(this.model.f_new_lcd))
        console.log('IC走气'+this.model.f_icsnapsgas)
        this.model.f_result_state = res.f_result_state
        console.log('抄表状态'+this.model.f_result_state)
        this.model.f_datacomparison = (parseInt(this.model.f_icsnapsgas)-parseInt(this.model.f_tablesnapsgas))
      },
      //获取ic卡表数据
      getCardMessage(){
        if (this.model.f_new_lcd === '' || this.model.f_new_lcd === undefined) {
          this.$showMessage('请检查你录入的液晶示数')
          return
        }
        this.model.f_curbalance = parseInt(this.model.f_new_lcd * this.model.f_price)
        this.model.f_pregas = this.model.f_pregas?this.model.f_pregas:0
        this.model.f_sumgas_moment = this.model.f_sumgas_moment?this.model.f_sumgas_moment:0
        let res = this.$androidUtil.bzLogic('gasComputation', this.model,{rejectMsg: null, resolve: null})
        this.model.f_hasnotcharge = parseInt(res.hasnotCharge)
        this.model.f_hascharge = (parseInt(this.model.f_sumgas_moment)+ parseInt(this.model.f_nogasvalue) - parseInt(this.model.f_hasnotcharge))
        console.log('本期已充'+this.model.f_hascharge)
        this.model.f_last_lcd= this.model.f_last_lcd?this.model.f_last_lcd:0
        this.model.f_icsnapsgas = (parseInt(this.model.f_last_lcd)+ parseInt(this.model.f_hascharge)+parseInt(this.model.f_card_repair)- parseInt(this.model.f_new_lcd))
        console.log('IC走气'+this.model.f_icsnapsgas)
        this.model.f_result_state = res.f_result_state
        console.log('抄表状态'+this.model.f_result_state)
        this.model.f_datacomparison = (parseInt(this.model.f_icsnapsgas)-parseInt(this.model.f_tablesnapsgas))

        console.log('剩余金额'+this.model.f_curbalance)
        // let res = this.$androidUtil.bzLogic('gasComputation', this.model, {rejectMsg: null, resolve: null})

      },
      getWeekCardMessage(){
        if(this.model.f_card_id){
          if (this.model.f_weekcheckicdishu === '' || this.model.f_weekcheckicdishu === undefined) {
            this.$showMessage('请检查你录入的液晶示数')
            return
          }
        }
        let postdata = Object.assign({},this.model)
        postdata.week = '1',
        this.model.f_pregas = this.model.f_pregas?this.model.f_pregas:0
        this.model.f_sumgas_moment = this.model.f_sumgas_moment?this.model.f_sumgas_moment:0
        let res = this.$androidUtil.bzLogic('gasComputation', postdata,{rejectMsg: null, resolve: null})
        this.model.f_hasnotcharge = parseInt(res.hasnotCharge)
        this.model.f_hascharge = (parseInt(this.model.f_sumgas_moment)+ parseInt(this.model.f_nogasvalue) - parseInt(this.model.f_hasnotcharge))
        console.log('本期已充'+this.model.f_hascharge)
        this.model.f_weekcheckicnum= this.model.f_weekcheckicnum?this.model.f_weekcheckicnum:0
        this.model.f_weekicsnapsgas = (parseInt(this.model.f_weekcheckicnum)+ parseInt(this.model.f_hascharge)+parseInt(this.model.f_card_repair)- parseInt(this.model.f_weekcheckicdishu))
        console.log('IC走气'+this.model.f_icsnapsgas)
        this.model.f_check_result_state = res.f_result_state
        console.log('抄表状态'+this.model.f_result_state)
        this.model.f_datacomparison = (parseInt(this.model.f_icsnapsgas)-parseInt(this.model.f_tablesnapsgas))
        this.model.f_curbalance = parseInt(this.model.f_new_lcd * this.model.f_price)
        console.log('剩余金额'+this.model.f_curbalance)

        // let res = this.$androidUtil.bzLogic('gasComputation', this.model, {rejectMsg: null, resolve: null})

      },
      //获取基表走气量
      getWeekMeterMessage(){
        // if(this.model.f_weekcheck&&this.model.f_weekcheck ==='1'&& this.model.f_weekcheckdishu){
        //  this.model.f_weekcheckdishu = this.model.f_new_tablebase
        // }
        if (this.model.f_weekcheckdishu === '' || this.model.f_weekcheckdishu === undefined) {
          this.$showMessage('请检查你录入的表底数')
          return
        }
        if (parseInt(this.model.f_weekcheckdishu) - parseInt(this.model.f_weekchecknum) < 0) {
          this.$showMessage('录入本期表底数不能小于上期表底数！')
          return
        }
        this.model.f_meter_repair= this.model.f_meter_repair?this.model.f_meter_repair:0
        this.model.f_weekchecknum= this.model.f_weekchecknum?this.model.f_weekchecknum:0
        // this.$set(this.model.f_tablesnapsgas,'')
        this.model.f_weektablesnapsgas = parseInt(this.model.f_weekcheckdishu)- parseInt(this.model.f_weekchecknum)-parseInt(this.model.f_meter_repair)
        if (this.model.f_weekcheckicdishu && this.model.f_card_id ) {
          this.getWeekCardMessage()
        }
      },
      //获取基表走气量
      getMeterMessage(){
        // if(this.model.f_weekcheck&&this.model.f_weekcheck ==='1'&& this.model.f_weekcheckdishu){
        //   this.model.f_new_tablebase = this.model.f_weekcheckdishu
        // }
        if (this.model.f_new_tablebase === '' || this.model.f_new_tablebase === undefined) {
          this.$showMessage('请检查你录入的表底数')
          return
        }
        if (parseInt(this.model.f_new_tablebase) - parseInt(this.model.f_last_tablebase) < 0) {
          this.$showMessage('录入本期表底数不能小于上期表底数！')
          return
        }
        this.model.f_meter_repair= this.model.f_meter_repair?this.model.f_meter_repair:0
        this.model.f_last_tablebase= this.model.f_last_tablebase?this.model.f_last_tablebase:0
        // this.$set(this.model.f_tablesnapsgas,'')
        this.model.f_tablesnapsgas = parseInt(this.model.f_new_tablebase)- parseInt(this.model.f_last_tablebase)-parseInt(this.model.f_meter_repair)
        if (this.model.f_new_lcd ) {
          this.getCardMessage()
        }
      },
      // getWeekMeterMessage(){
      //   if (this.model.f_weekcheckdishu === '' || this.model.f_weekcheckdishu === undefined) {
      //     this.$showMessage('请检查你录入的表底数')
      //     return
      //   }
      //   if (parseInt(this.model.f_weekcheckdishu) - parseInt(this.model.f_last_tablebase) < 0) {
      //     this.$showMessage('录入本期表底数不能小于上期表底数！')
      //     return
      //   }
      //   this.model.f_new_tablebase = parseInt(this.model.f_weekcheckdishu)
      //   this.model.f_meter_repair= this.model.f_meter_repair?this.model.f_meter_repair:0
      //   this.model.f_last_tablebase= this.model.f_last_tablebase?this.model.f_last_tablebase:0
      //   // this.$set(this.model.f_tablesnapsgas,'')
      //   this.model.f_tablesnapsgas = parseInt(this.model.f_weekcheckdishu)- parseInt(this.model.f_last_tablebase)-parseInt(this.model.f_meter_repair)
      // },

      commit () {
        if(!this.model.f_checkic1){
          console.log(this.model.f_checkic1)
          this.$showMessage('请输入IC卡累计！！！')
          return
        }

        if(this.model.f_weekcheck==='1'||this.model.f_weekcheck==='true'||this.model.f_weekcheck==='是'){
          if (this.f_weektablesnapsgas < 0 && this.model.f_if_change!=='是') {
            this.$showMessage('录入本期表底数不能小于上期表底数！请核对抄表数据')
            return
          }

          // if (parseInt(this.model.f_weekcheckdishu) - parseInt(this.model.f_weekchecknum) < 0) {
          //   this.$showMessage('录入本期表底数不能小于上期表底数！')
          //   return
          // }
        }else{
          if (this.model.f_new_tablebase === '' || this.model.f_new_tablebase === undefined) {
            this.$showMessage('请检查你录入的表底数')
            return
          }
          if ((parseInt(this.model.f_new_tablebase) - parseInt(this.model.f_last_tablebase) < 0) && this.model.f_if_change!=='是') {
            this.$showMessage('录入本期表底数不能小于上期表底数！')
            return
          }
        }
        // if(this.model.f_result_state==='异常'&&){
        //   this.$showMessage(`抄表异常，请核对抄表数据`)
        //   return
        // }

        // if (!(this.model.imgName && this.model.imgName.length > 0)) {
        //   this.$showMessage('请录入抄表照片！')
        //   return
        // }
        if (!this.flag) {
          this.$showMessage(`系统正在进行抄表，请勿重复操作！`)
          // this.$showAlert('系统正在进行抄表，请勿重复操作！', 'warning', 2000)
          return
        }
        if(this.model.lastImgName){
          this.model.lastImgName = `.${this.model.f_user_name}${this.model.imgName.substring(this.model.imgName.indexOf('.'))}`
        }
        // 设置抄表按钮不可用
        // this.flag = false
        // 将用户编号放入抄表照片名中
        console.log(this.model.lastImgName)
        this.model.f_oughtamount = parseInt(this.model.f_new_tablebase) - parseInt(this.model.f_last_tablebase)
        this.model.f_end_time = this.data.f_end_time
        this.model.f_user_id = parseInt(this.model.f_user_id)
        this.model.f_new_tablebase = parseInt(this.model.f_new_tablebase)
        this.model.f_new_lcd = parseInt(this.model.f_new_lcd)
      if(  this.model.f_weekcheck==='1'||this.model.f_weekcheck==='true'||this.model.f_weekcheck==='是'){
        this.model.f_new_tablebase =this.model.f_new_tablebase?this.model.f_new_tablebase: parseInt(this.model.f_last_tablebase)
      }
        let res = this.$androidUtil.bzLogic('phone-readmeter', this.model, {rejectMsg: null, resolve: null})
        console.log('上传返回结果'+ res)
        console.log('上传返回结果'+JSON.stringify(res))
        if (res.code === 200) {
          console.log('抄表完成！')
          // 抄表完成设置按钮可用
          this.flag = false
          this.$showMessage('抄表成功！')
          // this.$showAlert('抄表成功！', 'success', 2000)
          // 发送抄表成功事件给父页面
          // this.$dispatch('hand-success', this.type)
        }else{
          console.log('抄表失败')
          // 抄表完成设置按钮可用
          this.flag = true
          // this.$showMessage(`${res.backData.msg}！请前往表单上传重新提交`)
          // this.$showAlert(`${res.backData.msg}！请前往表单上传重新提交`, 'danger', 2000)
        }
      },
      //将数据存入本地数据库，下次进入页面回写数据
      torepair(val){
        this.$showMessage('是否确定申请生成维修单', ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
              let re = repairGen(this,val)
              co(re)
          }
        })
      },
      save(){
        if (!this.flag) {
          this.$showMessage(`该抄表单已上传成功，请勿重复保存！`)
          return
        }
        if(this.model.f_weekcheck==='1'||this.model.f_weekcheck==='true'||this.model.f_weekcheck==='是'){
          if (this.f_weektablesnapsgas < 0 && this.model.f_if_change!=='是') {
            this.$showMessage('录入本期表底数不能小于上期表底数！请核对抄表数据')
            return
          }

          // if (parseInt(this.model.f_weekcheckdishu) - parseInt(this.model.f_weekchecknum) < 0) {
          //   this.$showMessage('录入本期表底数不能小于上期表底数！')
          //   return
          // }
        }else{
          if (this.model.f_new_tablebase === '' || this.model.f_new_tablebase === undefined) {
            this.$showMessage('请检查你录入的表底数')
            return
          }
          if (this.model.f_tablesnapsgas<0 && this.model.f_if_change!=='是') {
            this.$showMessage('录入本期表底数不能小于上期表底数！')
            return
          }
        }
        this.model.f_new_tablebase = parseInt(this.model.f_new_tablebase)
        this.model.f_new_lcd = parseInt(this.model.f_new_lcd)
        // this.$dispatch('updatemeter')
        this.model.f_end_time = this.data.f_end_time
        let res = this.$androidUtil.bzLogic('local-save',this.model,{rejectMsg: null, resolve: null})
        console.log('保存到本地'+ JSON.stringify(res))
        if(res.status === 200){
          // this.flag= false
          this.$showMessage('本地数据保存成功！')
          // this.$showAlert('本地数据保存成功!', 'success', 2000)
        }
      }
    }
  }
</script>
<style scoped>
  .mt-5 {
    margin-top: 5px;
  }
  .mt-10 {
    margin-top: 10px;
  }
  .mt-20 {
    margin-top: 20px;
  }

  .app-row-none-border {
    background-color: white;
    padding: 10px 10px 0 10px;
  }
  .font{
    font: 17px PingFang-SC-Medium;
    color: #666666
  }
  .show-font{
    font: 17px PingFang-SC-Medium;
    color: #333333
  }
  .btn-font{
    font:600 16px PingFang-SC-Bold;
    color: #499EDF;
  }
  .head{
    font-size: 1.25em;
    font-weight: bolder;
    padding: 0.5em;
  }
  .btn-color{
    background-color: #FFFFFF;
    border-radius: 10px ;
    border: 1px solid #499EDF;
  }
</style>
