<template>
  <div class="flex-row">
    <div class="span" style="overflow-y: auto;">
      <validator name='v'>
        <form novalidate class="form-horizontal">
          <div class="row" v-if="model.f_fill_gas > 0 || model.f_fill_money > 0">
            <div class="col-sm-4 form-group" v-if="row.f_collection_type === '按气量'">
              <label for="f_pregas" class=" font_normal_body">应补气量</label>
              <input class="input_search" style="width:60%" type="number"
                     v-model="model.f_fill_gas"
                     placeholder="应补气量" disabled>
            </div>
            <div class="col-sm-4 form-group" v-if="row.f_collection_type === '按金额'">
              <label for="f_pregas" class=" font_normal_body">应补金额</label>
              <input class="input_search" style="width:60%" type="number"
                     v-model="model.f_fill_money"
                     placeholder="应补金额" disabled>
            </div>
          </div>
          <!--<div v-show="remanentfalg">-->
            <!--<strong style="font-size: large" >【补气提示】:{{remanentstr}}</strong><br/>-->
          <!--</div>-->
          <div class="row" style="margin-top:10px;">
            <div class="col-sm-4 form-group">
              <label for="f_paytype" class=" font_normal_body" title="参数名称：付款方式">收款方式</label>
              <v-select id="f_payment"
                        v-model="f_payment"
                        placeholder='请选择'
                        :value.sync="model.f_payment"
                        :options='paytype' clear-button></v-select>
            </div>

            <div class="col-sm-4 form-group"
                 v-if = "row.f_collection_type === '按气量'"
                 :class="[$v.f_pregas.required || $v.f_pregas.dctest? 'has-error' : 'has-success']">
              <label for="f_pregas" class=" font_normal_body">预购气量</label>
              <input class="input_search" style="width:60%" type="number"
                     @blur="pregasBuy()" v-model="model.f_pregasBuy"
                     v-validate:f_pregas='{required: true, dctest: [maxgas, "<=" ]}' placeholder="预购气量"
                     v-next-el='sk' :disabled="row.f_collection_type !== '按气量'">
            </div>

            <div class="col-sm-4 form-group"
                 :class="[$v.f_preamount.required || $v.f_preamount.dctest? 'has-error' : 'has-success']">
              <label for="f_preamount" class=" font_normal_body">预购金额</label>
              <input class="input_search" style="width:60%" type="number" v-model="model.f_preamount"
                     v-validate:f_preamount='{dctest: [maxmoney, "<=" ]}'
                     v-scale="[model.f_preamount, 4]" placeholder="预购金额" disabled>
            </div>
          </div>
          <div class="row" style="margin-top:6px;">
            <div class="col-sm-4 form-group">
              <!-- <print-style :print.sync='model.f_print'></print-style> -->
              <label for="f_print" class="font_normal_body">打印格式</label>
              <!--<input type="text" v-show="false" v-model="$refs.printstyle.selectedItems"-->
                     <!--v-validate:printstyle='{required: true }'>-->
              <v-select id="print"
                        v-model="f_print"
                        placeholder='请选择'
                        :multiple="mulPrint"
                        :value.sync="model.f_print"
                        :options='printstyle'
                        close-on-select clear-button v-ref:printstyle>
              </v-select>
            </div>
            <div class="col-sm-4 form-group" >
              <label for="f_pregas" class=" font_normal_body">写卡气量</label>
              <input class="input_search" style="width:60%" type="number"
                     v-model="model.f_pregas" placeholder="写卡气量" disabled>
            </div>
            <div class="col-sm-4 form-group"
                 :class="[$v.f_totalcost.required || $v.f_totalcost.dctest ? 'has-error' : 'has-success']">
              <label for="f_temp_amount" v-if="row.f_collection_type === '按气量'"
                     class=" font_normal_body">应收金额</label>
              <label for="f_temp_amount" v-if="row.f_collection_type === '按金额'"
                     class=" font_normal_body">本次缴费</label>
              <input class="input_search" style="width:60%" type="number"
                     @blur="preamount()" v-model="model.f_totalcost"
                     v-validate:f_totalcost='{required: true, dctest: [(openFee - 0), ">=" ] }' placeholder="应收金额"
                     v-next-el='sk' v-scale="[model.f_totalcost, 4]" :disabled="row.f_collection_type !== '按金额'">
            </div>
            <div class="col-sm-4 form-group" v-if="hasLimit&&limitgas">
              <label class="font_normal_body">购气上限</label>
              <input class="input_search" style="width:60%" style="width:60%" type="number" v-model="maxgas"
                     v-scale="[maxgas, 2]" placeholder='限购余气' disabled>
            </div>
            <div class="col-sm-4 form-group" v-if="hasLimit&&limitmoney">
              <label class="font_normal_body">金额上限</label>
              <input class="input_search" style="width:60%" style="width:60%" type="number" v-model="maxmoney"
                     v-scale="[maxmoney, 2]" placeholder='限购金额' disabled>
            </div>
            <!--<div class="col-sm-4 form-group" v-if="!hasLimit">-->
            <!--</div>-->
            <div class="row">
              <div class="col-sm-4 form-group">
                <label for="f_balance" class="font_normal_body">上期结余</label>
                <input class="input_search" style="width:60%" type="number" v-model="model.f_balance"
                       v-scale="[model.f_balance, 4]" placeholder="上期结余" disabled>
              </div>
              <div class="col-sm-4 form-group">
                <label for="f_curbalance" class="font_normal_body">本期结余</label>
                <input class="input_search" style="width:60%" type="number" v-model="curbalance"
                       v-scale="[model.f_curbalance, 4]" placeholder="本期结余" disabled>
              </div>

              <div class="col-sm-4 form-group" v-if="row.f_collection_type === '按气量'"
                   :class="[$v.f_collection.required || $v.f_collection.dctest ? 'has-error' : 'has-success']">
                <label for="f_collection" class=" font_normal_body"><font size="4px" style="font-weight:bold">*收&nbsp;&nbsp;款</font></label>
                <input class="input_search" style="width:60%;font-size: 18px;font-weight:bold;" type="number" v-model="model.f_collection"
                       v-validate:f_collection='{required: true, dctest: [(model.f_totalcost - 0) + (openFee - 0), ">=" ] }'
                       v-el:sk v-scale="[model.f_collection, 4]">
              </div>
              <div class="col-sm-4 form-group" v-if="row.f_collection_type === '按金额'">
                <label for="f_collection" class=" font_normal_body"><font size="4px" style="font-weight:bold">*收&nbsp;&nbsp;款</font></label>
                <input class="input_search" style="width:60%;font-size: 18px;font-weight:bold;" type="number" v-model="model.f_collection"
                       v-el:sk v-scale="[model.f_collection, 4]" :disabled='true'>
              </div>
            </div>
            <!--<div class="row" v-if="openFee > 0">-->
              <!--<div class="col-sm-4 form-group">-->
                <!--<label class="font_normal_body">&nbsp;&nbsp;&nbsp;开卡费</label>-->
                <!--<input class="input_search" style="width:60%" style="width:60%" type="number" v-model="openFee" placeholder='开卡费' disabled>-->
              <!--</div>-->
            <!--</div>-->
            <div class="row" style="margin-top:5px;">
              <div class="col-sm-9">
              </div>
              <div class="col-sm-3">
                <span v-if="$v.f_collection.dctest" style="color:red ">收款不能小于应收金额</span>
              </div>
            </div>
            <div class="row" v-if="model.f_payment[0].includes('POS')">
              <div class="col-sm-4 form-group">
                <label for="f_voucher_number" class="font_normal_body">&nbsp;&nbsp;&nbsp;凭证号</label>
                <input type="text" class="input_search" style="width:60%" v-model="model.f_voucher_number" placeholder="凭证号">
              </div>
            </div>

            <div class="row">
              <div class="col-sm-12">
                <label for="f_comments" class="font_normal_body">&nbsp;&nbsp;&nbsp;备注&nbsp;&nbsp;&nbsp;</label>
                <input type="text" class="input_search" style="width:87%" v-model="model.f_comments" placeholder="备注"/>
              </div>
            </div>
            <div v-if="paymentModel.length >1">
              <div class="row" style="margin-top:10px;" >
                <p class="col-sm-2 text-left" style="padding: 10px;"><img src="../../../../static/juxing.png"/><strong style="margin-left: 4%">付款明细</strong></p>
              </div>
              <div class="row" style="margin-top:10px;" >
                <div class="col-sm-4 form-group " v-for="pay in paymentModel" >
                  <label class="font_normal_body">{{pay.f_payment}}:</label>
                  <input id="f_money" type="text" class="input_search" style="width:60%" v-model="pay.f_money">
                </div>
                <div class="col-sm-4 form-group ">
                  <strong v-if="!islegal" style="color: red">所输入的金额必须等于收款金额</strong>
                </div>
              </div>
            </div>
          </div>
        </form>
        <validate-bill v-if="hasValidateBill" :data="model" @validate-bill="validateBill"></validate-bill>
        <print-bill :show="print" :bill-config='config' :bill-data='billData' v-on:toggle="close"
                    :data='row' @printok="printok" v-ref:printbill></print-bill>
        <div style="text-align:right; height: 25%;">
          <strong style="font-size: large" v-if="!config.notShowFormula">计算公式:{{calculatedetail ? calculatedetail : ' 暂无'}}</strong><br/>
          <payment-code-button :clickable="!$v.valid || validateOk || !islegal || clickConfirm"
                               :payment.sync="model.f_payment" :payment-data="paytype"
                               @confirm-payment="confirm()">
          </payment-code-button>
          <button class="button_search btn-gn" v-if="row.f_meter_type == '气量卡表' ? (model.f_pregas - 0) <= (model.f_fill_gas - 0) : (model.f_totalcost - 0) <= (model.f_fill_money - 0)" @click="confirm()" :disabled='!$v.valid || validateOk || !islegal || clickConfirm'>补气</button>
          <button class="button_search btn-gn" v-if="row.f_meter_type == '气量卡表' ? (model.f_pregas - 0) > (model.f_fill_gas - 0) : (model.f_totalcost - 0) > (model.f_fill_money - 0)" style="min-width: max-content;" @click="confirm()" :disabled='!$v.valid || validateOk || !islegal || clickConfirm'>补气并购气</button>
          <button class="button_clear btn-gn" @click="clean()" >取消</button>
        </div>
      </validator>
    </div>

    <payment-code v-ref:paymentcode :payment="model.f_payment" :row="row" :money="model.f_collection"></payment-code>
  </div>
  <upload :blodid="blodid" v-if="config.showupload" :businessid="randomBusinessId" isremark="true" fusetype="补气购气"></upload>
</template>
<script>
  /**
   *综合业务
   *发卡售气组件
   */

  import {HttpResetClass} from 'vue-client'
  import XML from '../../../plugins/ObjTree'

  let preamountGen = async function (self) {
    let calFee = (self.model.f_totalcost - 0) + (self.model.f_fill_money - 0)
    let getAmount = null
    if (((self.model.f_fill_money - 0)) < (calFee)) {
      let fee = calFee - (self.model.f_fill_money - 0)
      getAmount = await self.$CommonService.feeCalculate(self.model, fee)
      if (getAmount.data.gas) {
        if (self.row.f_isdecimal === '是') {
          if (self.row.f_alias === 'QiaoSong') {
            self.model.f_pregas = (getAmount.data.gas - 0).toFixed(1)
          } else {
            self.model.f_pregas = (getAmount.data.gas - 0).toFixed(4)
          }
        } else {
          self.model.f_pregas = parseInt(getAmount.data.gas - 0)
        }
      }
      self.model.f_preamount = calFee
      self.model.chargeprice = getAmount.data.chargeprice
      Object.assign(self.model, self.model, getAmount.data)
      self.model.f_collection = self.model.f_totalcost

      if(self.config.floor){
        self.model.f_collection=Math.ceil(self.model.f_collection)
      }
      self.calText(getAmount.data.chargeprice)
    } else {
      self.model.f_pregas = 0
      self.model.f_totalcost = 0
      self.model.f_collection = 0
    }
    self.remstrgas()
  }

  let pregasGen = async function (self) {
    if (self.row.f_isdecimal === '是') {
      self.model.f_pregas = (self.model.f_pregas - 0).toFixed(4)
    } else {
      self.model.f_pregas = (self.model.f_pregas - 0).toFixed(0)
    }
    self.model.f_meter_type = self.row.f_meter_type
    // 判断限购
    if ((self.model.f_pregas - 0) - (self.maxgas - 0) <= 0) {
      if ((self.model.f_fill_gas - 0) < (self.model.f_pregas - 0)) {
        // 超出【补气气量不符】部分走划价
        let gas = self.model.f_pregas - self.model.f_fill_gas
        let getAmount = await self.$CommonService.gasCalculate(self.model, gas)
        console.log('划价返回', getAmount, self.openFee, self.row.f_balance)
        self.model.f_preamount = getAmount.data.chargenum
        // 计算气费和其他费用(暂时只有开卡费，之后有其他费在加)
        let total = (getAmount.data.chargenum - 0) + (self.openFee - 0)
        self.model.f_totalcost = (self.row.f_balance - 0) > (total - 0) ? 0 : ((total - 0) - (self.row.f_balance - 0)).toFixed(4)
        Object.assign(self.model, self.model, getAmount.data)
        self.model.chargeprice = getAmount.data.chargeprice
        self.model.f_collection = self.model.f_totalcost
        self.calText(getAmount.data.chargeprice)
      } else {
        // 否则不走划价
        self.model.f_preamount = 0
        self.model.f_totalcost = 0
        self.model.f_collection = 0
      }
      self.remstrgas()
    }
  }

  // 写卡操作
  let initCardGen = async function (self) {
    try {
      if (self.paymentModel.length === 0) {
        self.paymentModel = [{
          f_payment: self.model.f_payment[0],
          f_money: self.model.f_preamount
        }]
      }
      self.model.payments = self.paymentModel
      // 加入扫码盒付款码支付流水号
      self.model.f_serial_id = self.$refs.paymentcode.paymentCodeReturnData.f_out_trade_no
      let res = await self.$CardService.remanentinitCard(self.model, self.row, self.cardallot)
      console.log('换表发卡数据返回', res.data.sellid, res.data.fillgasid, res, self.model)
      if (self.config.showupload) {
        let param = []
        for (let row of self.resid) {
          param.push({id: row.id})
        }
        let data1 = {
          param: param,
          f_blobid: res.data.sellid
        }
        console.log('-------------------------->', data1)
        await self.$resetpost('rs/logic/updatefiles', data1)
      }
      // 开始打票
      if (self.config.hasPrint) {
        if (self.model.f_print.indexOf('电子发票') == -1) {
          if (self.config.hasBillManage) {
            // 启用发票管理，获取票据管理中的票号并存储记录
            console.log('进入票据之前。。', res.data.sellid)
            if (res.data.sellid) self.row.id = res.data.sellid
            if (res.data.fillgasid) self.row.fillgasid = res.data.fillgasid
            self.row.f_bill_type = '卡表收费'
            self.row.f_bill_style = self.model.f_print[0]
            self.print = true
          } else {
            self.row.id = res.data.sellid
            self.row.fillgasid = res.data.fillgasid
            self.print = true
          }
        } else {
          if (self.model.f_print[0] === '电子发票') {
            self.$CommonService.openEticket(res.data.id, '售气收费')
            self.$dispatch('success')
          }
        }
      } else {
        self.$showAlert('补气购气成功', 'success', 2000)
        self.$dispatch('success')
      }
      self.clickConfirm = false
    } catch (error) {
      console.log('抛出的错误。。', error)
      self.$showAlert(error, 'danger', 0)
      self.$dispatch('refresh')
      self.clickConfirm = false
    }
  }

  let asyncShowCardSellGas = async function (self) {
    await self.$getConfig(self, 'CardChangeFill')
    console.log('换表发卡config', self.config)
    self.model.f_print = self.config.printType instanceof Array ? self.config.printType : [self.config.printType]
    self.model.f_payment = [self.config.payment]
    self.mulPrint = self.config.printType instanceof Array

    self.model.f_use_type = self.config.billType
    self.model.f_bill_type = self.model.f_print
    self.hasValidateBill = self.config.hasBillManage

    // 判断限购
    // 获取限购值
    let limit_param = {
      f_userinfo_id: self.row.f_userinfo_id,
      f_user_id: self.row.f_user_id,
      f_stairprice_id: self.row.f_stairprice_id
    }
    let http = new HttpResetClass()
    let getLimit = await http.load('POST', 'rs/logic/sale_getLimitGas', {data: limit_param}, {resolveMsg: null, rejectMsg: '获取限购值失败！！'})
    console.log('获取限购值', getLimit)
    self.hasLimit = getLimit.data.hasLimit
    if (self.hasLimit) {
      if (getLimit.data.f_limit_value || getLimit.data.f_limit_amount) {
        if (getLimit.data.f_limit_value < 0 || getLimit.data.f_limit_amount < 0) {
          self.$showAlert(`${getLimit.data.msg}`, 'warning', 3000)
          self.$dispatch('refresh')
        } else {
          if (getLimit.data.f_limit_value) {
            self.maxgas = (getLimit.data.f_limit_value - 0)
            self.limitgas = true
          }
          if (getLimit.data.f_limit_amount) {
            self.maxmoney = (getLimit.data.f_limit_amount - 0)
            self.limitmoney = true
          }
        }
      }
    }
  }

  export default {
    title: '换表补气',
    data () {
      return {
        config: {
          notShowFormula: false, // 不显示计算公式,默认显示
          hasPrint: false,  // 默认打票
          hasBillManage: false,  // 默认不启用发票管理
          billType: '燃气费',   // 票据类型（燃气费，其他费用，调用的发票代码不同）
          printType: '普通收据', // 收据/电子票/专用发票/国税发票
          payment: '现金缴费',
          showupload: false, // 默认不显示上传附件
          floor: false
        },
        model: {
          // 真实补气量
          f_fill_gas: 0,
          f_fill_money: 0,
          f_stairprice_id: '',
          f_payment: '现金缴费',
          f_pregas: '',
          f_preamount: 0,
          f_totalcost: 0,
          f_balance: 0,
          f_curbalance: 0,
          f_collection: '',
          chargeprice: [],
          f_print: [],
          f_meter_type: '',
          f_voucher_number: ''
        },
        cardallot: null,
        calculatedetail: '',
        blodid: '',
        billData: {
          url: 'rs/report/card_gas_bill',
          bill: ''
        },
        randomBusinessId: '',
        resid: [],  // 存放新增的f_files表中id
        print: false,

        // 是否有限购
        hasLimit: false,
        // 补气提示开关
        remanentfalg: false,
        // 补气提示
        remanentstr: '',
        // 启用发票管理需要对票号进行验证
        hasValidateBill: false,
        validateOk: false,

        maxgas: 99999999,
        maxmoney: 99999999,
        limitmoney: false,
        limitgas: false,

        clickConfirm: false,

        mulPrint: false, // 控制打印格式是否可以多选
        openFee: 0, // 是否有开卡费
        paymentModel: [], // 多笔付款方式
        paytype: this.$appdata.getParam('付款方式') ? this.$appdata.getParam('付款方式') : [],
        printstyle: this.$appdata.getParam('打印格式') ? this.$appdata.getParam('打印格式') : []
      }
    },

    props: ['row'],
    async ready () {
      this.blodid = this.row.f_userinfo_id
      this.model.f_price_id = this.row.f_price_id
      this.model.f_user_id = this.row.f_user_id
      this.model.f_userfiles_id = this.row.f_userfiles_id
      this.model.f_userinfo_id = this.row.f_userinfo_id
      // 补气信息
      this.model.f_balance = this.row.f_balance

      let getResult = this.$CommonService.calRemanentMoney(this.row)
      if (this.row.f_collection_type === '按气量') {
        if (getResult > 0) {
          this.model.f_pregas = this.model.f_fill_gas = getResult - 0
          this.model.f_preamount = 0
        } else {
          this.model.f_pregas = ''
        }
      } else {
        this.model.f_fill_money = getResult
        this.model.f_preamount = (this.model.f_fill_money - 0) + (this.row.f_balance - 0)
        if (this.row.f_meter_type.includes('金额')) {
          this.model.f_pregas = 0
          this.model.f_totalcost = 0
        }
        await preamountGen(this)
      }

      this.model.f_collection = 0
      this.getRandomId()
      await asyncShowCardSellGas(this)
    },
    watch: {
      'row' (val) {
        this.model.f_balance = val.f_balance
      },
      'model.f_payment.length' (val) {
        console.log('付款方式多选。。', val)
        if (val > 3) {
          this.$showAlert('目前只支持三种支付方式', 'warning', 2000)
          return
        }
        if (val > 1 && !this.model.f_preamount) {
          this.model.f_payment = ['现金缴费']
          this.$showAlert('请先计算付款金额', 'warning', 2000)
        } else {
          this.paymentModel = []
          this.model.f_payment.forEach((res) => {
            let temp = {
              f_payment: res,
              f_money: 0
            }
            this.paymentModel.push(temp)
          })
          this.$resetValidation()
        }
      }
    },
    events: {
      // 删除Resid数组元素
      'delResid' (val) {
        this.resid.$remove({id: val, f_biobid: ''})
        // this.resid.splice(this.resid.indexOf({id:val,f_biobid:''}),1);
      },
      // 增加Resid数组元素
      'resid' (val) {
        this.resid.push({id: val, f_biobid: ''})
      }
    },
    methods: {
      getRandomId () {
        this.randomBusinessId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
          let res = Math.random() * 16 | 0
          let v = c == 'x' ? res : (res & 0x3 | 0x8)
          return v.toString(16)
        })
      },
      confirm () {
        this.$dispatch('no-button')
        this.clickConfirm = true
        // 用于获取卡号
        console.log('开始换表发卡。。', this.model, this.row)
        this.$showMessage(`对客户${this.row.f_user_name}进行补气购气操作。请确保你已经插入了${this.row.f_meter_brand}的卡？`, ['confirm', 'cancel']).then(async (res) => {
          if (res === 'confirm') {
            // 先调用付款码支付组件流程
            let ss = await this.$refs.paymentcode.flowPath()
            this.$refs.paymentcode.paymentCodeShow = false
            console.log('付款码操作返回', ss)
            if (!ss.result) return

            initCardGen(this)
          } else {
            this.clickConfirm = false
          }
        })
      },
      clean () {
        this.$info('取消操作')
        this.$dispatch('refresh', this.row)
      },
      pregasBuy () {
        if (this.model.f_pregasBuy < 0) {
          this.model.f_pregasBuy = 0
          return
        }
        this.model.f_pregas = (this.model.f_fill_gas - 0 + (this.model.f_pregasBuy - 0)).toFixed(4) - 0
        this.pregas()
      },
      pregas () {
        if (this.model.f_pregas >= 0) {
          try {
            pregasGen(this)
          } catch (error) {
            this.$showAlert(`发卡售气划价错误，错误类型：${error}`, 'danger', 0)
            this.$dispatch('error', '发卡售气', this.model, error)
          }
        } else {
          this.model.f_pregas = null
        }
      },
      preamount () {
        if (this.model.f_totalcost && this.model.f_totalcost >= 0) {
          try {
            preamountGen(this)
          } catch (error) {
            this.$showAlert(`发卡售气划价错误，错误类型：${error}`, 'danger', 0)
            this.$dispatch('error', '发卡售气', this.model, error)
          }
        } else {
          this.model.f_totalcost = null
        }
      },

      validateBill (val) {
        this.validateOk = !val.isOk
        this.billData.bill = val.bill
      },
      printok () {
        // 收据打完，判断是否还有其他票据进行请求
        for (let i = 0; i < this.model.f_print.length; i++) {
          if (this.model.f_print[i] === '电子发票') {
            this.$CommonService.openEticket(this.row.id, '售气收费')
          }
        }
        this.$dispatch('success')
      },
      remstrgas () {
        if (this.row.f_collection_type == '按气量') {
          if ((this.model.f_fill_gas - 0) > (this.model.f_pregas - 0) && this.model.f_pregas > 0) {
            this.remanentstr = '您已经成功抵扣' + this.model.f_pregas + '补气量！！，该气量不会产生任何费用'
            this.remanentfalg = true
          } else if ((this.model.f_fill_gas - 0) < (this.model.f_pregas - 0) && this.model.f_fill_gas > 0) {
            this.remanentstr = '您已经成功抵扣' + this.model.f_fill_gas + '补气量！！！，该气量不会产生任何费用,并且超出购买' + (this.model.f_pregas - this.model.f_fill_gas) +
            '方气量，超出部分产生费用!'
            this.remanentfalg = true
          } else {
            this.remanentfalg = false
            this.remanentstr = ''
          }
        } else {
          if ((this.model.f_fill_money - 0) > (this.model.f_preamount - 0) && this.model.f_preamount > 0) {
            this.remanentstr = '您已经成功抵扣' + this.model.f_preamount + '元！！！，本次不收取费用！！'
            this.remanentfalg = true
          } else if ((this.model.f_fill_money - 0) < (this.model.f_preamount - 0) && this.model.f_fill_money > 0) {
            this.remanentstr = '您已经成功抵扣' + this.model.f_fill_money + '元！！！，本次将收取' + ((this.model.f_preamount - 0) - (this.model.f_fill_money - 0) - (this.row.f_balance - 0)).toFixed(4) + '元！！！'
            this.remanentfalg = true
          } else {
            this.remanentfalg = false
            this.remanentstr = ''
          }
        }
      },
      calText (val) {
        let str = ''
        val.forEach((item) => {
          str = str + item.f_price + ' x ' + item.f_gas + '+'
        })
        str = str.slice(0, str.length - 1)
        this.calculatedetail = str
      },
      close () {
        this.showprint = false
        this.print = false
        this.clean()
      }
    },
    computed: {
      'curbalance' () {
        console.log('查看model', this.model.f_preamount)
        if (this.model.f_preamount >= 0) {
          if (this.row.f_collection_type === '按金额') {
            return ((this.model.f_totalcost - 0) + (this.row.f_balance - 0) + (this.model.f_fill_money - 0) - (this.model.f_preamount - 0)).toFixed(4)
          } else {
            if ((this.row.f_balance - 0) > (this.model.f_preamount - 0)) {
              return ((this.row.f_balance - 0) - (this.model.f_preamount - 0)).toFixed(4)
            } else {
              return ((this.model.f_collection - 0) - (this.model.f_totalcost - 0)).toFixed(4)
            }
          }
        } else {
          console.log('走0了？')
          return 0
        }
      },
      'islegal' () {
        if (this.paymentModel.length > 1 && this.model.f_collection) {
          let sum = 0
          this.paymentModel.forEach((res) => {
            sum += (res.f_money - 0)
          })

          return (this.model.f_collection - 0) === (sum - 0)
        } else {
          return true
        }
      }
    }
  }
</script>

<style>
</style>
