<template>
  <div class="app-container">
    <div v-show="viewState == 1">
      <div class="tab-header webtop">
        <div>{{ viewTitle }}</div>
        <div>
          <el-button type="primary" size="small" :disabled="submitdisabled" @click="saveOrUpdate()">保存</el-button>
          <el-button type="primary" size="small" :disabled="submitdisabled" @click="submit()">提交</el-button>
          <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
        </div>
      </div>
      <div class="listconadd">
        <el-form ref="form_obj" :model="formobj" :rules="rules" class="formaddcopy02">
          <div style="font-size: 16px;text-align: right">金额单位：元</div>
          <el-row style="border-top: 1px solid #e0e3eb">
            <el-col :span="8">
              <div class="span-sty">申请部门</div>
              <el-form-item><span class="addinputInfo">{{ formobj.createDept }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">申请人</div>
              <el-form-item><span class="addinputInfo">{{ formobj.createByName }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">申请日期</div>
              <el-form-item><span class="addinputInfo">{{ formobj.createTime }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">车架号</div>
              <el-form-item><span class="addinputInfo">{{ formobj.vinNo }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">车牌号</div>
              <el-form-item><span class="addinputInfo">{{ formobj.vehMark }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item>
                <span style="margin-left: 10px;color: #20a0ff" @click="lookCSJL(formobj.csjlSid)">催收记录</span><span style="margin-left: 10px;color: #20a0ff" @click="lookJRFA(formobj.jrfaSid)">金融方案</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">客户名称</div>
              <el-form-item><span class="addinputInfo">{{ formobj.customerName }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">贷款人</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanName }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">贷款合同编号</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanContractNo }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">资方</div>
              <el-form-item><span class="addinputInfo">{{ formobj.bankName }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方合同编号</div>
              <el-form-item><span class="addinputInfo">{{ formobj.bankContractNo }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">结清日期</div>
              <el-form-item><span class="addinputInfo">{{ formobj.settingDate }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">公司当前逾期月还</div>
              <el-form-item><span class="addinputInfo">{{ formobj.overdueMonthPrice }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">公司当期未到期月还</div>
              <el-form-item><span class="addinputInfo">{{ formobj.currentNotDuePrice }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">公司未到期金额</div>
              <el-form-item><span class="addinputInfo">{{ formobj.notDuePrice }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">备注</div>
              <el-form-item>
                <el-input class="addinputInfo addinputw" v-model="formobj.remarks" clearable placeholder=""/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="formobj.showHg">
            <el-col :span="16">
              <div class="span-sty">回购申请</div>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">预结清日期</div>
              <el-form-item><span class="addinputInfo">{{ formobj.settingDateBe }}</span></el-form-item>
            </el-col>
          </el-row>
          <div class="title" style="display: flex;flex-direction: row;justify-content: space-between;align-items: center">
            <div>资方结清费用</div>
            <div style="display: flex;flex-direction: row;justify-content: space-between;align-items: center">
              <div>贷款保证金:<el-input style="width: 60%" @keyup.native="UpNumber" v-model="formobj.loanSettleBankCostVo.loanDeposit" clearable placeholder="" /></div>
              <div>是否抵顶:
                <el-radio-group v-model="formobj.loanSettleBankCostVo.topping">
                  <el-radio label="1">是</el-radio>
                  <el-radio label="0">否</el-radio>
                </el-radio-group>
              </div>
            </div>
          </div>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">资方逾期月还</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleBankCostVo.price }}</span>
                <el-input v-else class="addinputInfo addinputw" @keyup.native="UpNumber" v-model="formobj.loanSettleBankCostVo.price" clearable placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方当期未到期月还</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleBankCostVo.currentNotDuePrice }}</span>
                <el-input v-else class="addinputInfo addinputw" @keyup.native="UpNumber" v-model="formobj.loanSettleBankCostVo.currentNotDuePrice" clearable placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方未到期金额</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleBankCostVo.notDuePrice }}</span>
                <el-input v-else class="addinputInfo addinputw" @keyup.native="UpNumber" @input="notDuePriceInput" v-model="formobj.loanSettleBankCostVo.notDuePrice" clearable placeholder=""/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">资方逾期利息</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleBankCostVo.bankInterest }}</span>
                <el-input v-else class="addinputInfo addinputw" @keyup.native="UpNumber" @input="bankInterestInput" v-model="formobj.loanSettleBankCostVo.bankInterest" clearable placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方名义价</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleBankCostVo.bankNominalPrice }}</span>
                <el-input v-else class="addinputInfo addinputw" @keyup.native="UpNumber" @input="bankNominalPriceInput" v-model="formobj.loanSettleBankCostVo.bankNominalPrice" clearable placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方合同违约金</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleBankCostVo.bankContractLiquidated }}</span>
                <el-input v-else class="addinputInfo addinputw" @keyup.native="UpNumber" @input="bankContractLiquidatedInput" v-model="formobj.loanSettleBankCostVo.bankContractLiquidated" clearable placeholder=""/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">资方其他应收</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleBankCostVo.bankOtherReceivable }}</span>
                <el-input v-else class="addinputInfo addinputw" @keyup.native="UpNumber" v-model="formobj.loanSettleBankCostVo.bankOtherReceivable" clearable placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">其他应收说明</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleBankCostVo.otherReceivableRemarks }}</span>
                <el-input v-else class="addinputInfo addinputw" v-model="formobj.loanSettleBankCostVo.otherReceivableRemarks" clearable placeholder=""/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">资方结清金额</div>
              <el-form-item><span class="addinputInfo">{{ calculateBankSettlePrice }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方收款账号</div>
              <el-form-item>
                <el-select class="addinputInfo" v-model="formobj.loanSettleBankCostVo.bankAccount" placeholder="请选择" clearable filterable @change="bankAccountChange">
                  <el-option v-for="item in bank_list" :key="item.bankAccount" :label="item.accountName" :value="item.bankAccount"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方收款账户</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleBankCostVo.accountName }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">附件</div>
              <el-form-item>
                <div v-if="formobj.showHg">
                  <el-image  class="addinputInfo" style="width: 150px;height: 150px" v-for="(item, index) in image_list" :key="index" :src="item" :preview-src-list="image_list" />
                </div>
                <uploadImg v-else ref="uploadImg" class="addinputInfo" v-model="formobj.loanSettleBankCostVo.filesList" :limit="50" bucket="map" :upload-data="{ type: '0001' }"/>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="title" style="display: flex;flex-direction: row;justify-content: space-between;align-items: center">
            <div>公司结清费用</div>
            <div>贷款保证金：<span>{{ formobj.loanSettleCompanyCostVo.loanDeposit }}</span></div>
          </div>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">公司逾期月还</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.overduePrice }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">垫资方逾期利息</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.putBankInterest }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资金占用费</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.funfCost }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">资方逾期利息</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.bankOverInterest }}</span>
                <el-input v-else class="addinputInfo addinputw" @keyup.native="UpNumber" v-model="formobj.loanSettleCompanyCostVo.bankOverInterest" clearable placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">公司当期未到期月还</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.companyCurrentNotPrice }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方未到期金额</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.bankNotPrice }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">贷款保证金扣罚金额</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.deductionAmount }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">名义价</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.companyNominalPrice }}</span>
                <el-input v-else class="addinputInfo addinputw" @keyup.native="UpNumber" v-model="formobj.loanSettleCompanyCostVo.companyNominalPrice" clearable placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">合同违约金</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.contractLiquidated }}</span>
                <el-input v-else class="addinputInfo addinputw" @keyup.native="UpNumber" v-model="formobj.loanSettleCompanyCostVo.contractLiquidated" clearable placeholder=""/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">公司其他费用</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.companyOtherPrice }}</span>
                <el-input v-else class="addinputInfo addinputw" @keyup.native="UpNumber" v-model="formobj.loanSettleCompanyCostVo.companyOtherPrice" clearable placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">其他费用说明</div>
              <el-form-item>
                <span v-if="formobj.showHg" class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.otherCostRemarks }}</span>
                <el-input v-else class="addinputInfo addinputw" v-model="formobj.loanSettleCompanyCostVo.otherCostRemarks" clearable placeholder=""/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">公司正常结清合计</div>
              <el-form-item><span class="addinputInfo">{{ calculateSettleAll }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="formobj.showHg">
            <el-col :span="24">
              <div class="span-sty">截止当前资金占用费</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.fundAll }}</span></el-form-item>
            </el-col>
          </el-row>
          <div class="title"><el-checkbox @change="trueReductionChange" v-model="formobj.trueReduction" style="padding-right: 5px"/>公司结清费用减免情况</div>
          <div v-if="formobj.trueReduction">
            <el-row>
              <el-col :span="8">
                <div class="span-sty">资金占用费减免</div>
                <el-form-item><el-input class="addinputInfo addinputw" @keyup.native="UpNumber" v-model="formobj.loanSettleCompanyReductionVo.fundPenalty" clearable placeholder=""/></el-form-item>
              </el-col>
              <el-col :span="8">
                <div class="span-sty">贷款保证金扣减减免</div>
                <el-form-item><el-input class="addinputInfo addinputw" @keyup.native="UpNumber" v-model="formobj.loanSettleCompanyReductionVo.depositPenalty" clearable placeholder=""/></el-form-item>
              </el-col>
              <el-col :span="8">
                <div class="span-sty">其他费用减免</div>
                <el-form-item><el-input class="addinputInfo addinputw" @keyup.native="UpNumber" v-model="formobj.loanSettleCompanyReductionVo.otherCost" clearable placeholder=""/></el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <div class="span-sty">公司减免后结清合计</div>
                <el-form-item><span class="addinputInfo">{{ calculateAmountTo }}</span></el-form-item>
              </el-col>
            </el-row>
          </div>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">结清利润</div>
              <el-form-item><span class="addinputInfo">{{ calculateProfit }}</span></el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
    <!-- 查看催收记录 -->
    <vehiclecollectionrecords v-show="viewState == 2" ref="divCollection" @doback="resetState"/>
    <!-- 查看金融方案 -->
    <financialschemeInfo v-show="viewState == 3" ref="divFinancial" @doback="resetState"/>
  </div>
</template>

<script>
import req from '@/api/settle/settle'
import uploadImg from '@/components/uploadFile/uploadImg'
import vehiclecollectionrecords from '../overduevehicle/vehiclecollectionrecords'
import financialschemeInfo from '@/components/publicPage/financialschemeInfo'
import { fetchListByBankSid } from '@/api/Common/dictcommons'

export default {
  name: 'SettleAdd',
  components: {
    uploadImg,
    vehiclecollectionrecords,
    financialschemeInfo
  },
  computed: {
    // 资方结清费用模块--资方结清金额计算
    calculateBankSettlePrice() {
      let bankSettlePrice = '0'
      // 是否抵顶为是，资方结清金额 = 资方逾期月还 + 资方当期未到期月还 + 资方未到期金额 + 资方逾期利息 + 资方名义价 + 资方合同违约金 + 资方其他应收 - 贷款保证金
      if (this.formobj.loanSettleBankCostVo.topping !== '' && this.formobj.loanSettleBankCostVo.topping === '1') {
        bankSettlePrice = Math.round((parseFloat(this.formobj.loanSettleBankCostVo.price === '' ? 0 : this.formobj.loanSettleBankCostVo.price) + parseFloat(this.formobj.loanSettleBankCostVo.currentNotDuePrice === '' ? 0 : this.formobj.loanSettleBankCostVo.currentNotDuePrice) + parseFloat(this.formobj.loanSettleBankCostVo.notDuePrice === '' ? 0 : this.formobj.loanSettleBankCostVo.notDuePrice) + parseFloat(this.formobj.loanSettleBankCostVo.bankInterest === '' ? 0 : this.formobj.loanSettleBankCostVo.bankInterest) + parseFloat(this.formobj.loanSettleBankCostVo.bankNominalPrice === '' ? 0 : this.formobj.loanSettleBankCostVo.bankNominalPrice) + parseFloat(this.formobj.loanSettleBankCostVo.bankContractLiquidated === '' ? 0 : this.formobj.loanSettleBankCostVo.bankContractLiquidated) + parseFloat(this.formobj.loanSettleBankCostVo.bankOtherReceivable === '' ? 0 : this.formobj.loanSettleBankCostVo.bankOtherReceivable) - parseFloat(this.formobj.loanSettleBankCostVo.loanDeposit !== '' ? this.formobj.loanSettleBankCostVo.loanDeposit : '0')) * 100) / 100
      } else {
        // 是否抵顶为否，资方结清金额 = 资方逾期月还 + 资方当期未到期月还 + 资方未到期金额 + 资方逾期利息 + 资方名义价 + 资方合同违约金 + 资方其他应收
        bankSettlePrice = Math.round((parseFloat(this.formobj.loanSettleBankCostVo.price === '' ? 0 : this.formobj.loanSettleBankCostVo.price) + parseFloat(this.formobj.loanSettleBankCostVo.currentNotDuePrice === '' ? 0 : this.formobj.loanSettleBankCostVo.currentNotDuePrice) + parseFloat(this.formobj.loanSettleBankCostVo.notDuePrice === '' ? 0 : this.formobj.loanSettleBankCostVo.notDuePrice) + parseFloat(this.formobj.loanSettleBankCostVo.bankInterest === '' ? 0 : this.formobj.loanSettleBankCostVo.bankInterest) + parseFloat(this.formobj.loanSettleBankCostVo.bankNominalPrice === '' ? 0 : this.formobj.loanSettleBankCostVo.bankNominalPrice) + parseFloat(this.formobj.loanSettleBankCostVo.bankContractLiquidated === '' ? 0 : this.formobj.loanSettleBankCostVo.bankContractLiquidated) + parseFloat(this.formobj.loanSettleBankCostVo.bankOtherReceivable === '' ? 0 : this.formobj.loanSettleBankCostVo.bankOtherReceivable)) * 100) / 100
      }
      return bankSettlePrice
    },
    // 公司结清费用模块--公司正常结清合计计算
    calculateSettleAll() {
      if (!this.formobj.showHg) {
        return parseFloat(this.formobj.loanSettleCompanyCostVo.overduePrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.overduePrice) + parseFloat(this.formobj.loanSettleCompanyCostVo.funfCost === '' ? 0 : this.formobj.loanSettleCompanyCostVo.funfCost) + parseFloat(this.formobj.loanSettleCompanyCostVo.bankOverInterest === '' ? 0 : this.formobj.loanSettleCompanyCostVo.bankOverInterest) + parseFloat(this.formobj.loanSettleCompanyCostVo.companyCurrentNotPrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.companyCurrentNotPrice) + parseFloat(this.formobj.loanSettleCompanyCostVo.bankNotPrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.bankNotPrice) + parseFloat(this.formobj.loanSettleCompanyCostVo.deductionAmount === '' ? 0 : this.formobj.loanSettleCompanyCostVo.deductionAmount) + parseFloat(this.formobj.loanSettleCompanyCostVo.companyNominalPrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.companyNominalPrice) + parseFloat(this.formobj.loanSettleCompanyCostVo.contractLiquidated === '' ? 0 : this.formobj.loanSettleCompanyCostVo.contractLiquidated) + parseFloat(this.formobj.loanSettleCompanyCostVo.companyOtherPrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.companyOtherPrice) - parseFloat(this.formobj.loanSettleCompanyCostVo.loanDeposit === '' ? 0 : this.formobj.loanSettleCompanyCostVo.loanDeposit) || 0
      } else {
        return parseFloat(this.formobj.loanSettleCompanyCostVo.overduePrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.overduePrice) + parseFloat(this.formobj.loanSettleCompanyCostVo.funfCost === '' ? 0 : this.formobj.loanSettleCompanyCostVo.funfCost) + parseFloat(this.formobj.loanSettleCompanyCostVo.bankOverInterest === '' ? 0 : this.formobj.loanSettleCompanyCostVo.bankOverInterest) + parseFloat(this.formobj.loanSettleCompanyCostVo.companyCurrentNotPrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.companyCurrentNotPrice) + parseFloat(this.formobj.loanSettleCompanyCostVo.bankNotPrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.bankNotPrice) + parseFloat(this.formobj.loanSettleCompanyCostVo.deductionAmount === '' ? 0 : this.formobj.loanSettleCompanyCostVo.deductionAmount) + parseFloat(this.formobj.loanSettleCompanyCostVo.companyNominalPrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.companyNominalPrice) + parseFloat(this.formobj.loanSettleCompanyCostVo.contractLiquidated === '' ? 0 : this.formobj.loanSettleCompanyCostVo.contractLiquidated) + parseFloat(this.formobj.loanSettleCompanyCostVo.companyOtherPrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.companyOtherPrice) - parseFloat(this.formobj.loanSettleCompanyCostVo.loanDeposit === '' ? 0 : this.formobj.loanSettleCompanyCostVo.loanDeposit) - parseFloat(this.formobj.buyBackMoney === '' ? 0 : this.formobj.buyBackMoney) || 0
      }
    },
    // 公司结清费用减免情况模块--公司减免后结清合计计算
    calculateAmountTo() {
      if (this.formobj.trueReduction) {
        return parseFloat(this.calculateSettleAll === '' ? 0 : this.calculateSettleAll) - parseFloat(this.formobj.loanSettleCompanyReductionVo.fundPenalty === '' ? 0 : this.formobj.loanSettleCompanyReductionVo.fundPenalty) - parseFloat(this.formobj.loanSettleCompanyReductionVo.depositPenalty === '' ? 0 : this.formobj.loanSettleCompanyReductionVo.depositPenalty) - parseFloat(this.formobj.loanSettleCompanyReductionVo.otherCost === '' ? 0 : this.formobj.loanSettleCompanyReductionVo.otherCost) || 0
      } else {
        return '0'
      }
    },
    // 结清利润计算
    calculateProfit() {
      return (parseFloat(this.formobj.loanSettleCompanyCostVo.bankOverInterest === '' ? 0 : this.formobj.loanSettleCompanyCostVo.bankOverInterest) + parseFloat(this.formobj.loanSettleCompanyCostVo.companyNominalPrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.companyNominalPrice) + parseFloat(this.formobj.loanSettleCompanyCostVo.contractLiquidated === '' ? 0 : this.formobj.loanSettleCompanyCostVo.contractLiquidated) + parseFloat(this.formobj.loanSettleCompanyCostVo.companyOtherPrice === '' ? 0 : this.formobj.loanSettleCompanyCostVo.companyOtherPrice)) - (parseFloat(this.formobj.loanSettleBankCostVo.bankInterest === '' ? 0 : this.formobj.loanSettleBankCostVo.bankInterest) + parseFloat(this.formobj.loanSettleBankCostVo.bankNominalPrice === '' ? 0 : this.formobj.loanSettleBankCostVo.bankNominalPrice) + parseFloat(this.formobj.loanSettleBankCostVo.bankContractLiquidated === '' ? 0 : this.formobj.loanSettleBankCostVo.bankContractLiquidated) + parseFloat(this.formobj.loanSettleBankCostVo.bankOtherReceivable === '' ? 0 : this.formobj.loanSettleBankCostVo.bankOtherReceivable)) || 0
    }
  },
  data() {
    return {
      viewTitle: '',
      viewState: 1,
      submitdisabled: false,
      tableKey: 1,
      index: 0,
      image_list: [],
      bank_list: [],
      formobj: {
        bankContractNo: '',
        bankName: '',
        bankSid: '',
        busSid: '',
        busVinSid: '',
        createByName: '',
        createDept: '',
        createDeptSid: '',
        createTime: '',
        currentNotDuePrice: '',
        customerName: '',
        customerSid: '',
        loanContractNo: '',
        loanName: '',
        loanSettleBankCostVo: {
          bankContractLiquidated: '',
          bankInterest: '',
          bankNominalPrice: '',
          bankOtherReceivable: '',
          bankSettlePrice: '',
          currentNotDuePrice: '',
          filesList: [],
          notDuePrice: '',
          otherReceivableRemarks: '',
          price: '',
          topping: '',
          loanDeposit: '',
          bankAccount: '',
          accountName: ''
        },
        loanSettleCompanyCostVo: {
          bankNotPrice: '',
          bankOverInterest: '',
          companyCurrentNotPrice: '',
          companyNominalPrice: '',
          companyOtherPrice: '',
          contractLiquidated: '',
          deductionAmount: '',
          fundAll: '',
          funfCost: '',
          loanDeposit: '',
          otherCostRemarks: '',
          overduePrice: '',
          putBankInterest: '',
          settleAll: ''
        },
        loanSettleCompanyReductionVo: {
          amountTo: '',
          depositPenalty: '',
          fundPenalty: '',
          otherCost: '',
          profit: ''
        },
        loanSid: '',
        notDuePrice: '',
        orgPath: '',
        overdueMonthPrice: '',
        saleOrderSid: '',
        settingDate: '',
        settingDateBe: '',
        showHg: false, // 是否展示回购字段
        buyBackMoney: '', // 回购后的还款金额
        sid: '',
        trueReduction: false,
        useOrgName: '',
        useOrgSid: '',
        userSid: '',
        vehMark: '',
        vinNo: '',
        remarks: ''
      },
      rules: {}
    }
  },
  methods: {
    UpNumber(e) {
      e.target.value = e.target.value.replace(/[^0-9.]/g, '') // 清除“数字”和“.”以外的字符
      e.target.value = e.target.value.replace(/^00/, '0.') // 开头不能有两个0
      e.target.value = e.target.value.replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的
      e.target.value = e.target.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.')
      e.target.value = e.target.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3') // 只能输入两个小数
      if (e.target.value.indexOf('.') < 0 && e.target.value !== '' && e.target.value !== '-') {
        // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        e.target.value = parseFloat(e.target.value)
      }
    },
    showAdd(row) {
      this.viewTitle = '【新增】结清申请'
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      req.fetchBySid({ busVinSid: row.busVinSid, orgPath: window.sessionStorage.getItem('defaultOrgPath'), sid: '', userSid: window.sessionStorage.getItem('userSid') }).then((res) => {
        if (res.success) {
          this.formobj = res.data
          fetchListByBankSid({ bankSid: this.formobj.bankSid }).then((res) => {
            if (res.success) {
              this.bank_list = res.data
            }
          })
        }
      })
    },
    showEdit(row) {
      this.viewTitle = '【编辑】结清申请'
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      req.fetchBySid({ busVinSid: '', orgPath: '', sid: row.sid, userSid: '' }).then((res) => {
        if (res.success) {
          this.formobj = res.data
          this.formobj.instanceId = res.data.procInstId
          fetchListByBankSid({ bankSid: this.formobj.bankSid }).then((res) => {
            if (res.success) {
              this.bank_list = res.data
            }
          })
          if (this.formobj.showHg && this.formobj.loanSettleBankCostVo.filesList.length > 0) {
            const aa = []
            this.formobj.loanSettleBankCostVo.filesList.forEach((e) => {
              aa.push(e.url)
            })
            this.image_list = aa
          }
        }
      })
    },
    // 回购申请管理--点击结清申请初始化
    showInit(sid) {
      this.viewTitle = '【新增】结清申请'
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      req.settleRepoInit({ orgPath: window.sessionStorage.getItem('defaultOrgPath'), sid: sid, userSid: window.sessionStorage.getItem('userSid') }).then((res) => {
        if (res.success) {
          this.formobj = res.data
          fetchListByBankSid({ bankSid: this.formobj.bankSid }).then((res) => {
            if (res.success) {
              this.bank_list = res.data
            }
          })
          if (this.formobj.loanSettleBankCostVo.filesList.length > 0) {
            const aa = []
            this.formobj.loanSettleBankCostVo.filesList.forEach((e) => {
              aa.push(e.url)
            })
            this.image_list = aa
          }
        }
      })
    },
    // 查看催收记录
    lookCSJL(sid) {
      if (sid !== '') {
        this.viewState = 2
        this.$refs['divCollection'].showInfo({ saleVehSid: this.formobj.busVinSid })
      } else {
        this.$message({ showClose: true, type: 'error', message: '暂无催收记录' })
      }
    },
    lookJRFA(sid) {
      if (sid !== '') {
        req.selectDetailss({ businessSid: this.formobj.saleOrderSid }).then((res) => {
          if (res.success) {
            this.viewState = 3
            this.$refs['divFinancial'].showInfo(res.data, '03')
          }
        })
      } else {
        this.$message({ showClose: true, type: 'error', message: '暂无金融方案' })
      }
    },
    resetState() {
      this.viewState = 1
    },
    bankAccountChange(value) {
      const choose = this.bank_list.filter((item) => item.bankAccount === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.loanSettleBankCostVo.accountName = choose[0].accountName
      } else {
        this.formobj.loanSettleBankCostVo.accountName = ''
      }
    },
    notDuePriceInput(val) {
      this.formobj.loanSettleCompanyCostVo.bankNotPrice = val
    },
    bankInterestInput(val) {
      this.formobj.loanSettleCompanyCostVo.bankOverInterest = val
    },
    bankNominalPriceInput(val) {
      this.formobj.loanSettleCompanyCostVo.companyNominalPrice = val
    },
    bankContractLiquidatedInput(val) {
      this.formobj.loanSettleCompanyCostVo.contractLiquidated = val
    },
    trueReductionChange() {
      if (!this.formobj.trueReduction) {
        this.formobj.loanSettleCompanyReductionVo.fundPenalty = ''
        this.formobj.loanSettleCompanyReductionVo.depositPenalty = ''
        this.formobj.loanSettleCompanyReductionVo.otherCost = ''
      }
    },
    saveOrUpdate() {
      this.formobj.loanSettleBankCostVo.bankSettlePrice = this.calculateBankSettlePrice
      this.formobj.loanSettleCompanyCostVo.settleAll = this.calculateSettleAll
      this.formobj.loanSettleCompanyReductionVo.amountTo = this.calculateAmountTo
      this.formobj.loanSettleCompanyReductionVo.profit = this.calculateProfit
      this.$refs['form_obj'].validate((valid) => {
        if (valid) {
          this.submitdisabled = true
          req.saveOrUpdate(this.formobj).then((res) => {
            if (res.success) {
              this.$message({ showClose: true, type: 'success', message: '保存成功' })
              this.handleReturn('true')
            } else {
              this.submitdisabled = false
            }
          }).catch(() => {
            this.submitdisabled = false
          })
        }
      })
    },
    submit() {
      this.formobj.loanSettleBankCostVo.bankSettlePrice = this.calculateBankSettlePrice
      this.formobj.loanSettleCompanyCostVo.settleAll = this.calculateSettleAll
      this.formobj.loanSettleCompanyReductionVo.amountTo = this.calculateAmountTo
      this.formobj.loanSettleCompanyReductionVo.profit = this.calculateProfit
      this.$refs['form_obj'].validate((valid) => {
        if (valid) {
          this.submitdisabled = true
          req.submit(this.formobj).then((res) => {
            if (res.success) {
              this.$message({ showClose: true, type: 'success', message: '操作成功' })
              this.handleReturn('true')
            } else {
              this.submitdisabled = false
            }
          }).catch(() => {
            this.submitdisabled = false
          })
        }
      })
    },
    handleReturn(isreload) {
      if (isreload === 'true') this.$emit('reloadlist')
      this.formobj = {
        bankContractNo: '',
        bankName: '',
        bankSid: '',
        busSid: '',
        busVinSid: '',
        createByName: '',
        createDept: '',
        createDeptSid: '',
        createTime: '',
        currentNotDuePrice: '',
        customerName: '',
        customerSid: '',
        loanContractNo: '',
        loanName: '',
        loanSettleBankCostVo: {
          bankContractLiquidated: '',
          bankInterest: '',
          bankNominalPrice: '',
          bankOtherReceivable: '',
          bankSettlePrice: '',
          currentNotDuePrice: '',
          filesList: [],
          notDuePrice: '',
          otherReceivableRemarks: '',
          price: '',
          topping: '',
          loanDeposit: '',
          bankAccount: '',
          accountName: ''
        },
        loanSettleCompanyCostVo: {
          bankNotPrice: '',
          bankOverInterest: '',
          companyCurrentNotPrice: '',
          companyNominalPrice: '',
          companyOtherPrice: '',
          contractLiquidated: '',
          deductionAmount: '',
          fundAll: '',
          funfCost: '',
          loanDeposit: '',
          otherCostRemarks: '',
          overduePrice: '',
          putBankInterest: '',
          settleAll: ''
        },
        loanSettleCompanyReductionVo: {
          amountTo: '',
          depositPenalty: '',
          fundPenalty: '',
          otherCost: '',
          profit: ''
        },
        loanSid: '',
        notDuePrice: '',
        orgPath: '',
        overdueMonthPrice: '',
        saleOrderSid: '',
        showHg: false, // 是否展示回购字段
        buyBackMoney: '', // 回购后的还款金额
        settingDate: '',
        settingDateBe: '',
        sid: '',
        trueReduction: false,
        useOrgName: '',
        useOrgSid: '',
        userSid: '',
        vehMark: '',
        vinNo: '',
        remarks: ''
      }
      this.image_list = []
      this.submitdisabled = false
      this.$emit('doback')
    }
  }
}
</script>

<style scoped>
.span-sty {
  width: 200px !important;
}
.addinputInfo {
  margin-left: 190px !important;
}
/* 覆盖element-ui的单选按钮样式 */
/deep/ .el-radio__input.is-checked .el-radio__inner {
  border-color: #409EFF; /* 未选中状态下的边框颜色 */
  background-color: #409EFF; /* 选中后的背景色 */
}
/* 如果需要改变选中后对勾的颜色 */
/deep/ .el-radio__input.is-checked .el-radio__inner:after {
  background-color: #000000; /* 对勾的颜色 */
}
/deep/ .el-radio__input.is-checked+.el-radio__label {
  color: #000000; /* 选中后的字体颜色 */
}
</style>
