<template>
  <div class="auto">
    <validator name='v'>
      <form novalidate class="form-horizontal">
        <p class="bg-info text-center" style="padding: 8px;">物联网表补费扣费</p>
        <div  class="row">
          <div class="col-sm-4">
            <label class="font_normal_body">&nbsp;操作&nbsp;</label>
            <input v-show="false" v-model="model.f_operat_type"
                   v-validate:f_operat_type='{required: true}'>
            <v-select v-if="this.data.f_collection_type==='按金额'" :value.sync="model.f_operat_type"
                      :options='operator_type' placeholder='请选择'
                      selected="补费"
                      style="width:60%"
                      close-on-select></v-select>
            <v-select v-if="this.data.f_collection_type==='按气量'" :value.sync="model.f_operat_type"
                      :options='operator_type2' placeholder='请选择'
                      selected="补气"
                      style="width:60%"
                      close-on-select></v-select>
          </div>
          <div class="col-sm-4"></div>

          <div v-if="this.data.f_collection_type==='按金额'" class="col-sm-4"
               :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,  dctest: [0, ">" ]}' placeholder="金额">
          </div>
          <div v-if="this.data.f_collection_type==='按气量'" class="col-sm-4"
               :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,  dctest: [0, ">" ]}' 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" @click="confirm()" :disabled='!$v.valid'>确认</button>
        <button class="btn button_clear" @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>
</template>


<script>



  import Vue from "vue";

  export default {
    title: '物联网表补费扣费',
    data () {
      return {
        operator_type:[{label:'补费',value:'补费'},{label:'扣费',value:'扣费'}],
        operator_type2:[{label:'补气',value:'补气'},{label:'扣气',value:'扣气'}],
        model: {
          f_operat_type: '',
          f_pregas:0,
          f_preamount:0,

          f_comments: ''
        }

      }
    },
    props: ['data'],
    ready () {
      if(this.data.f_collection_type==='按气量'){
        this.model.f_operat_type=['补气']
      }else{
        this.model.f_operat_type=['补费']
      }

    },
    methods: {
      async confirm () {

        let param = {
          fillgas:{
            f_userinfo_id: this.data.f_userinfo_id,
            f_user_id: this.data.f_user_id,
            f_userfiles_id: this.data.f_userfiles_id,
            f_user_name: this.data.f_user_name,
            f_user_type:this.data.f_user_type,
            f_gasproperties:this.data.f_gasproperties,
            f_meter_type:this.data.f_meter_type,
            f_pregas:this.model.f_pregas,
            f_address:this.data.f_address,
            f_meter_brand:this.data.f_meter_brand,
            f_preamount:this.model.f_preamount,
            f_type: this.model.f_operat_type[0],
            // f_preamount_state: '有效',
            f_comments: this.model.f_comments,
            f_billing: this.data.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_card_id: this.data.f_card_id,
            f_balance:this.data.f_balance_amount,
            f_operat_type: this.model.f_operat_type[0],
            f_describe: `${this.$login.f.name}对用户${this.data.f_user_name}进行${this.model.f_operat_type}操作`,
            f_state: '有效'
            // f_table_state:'有效'
          }
        }
      console.log(param)
      this.$resetpost('rs/logic/feededuction', {data: param}, {warnMsg: `确定要对用户${this.data.f_user_name}进行${this.model.f_operat_type}吗？`, resolveMsg: `${this.model.f_operat_type}成功！！`, rejectMsg: `${this.model.f_operat_type}失败！！请重试！！`}).then((res) => {
        this.clean()
  })

      },
      clean () {
        this.$dispatch('refresh')
      }
      // printok () {
      //   this.$dispatch('success')
      // },
      // validateBill (val) {
      //   this.validateOk = !val.isOk
      //   this.billData.bill = val.bill
      // }
    }
  }
</script>
