<template>
  <div class="app-container">
    <div v-show="viewState == 1">
      <div class="tab-header webtop">
        <div>{{ viewTitle }}</div>
        <div>
          <el-button type="primary" v-if="formobj.confirmAtn" size="small" @click="settleByConfirm()">确认客户结清</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><span class="addinputInfo">{{ formobj.remarks }}</span></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>
              <span style="margin-right: 10px">贷款保证金: {{ formobj.loanSettleBankCostVo.loanDeposit }}</span>
              <span>是否抵顶: {{ formobj.loanSettleBankCostVo.topping ? '是' : !formobj.loanSettleBankCostVo.topping ? '否' : '' }}</span>
            </div>
          </div>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">资方逾期月还</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleBankCostVo.price }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方当期未到期月还</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleBankCostVo.currentNotDuePrice }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方未到期金额</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleBankCostVo.notDuePrice }}</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.loanSettleBankCostVo.bankInterest }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方名义价</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleBankCostVo.bankNominalPrice }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方合同违约金</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleBankCostVo.bankContractLiquidated }}</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.loanSettleBankCostVo.bankOtherReceivable }}</span></el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">其他应收说明</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleBankCostVo.otherReceivableRemarks }}</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.loanSettleBankCostVo.bankSettlePrice }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">资方收款账号</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleBankCostVo.bankAccount }}</span></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>
                <el-image class="addinputInfo" style="width: 150px;height: 150px" v-for="(item, index) in formobj.loanSettleBankCostVo.filesList" :key="index" :src="item" :preview-src-list="formobj.loanSettleBankCostVo.filesList" />
              </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 class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.bankOverInterest }}</span></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 class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.companyNominalPrice }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">合同违约金</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.contractLiquidated }}</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.companyOtherPrice }}</span></el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">其他费用说明</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyCostVo.otherCostRemarks }}</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">{{ formobj.loanSettleCompanyCostVo.settleAll }}</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">公司结清费用减免情况</div>
          <div v-if="formobj.trueReduction">
            <el-row>
              <el-col :span="8">
                <div class="span-sty">资金占用费减免</div>
                <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyReductionVo.fundPenalty }}</span></el-form-item>
              </el-col>
              <el-col :span="8">
                <div class="span-sty">贷款保证金扣减减免</div>
                <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyReductionVo.depositPenalty }}</span></el-form-item>
              </el-col>
              <el-col :span="8">
                <div class="span-sty">其他费用减免</div>
                <el-form-item><span class="addinputInfo">{{ formobj.loanSettleCompanyReductionVo.otherCost }}</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">{{ formobj.loanSettleCompanyReductionVo.amountTo }}</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">{{ formobj.loanSettleCompanyReductionVo.profit }}</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 vehiclecollectionrecords from '../overduevehicle/vehiclecollectionrecords'
import financialschemeInfo from '@/components/publicPage/financialschemeInfo'

export default {
  name: 'SettleInfo',
  components: {
    vehiclecollectionrecords,
    financialschemeInfo
  },
  data() {
    return {
      viewTitle: '',
      viewState: 1,
      tableKey: 1,
      index: 0,
      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: ''
      },
      rules: {}
    }
  },
  methods: {
    showInfo(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
          if (this.formobj.loanSettleBankCostVo.filesList.length > 0) {
            const aa = []
            this.formobj.loanSettleBankCostVo.filesList.forEach((e) => {
              aa.push(e.url)
            })
            this.formobj.loanSettleBankCostVo.filesList = 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
    },
    settleByConfirm() {
      const tip = '请再次确认客户已交清所有结清款！'
      this.$confirm(tip, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
        req.confirmAtn({ sid: this.formobj.sid }).then((res) => {
          if (res.success) {
            this.$message({ showClose: true, type: 'success', message: '操作成功' })
            loading.close()
          } else {
            loading.close()
          }
        }).catch(e => {
          loading.close()
        })
      }).catch(() => {
      })

    },
    handleReturn() {
      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.$emit('doback')
    }
  }
}
</script>

<style scoped>
.span-sty {
  width: 200px !important;
}
.addinputInfo {
  margin-left: 190px !important;
}
</style>
