<template>
  <div>
    <el-form ref="form_obj" :model="finance" class="formaddcopy02">
      <el-row style="border-top: 1px solid #E0E3EB">
        <el-col :span="6">
          <div class="span-sty">是否打包</div>
          <el-form-item>
            <el-radio-group style="font-size: 1px" class="addinputw" @input="isPackChange" v-model="finance.isPack">
              <el-radio label="1">是</el-radio>
              <el-radio label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="18">
          <div class="span-sty">产品政策</div>
          <el-form-item>
            <el-select v-model="finance.policyName" placeholder="请选择" @change="changePolicy" clearable class="addinputInfo">
              <el-option v-for="item in policy_list" :key="item.sid" :label="item.name" :value="item.name"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="span-sty">融资项目</div>
          <el-form-item prop="mainVehicleAmount">
            <div class="addinputInfo">
              <span><span class="icon">*</span>主车发票价<el-input v-model="finance.mainVehicleAmount" @input="financingProject" clearable style="width: 100px" placeholder="" @keyup.native="finance.mainVehicleAmount = oninput(finance.mainVehicleAmount, 0)"/>元</span>
              <span style="padding-left: 5px"><el-checkbox v-model="finance.accessoriesAmountCb" style="padding-right: 5px"/>配件<el-input v-model="finance.accessoriesAmount" @input="financingProject" clearable style="width: 100px" placeholder="" @keyup.native="finance.accessoriesAmount = oninput(finance.accessoriesAmount, 0)"/>元</span>
              <span style="padding-left: 5px"><el-checkbox v-model="finance.trailerAmountCb" style="padding-right: 5px"/>挂车<el-input v-model="finance.trailerAmount" @input="financingProject" clearable style="width: 100px" placeholder="" @keyup.native="finance.trailerAmount = oninput(finance.trailerAmount, 0)"/>元</span>
              <span style="padding-left: 5px"><el-checkbox v-model="finance.premiumCb" :disabled="finance.isPack == '0'" style="padding-right: 5px"/>保险<el-input v-model="finance.premium" @input="financingProject" clearable style="width: 100px" placeholder="" @keyup.native="finance.premium = oninput(finance.premium, 0)"/>元</span>
              <span style="padding-left: 5px"><el-checkbox v-model="finance.purchaseTaxCb" :disabled="finance.isPack == '0'" style="padding-right: 5px"/>购置税<el-input v-model="finance.purchaseTax" @input="financingProject" clearable style="width: 100px" placeholder="" @keyup.native="finance.purchaseTax = oninput(finance.purchaseTax, 0)"/>元</span>
            </div>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <div class="span-sty">融资项目总额</div>
          <el-form-item>
            <span class="addinputInfo">{{ finance.loanTotal }}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <div class="span-sty">首付比例(%)</div>
          <el-form-item><span class="addinputInfo">{{ finance.downPayRatio }}</span></el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty"><span class="icon">*</span>首付金额</div>
          <el-form-item prop="downPayAmount">
            <el-input class="addinputw addinputInfo" v-model="finance.downPayAmount" @input="downPayAmountInput" placeholder="" clearable @keyup.native="finance.downPayAmount = oninput(finance.downPayAmount, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">产品贷款金额</div>
          <el-form-item>
            <span class="addinputInfo">{{ finance.loanAmount }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">产品期数</div>
          <el-form-item prop="loanPeriod">
            <span class="addinputInfo">{{ finance.loanPeriod }}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <div class="span-sty">贷款保证金比例(%)</div>
          <el-form-item>
            <span class="addinputInfo">{{ finance.bondRatio }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty"><span class="icon">*</span>贷款保证金</div>
          <el-form-item prop="bondAmount">
            <el-input class="addinputw" v-model="finance.bondAmount" placeholder="" @input="bondAmountInput" clearable @keyup.native="finance.bondAmount = oninput(finance.bondAmount, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty"><span class="icon">*</span>厂家贴息</div>
          <el-form-item prop="factoryDiscount">
            <el-input class="addinputw" v-model="finance.factoryDiscount" placeholder="" @input="factoryDiscountInput" clearable @keyup.native="finance.factoryDiscount = oninput(finance.factoryDiscount, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">贴息用途</div>
          <el-form-item>
            <el-select v-model="finance.factoryDiscountUse" placeholder="请选择" @change="changeFactoryDiscountUse" clearable class="addinputInfo">
              <el-option v-for="item in factoryDiscountUse_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictValue"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <div class="span-sty">年利率(%)</div>
          <el-form-item>
            <span class="addinputInfo">{{ finance.policyYearRatio }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">月还金额</div>
          <el-form-item>
            <span class="addinputInfo">{{ finance.loanPayMoney }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">利息总额</div>
          <el-form-item>
            <span class="addinputInfo">{{ finance.loanInterest }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">贴息抵车款</div>
          <el-form-item>
            <span class="addinputInfo">{{ finance.discountCar }}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="title">
        <el-checkbox v-model="finance.otherPolicyState" style="padding-right: 5px"/>
        其它融
      </div>
      <div v-if="finance.otherPolicyState">
        <el-row>
          <el-col :span="12">
            <div class="span-sty">其它融名称</div>
            <el-form-item>
              <el-select v-model="finance.otherPolicyName" placeholder="请选择" @change="changeOtherPolicy" clearable class="addinputInfo">
                <el-option v-for="item in other_list" :key="item.sid" :label="item.name" :value="item.name"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span class="icon">*</span>贷款金额</div>
            <el-form-item prop="otherPolicyAmount">
              <el-input class="addinputw" v-model="finance.otherPolicyAmount" placeholder="" @input="otherPolicyAmountInput" clearable @keyup.native="finance.otherPolicyAmount = oninput(finance.otherPolicyAmount, 0)"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty">期数</div>
            <el-form-item>
              <span class="addinputInfo">{{ finance.otherPolicyPeriod }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <div class="span-sty">年利率(%)</div>
            <el-form-item>
              <span class="addinputInfo">{{ finance.otherPolicyYearRatio }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty">月还金额</div>
            <el-form-item>
              <span class="addinputInfo">{{ finance.otherPolicyMonthlyRepay }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <div class="span-sty">利息总额</div>
            <el-form-item>
              <span class="addinputInfo">{{ finance.otherPolicyInterest }}</span>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <div class="title">方案汇总</div>
      <el-row>
        <el-col :span="6">
          <div class="span-sty">融资首付</div>
          <el-form-item>
            <span class="addinputInfo">{{ loanDownPay() }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">实际首付比例(%)</div>
          <el-form-item>
            <span class="addinputInfo">{{ downPayAmountsRatio() }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">总贷款金额</div>
          <el-form-item>
            <span class="addinputInfo">{{ loanAmountTotal() }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">期数</div>
          <el-form-item>
            <span class="addinputInfo">{{ period() }}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <div class="span-sty">月还金额</div>
          <el-form-item><span class="addinputInfo">{{ monthlyRepay() }}</span></el-form-item>
        </el-col>
        <el-col :span="12">
          <div class="span-sty">利息总额</div>
          <el-form-item>
            <span class="addinputInfo">{{ interest() }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty"><span class="icon">*</span>预计首款还款日</div>
          <el-form-item prop="returnTime">
            <el-date-picker value-format="yyyy-MM-dd" v-model="finance.returnTime" clearable class="addinputw" type="date" placeholder=""/>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="title">应收明细</div>
      <el-row>
        <el-col :span="6">
          <div class="span-sty">融资首付</div>
          <el-form-item>
            <span class="addinputInfo">{{ downPayAmounts() }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">贷款保证金</div>
          <el-form-item><span class="addinputInfo">{{ bondAmounts() }}</span></el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">保险保证金</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.depositPremium" placeholder="" clearable @keyup.native="finance.depositPremium = oninput(finance.depositPremium, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">落户保证金</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.depositSettle" placeholder="" clearable @keyup.native="finance.depositSettle = oninput(finance.depositSettle, 0)"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <div class="span-sty"><span class="icon">*</span>服务费</div>
          <el-form-item prop="serviceAmount">
            <el-input class="addinputw" v-model="finance.serviceAmount" placeholder="" clearable @keyup.native="finance.serviceAmount = oninput(finance.serviceAmount, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">代收意外险</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.proxyAccidentPremium" placeholder="" clearable @keyup.native="finance.proxyAccidentPremium = oninput(finance.proxyAccidentPremium, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">上牌费</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.registerAmount" placeholder="" clearable @keyup.native="finance.registerAmount = oninput(finance.registerAmount, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">运管费</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.operationAmount" placeholder="" clearable @keyup.native="finance.operationAmount = oninput(finance.operationAmount, 0)"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <div class="span-sty">补车价</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.vehOtherPrice" placeholder="" clearable @keyup.native="finance.vehOtherPrice = oninput(finance.vehOtherPrice, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <div class="span-sty">其它费用</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.otherAmount" placeholder="" clearable @keyup.native="finance.otherAmount = oninput(finance.otherAmount, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <div class="span-sty">其它费用说明</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.otherAmountRemark" placeholder="" clearable/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="span-sty">办理方式选择</div>
          <el-form-item>
            <el-select v-model="finance.dealWay" placeholder="请选择" @change="changeDealWay" clearable class="addinputInfo">
              <el-option v-for="item in dealWay_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictValue"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="finance.dealWayKey == '01' && finance.isPack == '0' ">
        <el-col :span="6">
          <div class="span-sty">代收费用合计</div>
          <el-form-item>
            <span class="addinputInfo">{{ proxyTotal() }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <div class="span-sty">代收首年保险费</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.proxyPremium" placeholder="" clearable @keyup.native="finance.proxyPremium = oninput(finance.proxyPremium, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <div class="span-sty">代收购置税</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.proxyPurchasetax" placeholder="" clearable @keyup.native="finance.proxyPurchasetax = oninput(finance.proxyPurchasetax, 0)"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="span-sty">应收合计</div>
          <el-form-item>
            <span class="addinputInfo">{{ receivableTotal() }}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="finance.dealWayKey == '02' && finance.isPack == '1'">
        <el-col :span="6">
          <div class="span-sty">抵顶费用合计</div>
          <el-form-item>
            <span class="addinputInfo">{{ offsetTotal() }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <div class="span-sty">抵顶首年保险费</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.offsetPremium" placeholder="" clearable @keyup.native="finance.offsetPremium = oninput(finance.offsetPremium, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="9">
          <div class="span-sty">抵顶购置税</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.offsetPurchasetax" placeholder="" clearable @keyup.native="finance.offsetPurchasetax = oninput(finance.offsetPurchasetax, 0)"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="span-sty">实收合计</div>
          <el-form-item>
            <span class="addinputInfo">{{ realTotal() }}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="span-sty">车辆总价</div>
          <el-form-item>
            <span class="addinputInfo">{{ vehTotalPrice() }}</span>
<!--            <el-input class="addinputw" v-model="finance.vehTotalPrice" placeholder="" clearable @keyup.native="finance.vehTotalPrice = oninput(finance.vehTotalPrice, 0)"/>-->
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <div class="span-sty">名义(留购)价</div>
          <el-form-item>
            <el-input class="addinputw" v-model="finance.nominalPrice" placeholder="" clearable @keyup.native="finance.nominalPrice = oninput(finance.nominalPrice, 0)"/>
          </el-form-item>
        </el-col>
        <el-col :span="18">
          <el-form-item><span class="addinputInfo">注：结清时需缴纳此费用</span></el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { typeValues, selectList, selectListByOther } from '@/api/Common/dictcommons'

export default {
  name: 'JinRongFangAnEdit',
  props: {
    params: {
      type: Object
    }
  },
  data() {
    return {
      viewTitle: '',
      tableKey: 0,
      index: 0,
      dealWay_list: [],
      policy_list: [],
      other_list: [],
      factoryDiscountUse_list: [],
      finance: {},
      rules: {
        // mainVehicleAmount: [{ required: true, message: '主车发票价不能为空', trigger: 'blur' }],
        // downPayAmount: [{ required: true, message: '首付金额不能为空', trigger: 'blur' }],
        // loanPeriod: [{ required: true, message: '产品期数不能为空', trigger: 'blur' }],
        // bondAmount: [{ required: true, message: '贷款保证金不能为空', trigger: 'blur' }],
        // factoryDiscount: [{ required: true, message: '厂家贴息不能为空', trigger: 'blur' }],
        // loanPayMoney: [{ required: true, message: '月还金额不能为空', trigger: 'blur' }],
        // otherPolicyAmount: [{ required: true, message: '贷款金额不能为空', trigger: 'blur' }],
        // otherPolicyPeriod: [{ required: true, message: '期数不能为空', trigger: 'blur' }],
        // otherPolicyMonthlyRepay: [{ required: true, message: '月还金额不能为空', trigger: 'blur' }],
        // returnTime: [{ required: true, message: '预计首期还款日不能为空', trigger: 'blur' }],
        // serviceAmount: [{ required: true, message: '服务费不能为空', trigger: 'blur' }],
        // factoryDiscountUse: [{ required: true, message: '厂家贴息用途不能为空', trigger: 'blur' }]
      }
    }
  },
  watch: {
    params: {
      deep: true,
      immediate: false,
      handler(newVal, oldVal) {
        this.finance = newVal
      }
    }
  },
  created() {
    typeValues({ type: 'dealWay' }).then((resp) => {
      if (resp.success) {
        this.dealWay_list = resp.data
      }
    })
    typeValues({ type: 'factoryDiscountUse' }).then((resp) => {
      if (resp.success) {
        this.factoryDiscountUse_list = resp.data
      }
    })
  },
  methods: {
    // 输入数字正则
    oninput(val, limit = 0) {
      val = val.replace(/[^\d]/g, '') // 保留数字
      val = val.replace(/^00/, '0'); // 开头不能有两个0
      /^0\d+/.test(val) ? val = val.slice(1) : '' // 两位以上数字开头不能为0
      const str = '^(\\d+)\\.(\\d{' + limit + '}).*$'
      const reg = new RegExp(str)
      if (limit === 0) {
        // 不需要小数点
        val = val.replace(reg, '$1')
      } else {
        // 通过正则保留小数点后指定的位数
        val = val.replace(reg, '$1.$2')
      }
      return val
    },
    // 是否打包
    isPackChange() {
      selectList({ orgPath: window.sessionStorage.getItem('defaultOrgPath'), userSid: window.sessionStorage.getItem('defaultOrgPath'), isPack: this.finance.isPack }).then((resp) => {
        if (resp.success) {
          this.policy_list = resp.data
        }
      })
    },
    // 资方产品政策
    changePolicy(value) {
      const choose = this.policy_list.filter((item) => item.name === value)
      if (choose.length > 0 && choose !== null) {
        this.finance.policySid = choose[0].sid
        // 从金融产品政策中-- 获取标准年利率
        this.finance.policyYearRatio = choose[0].yearRatio
        // 从金融产品政策中-- 获取首付比例
        this.finance.downPayRatio = choose[0].downPayRatio
        // 从金融产品政策中-- 获取期数
        this.finance.loanPeriod = choose[0].period
        // 从金融产品政策中-- 获取贷款保证金比例
        this.finance.bondRatio = choose[0].bondRatio
        // 贴息用途赋值
        this.finance.factoryDiscountUse = '抵利息'
        this.finance.factoryDiscountUseKey = '02'
        selectListByOther({ orgPath: window.sessionStorage.getItem('defaultOrgPath'), userSid: window.sessionStorage.getItem('defaultOrgPath'), sid: choose[0].sid }).then((res) => {
          if (res.success) {
            this.other_list = res.data
          }
        })
      } else {
        this.finance.policySid = ''
      }
    },
    // 主方案 -- 融资项目总额
    financingProject() {
      if (this.finance.mainVehicleAmount !== '') {
        this.finance.loanTotal = parseInt(this.arguments(this.finance.mainVehicleAmount))
        if (this.finance.mainVehicleAmount !== '' && this.finance.accessoriesAmountCb) {
          this.finance.loanTotal = parseInt(this.arguments(this.finance.mainVehicleAmount)) + parseInt(this.arguments(this.finance.accessoriesAmount))
        }
        if (this.finance.mainVehicleAmount !== '' && this.finance.accessoriesAmountCb && this.finance.trailerAmountCb) {
          this.finance.loanTotal = parseInt(this.arguments(this.finance.mainVehicleAmount)) + parseInt(this.arguments(this.finance.accessoriesAmount)) + parseInt(this.arguments(this.finance.trailerAmount))
        }
        if (this.finance.mainVehicleAmount !== '' && this.finance.accessoriesAmountCb && this.finance.trailerAmountCb && this.finance.premiumCb) {
          this.finance.loanTotal = parseInt(this.arguments(this.finance.mainVehicleAmount)) + parseInt(this.arguments(this.finance.accessoriesAmount)) + parseInt(this.arguments(this.finance.trailerAmount)) + parseInt(this.arguments(this.finance.premium))
        }
        if (this.finance.mainVehicleAmount !== '' && this.finance.accessoriesAmountCb && this.finance.trailerAmountCb && this.finance.premiumCb && this.finance.purchaseTaxCb) {
          this.finance.loanTotal = parseInt(this.arguments(this.finance.mainVehicleAmount)) + parseInt(this.arguments(this.finance.accessoriesAmount)) + parseInt(this.arguments(this.finance.trailerAmount)) + parseInt(this.arguments(this.finance.premium)) + parseInt(this.arguments(this.finance.purchaseTax))
        }
      } else {
        this.finance.loanTotal = ''
      }
      // 首次计算出或修改融资项目总额
      if (this.finance.loanTotal !== '') {
        // 主方案 -- 计算首付金额
        this.finance.downPayAmount = (parseInt(this.arguments(this.finance.loanTotal)) * parseFloat(this.arguments(this.finance.downPayRatio)) / 100).toFixed(0)
        // 主方案 -- 计算产品贷款金额
        this.finance.loanAmount = parseInt(this.arguments(this.finance.loanTotal)) - parseInt(this.arguments(this.finance.downPayAmount))
        // 主方案 -- 计算贷款保证金
        this.finance.bondAmount = (parseFloat(this.arguments(this.finance.bondRatio)) * parseInt(this.arguments(this.finance.loanAmount)) / 100).toFixed(0)
        // 主方案 -- 月还金额
        this.monthlyPayment(this.finance.policyYearRatio, this.finance.loanPeriod, this.finance.loanAmount, 0, 0)
      }
    },
    // 主方案 -- 修改首付金额
    downPayAmountInput() {
      if (this.finance.loanTotal !== '') {
        // 重新计算首付比例
        this.finance.downPayRatio = (parseInt(this.arguments(this.finance.downPayAmount)) / parseInt(this.arguments(this.finance.loanTotal)) * 100).toFixed(2)
        // 重新计算产品贷款金额
        this.finance.loanAmount = parseInt(this.arguments(this.finance.loanTotal)) - parseInt(this.arguments(this.finance.downPayAmount))
        // 主方案 -- 贷款保证金
        this.finance.bondAmount = (parseFloat(this.arguments(this.finance.bondRatio)) * parseInt(this.arguments(this.finance.loanAmount)) / 100).toFixed(0)
        // 主方案 -- 月还金额
        this.monthlyPayment(this.finance.policyYearRatio, this.finance.loanPeriod, this.finance.loanAmount, 0, 0)
      }
    },
    // 主方案 -- 修改贷款保证金，重新计算贷款保证金比例
    bondAmountInput() {
      if (this.finance.bondAmount !== '') {
        this.finance.bondRatio = (parseInt(this.arguments(this.finance.bondAmount)) / parseInt(this.arguments(this.finance.loanAmount)) * 100).toFixed(2)
      }
    },
    // 主方案 -- 计算月还金额
    monthlyPayment(rate, nperiod, pv, fv, type) {
      var pmt = ''
      rate = parseFloat(parseFloat(rate) / 100) / 12
      if (pv !== '') {
        if (!fv) fv = 0
        if (!type) type = 0
        if (rate == 0) return -(pv + fv)/nperiod
        var pvif = Math.pow(1 + rate, nperiod)
        pmt = rate / (pvif - 1) * (pv * pvif + fv)
        if (type == 1) {
          pmt /= (1 + rate)
        }
      }
      this.finance.loanPayMoney = parseFloat(pmt).toFixed(0)
      // 根据月还金额 -- 计算利息总额
      this.finance.loanInterest = parseInt(this.arguments(this.finance.loanPayMoney)) * parseInt(this.arguments(nperiod)) - parseInt(this.arguments(pv))
    },
    // 主方案 -- 厂家贴息(当厂家贴息大于0且贴息用途为抵利息时需重新计算利息总额、月还金额、年利率)
    factoryDiscountInput() {
      if (this.finance.factoryDiscount !== '' && this.finance.factoryDiscount != '0' && this.finance.factoryDiscountUseKey === '02') {
        // 计算利息总额
        this.finance.loanInterest = parseInt(this.arguments(this.finance.loanInterest)) - parseInt(this.arguments(this.finance.factoryDiscount))
        // 计算月还金额
        this.finance.loanPayMoney = (parseInt(this.arguments(this.finance.loanPayMoney)) - parseInt(this.arguments(this.finance.factoryDiscount))) / parseInt(this.arguments(this.finance.loanPeriod))
        // 年利率
        this.finance.policyYearRatio = (parseFloat(this.rate(this.finance.loanPeriod, this.finance.loanPayMoney, this.finance.loanAmount, 0, 0, 0.01)) * 12).toFixed(2)
      }
    },
    // 主方案 -- 厂家贴息(当厂家贴息大于0且贴息用途为抵利息时需重新计算年利率)
    rate(paymentsPerYear, paymentAmount, presentValue, futureValue, dueEndOrBeginning, interest) {
      if (interest == null) interest = 0.01
      if (futureValue == null) futureValue = 0
      if (dueEndOrBeginning == null) dueEndOrBeginning = 0
      var FINANCIAL_MAX_ITERATIONS = 128
      var FINANCIAL_PRECISION = 0.0000001
      var y, y0, y1, x0, x1 = 0, f = 0, i = 0
      var rate = interest
      if (Math.abs(rate) < FINANCIAL_PRECISION) {
        y = presentValue * (1 + paymentsPerYear * rate) + paymentAmount * (1 + rate * dueEndOrBeginning) * paymentsPerYear + futureValue
      } else {
        f = Math.exp(paymentsPerYear * Math.log(1 + rate))
        y = presentValue * f + paymentAmount * (1 / rate + dueEndOrBeginning) * (f - 1) + futureValue
      }
      y0 = presentValue + paymentAmount * paymentsPerYear + futureValue
      y1 = presentValue * f + paymentAmount * (1 / rate + dueEndOrBeginning) * (f - 1) + futureValue
      i = x0 = 0.0
      x1 = rate
      while ((Math.abs(y0 - y1) > FINANCIAL_PRECISION) && (i < FINANCIAL_MAX_ITERATIONS)) {
        rate = (y1 * x0 - y0 * x1) / (y1 - y0)
        x0 = x1
        x1 = rate
        if (Math.abs(rate) < FINANCIAL_PRECISION) {
          y = presentValue * (1 + paymentsPerYear * rate) + paymentAmount * (1 + rate * dueEndOrBeginning) * paymentsPerYear + futureValue
        } else {
          f = Math.exp(paymentsPerYear * Math.log(1 + rate))
          y = presentValue * f + paymentAmount * (1 / rate + dueEndOrBeginning) * (f - 1) + futureValue
        }
        y0 = y1
        y1 = y
        ++i
      }
      return rate
    },
    // 主方案 -- 贴息用途
    changeFactoryDiscountUse(value) {
      const choose = this.factoryDiscountUse_list.filter((item) => item.dictValue === value)
      if (choose.length > 0 && choose !== null) {
        this.finance.factoryDiscountUseKey = choose[0].dictKey
      } else {
        this.finance.factoryDiscountUseKey = ''
      }
      if (this.finance.factoryDiscountUseKey === '02') {
        this.factoryDiscountInput()
      }
    },
    // 其它融--名称
    changeOtherPolicy(value) {
      const choose = this.other_list.filter((item) => item.name === value)
      if (choose.length > 0 && choose !== null) {
        this.finance.otherPolicySid = choose[0].sid
        this.finance.otherPolicyYearRatio = choose[0].yearRatio
        this.finance.otherPolicyPeriod = choose[0].period
      } else {
        this.finance.otherPolicySid = ''
      }
    },
    // 其它融 -- 修改贷款金额 计算月还金额、利息总额
    otherPolicyAmountInput() {
      this.otherMonthlyPayment(this.finance.otherPolicyYearRatio, this.finance.otherPolicyPeriod, this.finance.otherPolicyAmount, 0, 0)
    },
    // 其它融 -- 计算月还金额、利息总额
    otherMonthlyPayment(rate, nperiod, pv, fv, type) {
      var pmt = ''
      rate = parseFloat(parseFloat(rate) / 100) / 12
      if (pv !== '') {
        if (!fv) fv = 0
        if (!type) type = 0
        if (rate == 0) return -(pv + fv)/nperiod
        var pvif = Math.pow(1 + rate, nperiod)
        pmt = rate / (pvif - 1) * (pv * pvif + fv)
        if (type == 1) {
          pmt /= (1 + rate)
        }
      }
      this.finance.otherPolicyMonthlyRepay = parseFloat(pmt).toFixed(0)
      // 根据月还金额 -- 计算利息总额
      this.finance.otherPolicyInterest = parseInt(this.arguments(this.finance.otherPolicyMonthlyRepay)) * parseInt(this.arguments(nperiod)) - parseInt(this.arguments(pv))
    },
    // 方案汇总 —— 融资首付
    loanDownPay() {
      if (this.finance.downPayAmount !== '') {
        if (this.finance.otherPolicyAmount !== '') {
          this.finance.loanDownPay = parseInt(this.arguments(this.finance.downPayAmount)) - parseInt(this.arguments(this.finance.otherPolicyAmount))
        } else {
          this.finance.loanDownPay = this.finance.downPayAmount
        }
      }
      return this.finance.loanDownPay
    },
    // 方案汇总 —— 实际首付比例
    downPayAmountsRatio() {
      if (this.finance.loanDownPay !== '' && this.finance.loanTotal !== '') {
        this.finance.downPayAmountsRatio = (parseInt(this.arguments(this.finance.loanDownPay)) / parseInt(this.arguments(this.finance.loanTotal)) * 100).toFixed(2)
      }
      return this.finance.downPayAmountsRatio
    },
    // 方案汇总 —— 总贷款金额
    loanAmountTotal() {
      if (this.finance.loanAmount !== '') {
        if (this.finance.otherPolicyAmount !== '') {
          this.finance.loanAmountTotal = parseInt(this.arguments(this.finance.loanAmount)) + parseInt(this.arguments(this.finance.otherPolicyAmount))
        } else {
          this.finance.loanAmountTotal = this.finance.loanAmount
        }
      }
      return this.finance.loanAmountTotal
    },
    // 方案汇总 —— 期数
    period() {
      if (this.finance.loanPeriod !== '') {
        if (this.finance.otherPolicyPeriod !== '') {
          if (parseInt(this.arguments(this.finance.loanPeriod)) - parseInt(this.arguments(this.finance.otherPolicyPeriod)) < 0) {
            this.finance.period = '-' + '/' + this.finance.loanPeriod
          } else {
            const aa = parseInt(this.arguments(this.finance.loanPeriod)) - parseInt(this.arguments(this.finance.otherPolicyPeriod))
            this.finance.period = this.finance.otherPolicyPeriod + '/' + aa
          }
        } else {
          this.finance.period = '-' + '/' + this.finance.loanPeriod
        }
      }
      return this.finance.period
    },
    // 方案汇总 —— 月还金额
    monthlyRepay() {
      if (this.finance.loanPayMoney !== '') {
        if (this.finance.otherPolicyMonthlyRepay !== '') {
          if (parseInt(this.arguments(this.finance.loanPayMoney)) - parseInt(this.arguments(this.finance.otherPolicyMonthlyRepay)) === 0) {
            const aa = parseInt(this.arguments(this.finance.loanPayMoney)) + parseInt(this.arguments(this.finance.otherPolicyMonthlyRepay))
            this.finance.monthlyRepay = aa + '/' + '-'
          } else {
            const bb = parseInt(this.arguments(this.finance.loanPayMoney)) + parseInt(this.arguments(this.finance.otherPolicyMonthlyRepay))
            this.finance.monthlyRepay = bb + '/' + this.finance.loanPayMoney
          }
        } else {
          this.finance.monthlyRepay = this.finance.loanPayMoney + '/' + '-'
        }
      }
      return this.finance.monthlyRepay
    },
    // 方案汇总 —— 利息总额
    interest() {
      if (this.finance.loanInterest !== '' && this.finance.otherPolicyInterest !== '') {
        this.finance.interest = parseInt(this.arguments(this.finance.loanInterest)) + parseInt(this.arguments(this.finance.otherPolicyInterest))
      } else if (this.finance.loanInterest === '' && this.finance.otherPolicyInterest !== '') {
        this.finance.interest = this.finance.otherPolicyInterest
      } else if (this.finance.loanInterest !== '' && this.finance.otherPolicyInterest === '') {
        this.finance.interest = this.finance.loanInterest
      } else {
        this.finance.interest = ''
      }
      return this.finance.interest
    },
    // 应收明细 —— 融资首付
    downPayAmounts() {
      if (this.finance.downPayAmount !== '') {
        if (this.finance.otherPolicyAmount !== '') {
          this.finance.downPayAmounts = parseInt(this.arguments(this.finance.downPayAmount)) - parseInt(this.arguments(this.finance.otherPolicyAmount))
        } else {
          this.finance.downPayAmounts = this.finance.downPayAmount
        }
      }
      return this.finance.downPayAmounts
    },
    // 应收明细 —— 贷款保证金
    bondAmounts() {
      if (this.finance.bondAmount !== '') {
        this.finance.bondAmounts = this.finance.bondAmount
      }
      return this.finance.bondAmount
    },
    changeDealWay(value) {
      const choose = this.dealWay_list.filter((item) => item.dictValue === value)
      if (choose.length > 0 && choose !== null) {
        this.finance.dealWayKey = choose[0].dictKey
      } else {
        this.finance.dealWayKey = ''
      }
      if (this.finance.dealWayKey === '02') {
        this.finance.proxyPremium = '0'
        this.finance.proxyPurchasetax = '0'
      } else {
        this.finance.proxyPremium = ''
        this.finance.proxyPurchasetax = ''
      }
    },
    // 应收明细 -- 代收费用合计
    proxyTotal() {
      if (this.finance.proxyPremium !== '' && this.finance.proxyPurchasetax !== '') {
        this.finance.proxyTotal = parseInt(this.arguments(this.finance.proxyPremium)) + parseInt(this.arguments(this.finance.proxyPurchasetax))
      } else if (this.finance.proxyPremium === '' && this.finance.proxyPurchasetax !== '') {
        this.finance.proxyTotal = this.finance.proxyPurchasetax
      } else if (this.finance.proxyPremium !== '' && this.finance.proxyPurchasetax === '') {
        this.finance.proxyTotal = this.finance.proxyPremium
      } else {
        this.finance.proxyTotal = ''
      }
      return this.finance.proxyTotal
    },
    // 应收明细 —— 应收合计
    receivableTotal() {
      if (this.finance.serviceAmount !== '') {
        this.finance.receivableTotal = parseInt(this.arguments(this.finance.downPayAmounts)) + parseInt(this.arguments(this.finance.bondAmounts)) + parseInt(this.arguments(this.finance.depositPremium)) + parseInt(this.arguments(this.finance.depositSettle)) + parseInt(this.arguments(this.finance.serviceAmount)) + parseInt(this.arguments(this.finance.proxyAccidentPremium)) + parseInt(this.arguments(this.finance.registerAmount)) + parseInt(this.arguments(this.finance.operationAmount)) + parseInt(this.arguments(this.finance.vehOtherPrice)) + parseInt(this.arguments(this.finance.otherAmount)) + parseInt(this.arguments(this.finance.proxyPremium)) + parseInt(this.arguments(this.finance.proxyPurchasetax))
      }
      return this.finance.receivableTotal
    },
    // 应收明细 —— 抵顶费用合计
    offsetTotal() {
      if (this.finance.offsetPremium !== '' && this.finance.offsetPurchasetax !== '') {
        this.finance.offsetTotal = parseInt(this.arguments(this.finance.offsetPremium)) + parseInt(this.arguments(this.finance.offsetPurchasetax))
      } else if (this.finance.offsetPremium === '' && this.finance.offsetPurchasetax !== '') {
        this.finance.offsetTotal = this.finance.offsetPurchasetax
      } else if (this.finance.offsetPremium !== '' && this.finance.offsetPurchasetax === '') {
        this.finance.offsetTotal = this.finance.offsetPremium
      } else {
        this.finance.offsetTotal = ''
      }
      return this.finance.offsetTotal
    },
    // 应收明细 —— 实收合计
    realTotal() {
      if (this.finance.offsetTotal !== '') {
        this.finance.realTotal = parseInt(this.arguments(this.finance.receivableTotal)) - parseInt(this.arguments(this.finance.offsetTotal))
      } else {
        this.finance.realTotal = this.finance.receivableTotal
      }
      return this.finance.realTotal
    },
    // 应收明细 -- 车辆总价
    vehTotalPrice() {
      this.finance.vehTotalPrice = parseInt(this.arguments(this.finance.downPayAmounts)) + parseInt(this.arguments(this.finance.serviceAmount)) + parseInt(this.arguments(this.finance.proxyAccidentPremium)) + parseInt(this.arguments(this.finance.registerAmount)) + parseInt(this.arguments(this.finance.operationAmount)) + parseInt(this.arguments(this.finance.vehOtherPrice)) + parseInt(this.arguments(this.finance.otherAmount)) + parseInt(this.arguments(parseInt(this.arguments(this.finance.loanPayMoney)) * parseInt(this.arguments(this.finance.loanPeriod)))) + parseInt(this.arguments(parseInt(this.arguments(this.finance.otherPolicyMonthlyRepay)) * parseInt(this.arguments(this.finance.otherPolicyPeriod))))
      if (!this.finance.premiumCb && this.finance.premium !== '' && this.finance.premium !== null) {
        this.finance.vehTotalPrice = parseInt(this.arguments(this.finance.downPayAmounts)) + parseInt(this.arguments(this.finance.serviceAmount)) + parseInt(this.arguments(this.finance.proxyAccidentPremium)) + parseInt(this.arguments(this.finance.registerAmount)) + parseInt(this.arguments(this.finance.operationAmount)) + parseInt(this.arguments(this.finance.vehOtherPrice)) + parseInt(this.arguments(this.finance.otherAmount)) + parseInt(this.arguments(parseInt(this.arguments(this.finance.loanPayMoney)) * parseInt(this.arguments(this.finance.loanPeriod)))) + parseInt(this.arguments(parseInt(this.arguments(this.finance.otherPolicyMonthlyRepay)) * parseInt(this.arguments(this.finance.otherPolicyPeriod)))) + parseInt(this.arguments(this.finance.premium))
      }
      if (!this.finance.purchaseTaxCb && this.finance.purchaseTax !== '' && this.finance.purchaseTax !== null) {
        this.finance.vehTotalPrice = parseInt(this.arguments(this.finance.downPayAmounts)) + parseInt(this.arguments(this.finance.serviceAmount)) + parseInt(this.arguments(this.finance.proxyAccidentPremium)) + parseInt(this.arguments(this.finance.registerAmount)) + parseInt(this.arguments(this.finance.operationAmount)) + parseInt(this.arguments(this.finance.vehOtherPrice)) + parseInt(this.arguments(this.finance.otherAmount)) + parseInt(this.arguments(parseInt(this.arguments(this.finance.loanPayMoney)) * parseInt(this.arguments(this.finance.loanPeriod)))) + parseInt(this.arguments(parseInt(this.arguments(this.finance.otherPolicyMonthlyRepay)) * parseInt(this.arguments(this.finance.otherPolicyPeriod)))) + parseInt(this.arguments(this.finance.premium)) + parseInt(this.arguments(this.finance.purchaseTax))
      }
      return this.finance.vehTotalPrice
    },
    arguments(val) {
      if (val === '' || val === undefined) {
        val = 0
        return val
      } else {
        return val
      }
    },
    backData() {
      this.$emit('backData', this.finance)
    }
  }
}
</script>

<style scoped>
.formaddcopy02 {
  padding: 0px;
}
.span-sty {
  width: 140px !important;
}

.addinputInfo {
  margin-left: 130px !important;
}

.addinputw {
  margin-left: 130px !important;
}

.formaddcopy02 .el-row .el-col /deep/ .el-form-item .addinputw {
  margin-left: 130px !important;
  width: calc(100% - 125px);
}

/deep/ .el-form-item__error {
  margin-left: 120px !important;
}
</style>
