<template>
  <div class="auto">
    <validator name='v'>
      <form novalidate class="form-horizontal">
        <div  class="row">
          <div  class="col-sm-4 form-group"
                :class="[$v.f_pregas.required || $v.f_pregas.dctest ? 'has-error' : 'has-success']">
            <label class="font_normal_body">&nbsp;气量&nbsp;</label>
            <input class="input_search" type="number" v-model="model.f_pregas" style="width:60%"
                   v-validate:f_pregas='{required: true}' placeholder="气量">
          </div>
          <div  class="col-sm-4 form-group"
                :class="[$v.f_price.required || $v.f_price.dctest ? 'has-error' : 'has-success']">
            <label class="font_normal_body">&nbsp;单价&nbsp;</label>
            <input class="input_search" type="number" v-model="model.f_price" style="width:60%"
                   v-validate:f_price='{required: true,  dctest: [0, ">" ]}' placeholder="单价">
          </div>
          <div  class="col-sm-4 form-group"
               :class="[$v.f_preamount.required || $v.f_preamount.dctest ? 'has-error' : 'has-success']">
            <label class="font_normal_body">&nbsp;金额&nbsp;</label>
            <input class="input_search" type="number" v-model="model.f_preamount" style="width:60%"
                   v-validate:f_preamount='{required: true}' placeholder="金额">
          </div>
        </div>

        <div class="row">
          <div class="col-sm-12">
            <label for="f_paper_account" class="font_normal_body ">&nbsp;备注&nbsp;</label>
            <input class="input_search" style="width:87%" rows="1" v-model="model.f_comments"></input>
          </div>
        </div>
      </form>
      <div style="text-align:right;">
        <button class="btn button_search btn-gn" @click="confirm()" :disabled='!$v.valid'>确认</button>
        <button class="btn button_clear btn-gn" @click="clean()">取消</button>
      </div>
    </validator>
    <!--<validate-bill v-if="hasValidateBill" :data="model" @validate-bill="validateBill"></validate-bill>-->
    <!--<print-bill :show="print" :bill-manager='config.hasBillManage' v-ref:printbill :bill-url='billUrl' v-on:toggle="clean" @printok="printok" :data='printModel'></print-bill>-->
    <!--<print-bill :show="print" :bill-config='config' :bill-data='billData' v-on:toggle="clean" @printok="printok" :data='printModel'  v-ref:printbill></print-bill>-->
  </div>
  <upload :blodid="row.f_userinfo_id"  v-ref:upload    :isremark="true" fusetype="价格补差"></upload>

</template>


<script>
  import Vue from 'vue'

export default {
    title: '价格补差',
    data () {
      return {
        blodid: '',
        showupload: false,
        model: {
          f_comments: ''
        }

      }
    },
    props: ['row'],
    ready () {

    },
    methods: {
      async confirm () {
        console.log('价格补差：', this.row)
        if((this.model.f_preamount>0 && this.model.f_pregas<0) || (this.model.f_preamount<0 && this.model.f_pregas>0)){
          this.$showAlert('输入气量与金额必须同为负数或正数，您的输入有误！','warning',3000)
          return
        }

        if((this.model.f_pregas*this.model.f_price).toFixed(2) !== (this.model.f_preamount - 0).toFixed(2)){
          this.$showAlert('输入气量乘单价不等于金额，请重新输入！','warning',3000)
          return
        }
        let param = {
          sellinggas: {
            f_userfiles_id: this.row.f_userfiles_id,
            f_userinfo_id: this.row.f_userinfo_id,
            f_user_id: this.row.f_user_id,
            f_user_name: this.row.f_user_name,
            f_user_type: this.row.f_user_type,
            f_gasproperties: this.row.f_gasproperties,
            f_meternumber: this.row.f_meternumber,
            f_card_id: this.row.f_card_id,
            f_payment: '现金缴费',
            f_price_id: this.row.f_price_id,
            f_last_tablebase: this.row.f_meter_base,
            f_tablebase: this.row.f_meter_base,
            f_meter_type: this.row.f_meter_type,
            f_collection_type: this.row.f_collection_type,
            f_pregas: this.model.f_pregas,
            f_address: this.row.f_address,
            f_meter_brand: this.row.f_meter_brand,
            f_preamount: this.model.f_preamount,
            f_charge_type: '价格补差',
            f_comments: this.model.f_comments,
            f_billing: this.row.f_billing,
            f_operator: Vue.$login.f.name,
            f_operatorid: Vue.$login.f.id,
            f_orgid: Vue.$login.f.orgid,
            f_orgname: Vue.$login.f.orgs,
            f_depid: Vue.$login.f.depids,
            f_depname: Vue.$login.f.deps,
            f_operat_type: '价格补差',
            f_stair_price1: this.model.f_price,
            f_describe: `${this.$login.f.name}对用户${this.row.f_user_name}进行价格补差操作`,
            f_state: '有效'
            // f_table_state:'有效'
          }
        }
        console.log(param)
        this.$resetpost('rs/logic/priceJustment', {data: param}, {warnMsg: `确定要对用户${this.row.f_user_name}进行价格补差吗？`, resolveMsg: `价格补差成功！！`, rejectMsg: `价格补差失败！！请重试！！`}).then((res) => {
          this.clean()
        })
      },
      clean () {
        this.$dispatch('refresh')
      }
    }
  }
</script>
