<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>
        </div>
      </div>
      <div class="">
        <el-form ref="form_obj" :model="formobj" :rules="rules" class="formaddcopy02">
          <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.createDate }}</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.locationName }}</span></el-form-item>
            </el-col>
          </el-row>
          <div class="title titleOne">
            <div>二次销售车辆列表(含主车、挂车)</div>
            <el-button size="mini" type="primary" class="btntopblueline" @click="lookFinancial">金融方案</el-button>
          </div>
          <el-table :key="tableKey" :data="formobj.loanSecondarySalesVehVoList" :index="index" border style="width: 100%">
            <el-table-column fixed width="80" label="序号" type="index" :index="index + 1" align="center"/>
            <el-table-column fixed label="操作" width="80" align="center">
              <template slot-scope="scope">
                <el-button size="small" type="danger" @click="delete(scope.$index)">删除</el-button>
              </template>
            </el-table-column>
            <el-table-column prop="vinNo" label="车架号" align="center" min-width="100" />
            <el-table-column prop="vehMark" label="车牌号" align="center" min-width="100"/>
            <el-table-column prop="vehType" label="车辆类型" align="center" min-width="120"/>
            <el-table-column prop="modelName" label="车型" align="center" min-width="130"/>
          </el-table>
          <div class="title">车辆状况</div>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">是否年检</div>
              <el-form-item>
                <el-radio-group class="addinputInfo" style="font-size: 1px" v-model="formobj.inspect">
                  <el-radio label="是">是</el-radio>
                  <el-radio label="否">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">年检情况</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.inspectSituation" clearable placeholder=""/></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">是否已出保</div>
              <el-form-item>
                <el-radio-group class="addinputInfo" style="font-size: 1px" v-model="formobj.guaranteed">
                  <el-radio label="是">是</el-radio>
                  <el-radio label="否">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">保险情况</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.insuranceSituation" 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">{{ formobj.firstDate }}</span></el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">当前行驶公里数</div>
              <el-form-item><el-input class="addinputInfo" style="width: 30%" v-model="formobj.kilometerDriven" clearable placeholder=""/></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.illustrate" clearable placeholder=""/></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.filesList" :key="index" :src="item" :preview-src-list="formobj.filesList"/>
              </el-form-item>
            </el-col>
          </el-row>
          <div class="title">已还与欠款情况</div>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">已还金额</div>
              <el-form-item><span class="addinputInfo">{{ formobj.alRepaidMoney }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">当前逾期金额/其中资金占用费</div>
              <el-form-item><span class="addinputInfo">{{ formobj.currentBeMoney }}/{{ formobj.wheFundOccMoney }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">未到期金额</div>
              <el-form-item><span class="addinputInfo">{{ formobj.unexpiredMoney }}</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.nper }}/{{ formobj.currentPeriod }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">已还金额换算期数</div>
              <el-form-item><span class="addinputInfo">{{ formobj.alRepaidMoneyConPeriod }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">逾期金额换算期数</div>
              <el-form-item><span class="addinputInfo">{{ formobj.beOverdueMoneyAndPeriod }}</span></el-form-item>
            </el-col>
          </el-row>
          <div class="title">费用说明</div>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">欠款合计</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSecondarySalesCost.arrearsAll }}</span></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">贷款保证金</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSecondarySalesCost.loanDeposit }}</span></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.loanSecondarySalesCost.vehPrice" clearable placeholder=""/></el-form-item>
            </el-col>
          </el-row>
          <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.loanSecondarySalesCost.collectionCost" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">风控中心车辆评估价</div>
              <el-form-item><span class="addinputInfo">{{ formobj.loanSecondarySalesCost.vehicleEvaluation }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <span style="color: red;font-weight: bold">注：以下费用客户自行处理的无需录入</span>
            </el-col>
          </el-row>
          <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.loanSecondarySalesCost.bankSettleCost" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">承担方</div>
              <el-form-item>
                <el-select class="addinputInfo" v-model="formobj.loanSecondarySalesCost.bankSettleCostAssumeKey" placeholder="请选择" clearable filterable @change="bankSettleCostChange">
                  <el-option v-for="item in bearer_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <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.loanSecondarySalesCost.vehicleViolationCost" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">承担方</div>
              <el-form-item>
                <el-select class="addinputInfo" v-model="formobj.loanSecondarySalesCost.vehicleViolationCostAssumeKey" placeholder="请选择" clearable filterable @change="vehicleViolationCostChange">
                  <el-option v-for="item in bearer_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <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.loanSecondarySalesCost.inspectYearCost" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">承担方</div>
              <el-form-item>
                <el-select class="addinputInfo" v-model="formobj.loanSecondarySalesCost.inspectYearCostAssumeKey" placeholder="请选择" clearable filterable @change="inspectYearCostChange">
                  <el-option v-for="item in bearer_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <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.loanSecondarySalesCost.insureCost" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">承担方</div>
              <el-form-item>
                <el-select class="addinputInfo" v-model="formobj.loanSecondarySalesCost.insureCostAssumeKey" placeholder="请选择" clearable filterable @change="insureCostChange">
                  <el-option v-for="item in bearer_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <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.loanSecondarySalesCost.ownershipCost" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">承担方</div>
              <el-form-item>
                <el-select class="addinputInfo" v-model="formobj.loanSecondarySalesCost.ownershipCostAssumeKey" placeholder="请选择" clearable filterable @change="ownershipCostChange">
                  <el-option v-for="item in bearer_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <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.loanSecondarySalesCost.stopCost" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">承担方</div>
              <el-form-item>
                <el-select class="addinputInfo" v-model="formobj.loanSecondarySalesCost.stopCostAssumeKey" placeholder="请选择" clearable filterable @change="stopCostChange">
                  <el-option v-for="item in bearer_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <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.loanSecondarySalesCost.otherCost" clearable placeholder=""/></el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">承担方</div>
              <el-form-item>
                <el-select class="addinputInfo" v-model="formobj.loanSecondarySalesCost.otherCostAssumeKey" placeholder="请选择" clearable filterable @change="otherCostChange">
                  <el-option v-for="item in bearer_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <div class="span-sty">费用说明</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.loanSecondarySalesCost.costDescription" clearable placeholder=""/></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <div class="span-sty">购方应交总金额</div>
              <el-form-item><span class="addinputInfo">{{ purchaserMoney }}</span></el-form-item>
            </el-col>
            <el-col :span="12">
              <div class="span-sty" style="color: red">竞价结果</div>
              <el-form-item><span class="addinputInfo">{{ formobj.result }}</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">{{ lossPrice }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <div class="span-sty">是否追偿</div>
              <el-form-item>
                <el-radio-group class="addinputInfo" disabled v-model="formobj.loanSecondarySalesCost.isRecovery">
                  <el-radio label="1">是</el-radio>
                  <el-radio label="0">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <div class="span-sty">后续欠款处置方向</div>
              <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.loanSecondarySalesCost.debtDisposal" clearable placeholder=""/></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty">附件</div>
              <el-form-item>
                <uploadImg ref="uploadImg" class="addinputInfo" v-model="formobj.loanSecondarySalesCost.files" :limit="50" bucket="map" :upload-data="{ type: '0001' }"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
    <!-- 查看车辆历史催收记录 -->
    <financialschemeInfo v-show="viewState == 2" ref="divFinancial" @doback="resetState" />
  </div>
</template>

<script>
import req from '@/api/secondarysales/secondarysales'
import { typeValues } from '@/api/Common/dictcommons'
import uploadImg from '@/components/uploadFile/uploadImg'
import financialschemeInfo from '../publicPage/financialschemeInfo'

export default {
  name: 'SecondarySalesEdit',
  components: {
    uploadImg,
    financialschemeInfo
  },
  data() {
    return {
      viewTitle: '',
      viewState: 1,
      submitdisabled: false,
      tableKey: 1,
      index: 0,
      bearer_list: [],
      formobj: {
        alRepaidMoney: '',
        alRepaidMoneyConPeriod: '',
        bankContractNo: '',
        bankName: '',
        beOverdueMoneyAndPeriod: '',
        createByName: '',
        createDate: '',
        createDept: '',
        createDeptSid: '',
        currentBeMoney: '',
        currentPeriod: '',
        customerName: '',
        files: '',
        filesList: [],
        firstDate: '',
        guaranteed: '',
        illustrate: '',
        inspect: '',
        inspectSituation: '',
        insuranceSituation: '',
        kilometerDriven: '',
        loanContractNo: '',
        loanName: '',
        loanSecondarySalesCost: {
          arrearsAll: '',
          bankSettleCost: '',
          bankSettleCostAssume: '',
          bankSettleCostAssumeKey: '',
          collectionCost: '',
          costDescription: '',
          isRecovery: '',
          debtDisposal: '',
          files: [],
          inspectYearCost: '',
          inspectYearCostAssume: '',
          inspectYearCostAssumeKey: '',
          insureCost: '',
          insureCostAssume: '',
          insureCostAssumeKey: '',
          loanDeposit: '',
          lossPrice: '',
          otherCost: '',
          otherCostAssume: '',
          otherCostAssumeKey: '',
          ownershipCost: '',
          ownershipCostAssume: '',
          ownershipCostAssumeKey: '',
          stopCost: '',
          stopCostAssume: '',
          stopCostAssumeKey: '',
          vehPrice: '',
          vehicleEvaluation: '',
          vehicleViolationCost: '',
          vehicleViolationCostAssume: '',
          vehicleViolationCostAssumeKey: ''
        },
        loanSecondarySalesVehVoList: [],
        locationName: '',
        nper: '',
        orgPath: '',
        procInstId: '',
        salesOrderSid: '',
        sid: '',
        taskId: '',
        unexpiredMoney: '',
        useOrgSid: '',
        userSid: '',
        result: '',
        wheFundOccMoney: ''
      },
      rules: {}
    }
  },
  created() {
    console.log('url:' + window.location.href)
    var one = window.location.href.indexOf('&data') + 6
    const data = window.location.href.substr(one) // url解码unescape()已从web中移除,尽量不使用
    const obj = JSON.parse(decodeURIComponent(data))
    this.showInfo(obj.businessSid)
  },
  mounted() {
    window.parent.postMessage({
      cmd: 'returnHeight',
      params: {
        // 告诉父级页面，子页面的弹框高度。
        code: 2,
        data: 500 + 'px'
      }
    }, '*')
  },
  computed: {
    // 计算购方应交总金额 = 车辆售价 + 承担方为购方的各项费用
    purchaserMoney() {
      let money = 0
      money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.vehPrice !== '' ? this.formobj.loanSecondarySalesCost.vehPrice : 0)) * 100) / 100
      // 资方结清费用不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.bankSettleCost !== '' && this.formobj.loanSecondarySalesCost.bankSettleCostAssume === '购方') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.bankSettleCost)) * 100) / 100
      }
      // 车辆违章费用不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.vehicleViolationCost !== '' && this.formobj.loanSecondarySalesCost.vehicleViolationCostAssume === '购方') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.vehicleViolationCost)) * 100) / 100
      }
      // 年检费不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.inspectYearCost !== '' && this.formobj.loanSecondarySalesCost.inspectYearCostAssume === '购方') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.inspectYearCost)) * 100) / 100
      }
      // 保险费不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.insureCost !== '' && this.formobj.loanSecondarySalesCost.insureCostAssume === '购方') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.insureCost)) * 100) / 100
      }
      // 过户费不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.ownershipCost !== '' && this.formobj.loanSecondarySalesCost.ownershipCostAssume === '购方') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.ownershipCost)) * 100) / 100
      }
      // 停车费不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.stopCost !== '' && this.formobj.loanSecondarySalesCost.stopCostAssume === '购方') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.stopCost)) * 100) / 100
      }
      // 其他费用不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.otherCost !== '' && this.formobj.loanSecondarySalesCost.otherCostAssume === '购方') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.otherCost)) * 100) / 100
      }
      return money
    },
    // 计算预计亏损金额 = 欠款合计 - 贷款保证金 - 车辆售价 + 催收费用 + 承担方为公司的各项费用
    lossPrice() {
      let money = 0
      if (this.formobj.loanSecondarySalesCost.loanDeposit !== '' && this.formobj.loanSecondarySalesCost.loanDeposit !== null) {
        money = Math.round((parseFloat(this.formobj.loanSecondarySalesCost.arrearsAll) - parseFloat(this.formobj.loanSecondarySalesCost.loanDeposit)) * 100) / 100
      }
      // 车辆售价不等于空
      if (this.formobj.loanSecondarySalesCost.vehPrice !== '') {
        money = Math.round((parseFloat(money) - parseFloat(this.formobj.loanSecondarySalesCost.vehPrice)) * 100) / 100
      }
      // 催收费用不等于空
      if (this.formobj.loanSecondarySalesCost.collectionCost !== '') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.collectionCost)) * 100) / 100
      }
      // 资方结清费用不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.bankSettleCost !== '' && this.formobj.loanSecondarySalesCost.bankSettleCostAssume === '公司') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.bankSettleCost)) * 100) / 100
      }
      // 车辆违章费用不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.vehicleViolationCost !== '' && this.formobj.loanSecondarySalesCost.vehicleViolationCostAssume === '公司') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.vehicleViolationCost)) * 100) / 100
      }
      // 年检费不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.inspectYearCost !== '' && this.formobj.loanSecondarySalesCost.inspectYearCostAssume === '公司') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.inspectYearCost)) * 100) / 100
      }
      // 保险费不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.insureCost !== '' && this.formobj.loanSecondarySalesCost.insureCostAssume === '公司') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.insureCost)) * 100) / 100
      }
      // 过户费不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.ownershipCost !== '' && this.formobj.loanSecondarySalesCost.ownershipCostAssume === '公司') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.ownershipCost)) * 100) / 100
      }
      // 停车费不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.stopCost !== '' && this.formobj.loanSecondarySalesCost.stopCostAssume === '公司') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.stopCost)) * 100) / 100
      }
      // 其他费用不等于空且承担方为公司
      if (this.formobj.loanSecondarySalesCost.otherCost !== '' && this.formobj.loanSecondarySalesCost.otherCostAssume === '公司') {
        money = Math.round((parseFloat(money) + parseFloat(this.formobj.loanSecondarySalesCost.otherCost)) * 100) / 100
      }
      return money
    }
  },
  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)
      }
    },
    init() {
      typeValues({ type: 'costAssume' }).then((resp) => {
        if (resp.success) {
          this.bearer_list = resp.data
        }
      })
    },
    created() {
      console.log('url:' + window.location.href)
      var one = window.location.href.indexOf('&data') + 6
      const data = window.location.href.substr(one) // url解码unescape()已从web中移除,尽量不使用
      const obj = JSON.parse(decodeURIComponent(data))
      this.showInfo(obj.businessSid)
    },
    mounted() {
      window.parent.postMessage({
        cmd: 'returnHeight',
        params: {
          // 告诉父级页面，子页面的弹框高度。
          code: 2,
          data: 500 + 'px'
        }
      }, '*')
    },
    showInfo(sid) {
      this.viewTitle = '【编辑】交回车辆二次销售申请'
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      this.init()
      req.fetchBySid({ chooseSidList: [], orgPath: '', sid: sid, userSid: '' }).then((res) => {
        if (res.success) {
          this.formobj = res.data
          this.formobj.instanceId = res.data.procInstId
        }
      })
    },
    lookFinancial() {
      req.selectDetailss({ businessSid: this.formobj.salesOrderSid }).then((res) => {
        if (res.success) {
          this.viewState = 2
          this.$refs['divFinancial'].showInfo(res.data, '03')
        }
      })
    },
    delete(index) {
      this.formobj.loanSecondarySalesVehVoList.splice(index, 1)
    },
    bankSettleCostChange(value) {
      const choose = this.bearer_list.filter((item) => item.dictKey === value)
      if (choose.length > 0 && choose !== null) {
        this.formobj.loanSecondarySalesCost.bankSettleCostAssume = choose[0].dictValue
      } else {
        this.formobj.loanSecondarySalesCost.bankSettleCostAssume = ''
      }
    },
    vehicleViolationCostChange(value) {
      const choose = this.bearer_list.filter((item) => item.dictKey === value)
      if (choose.length > 0 && choose !== null) {
        this.formobj.loanSecondarySalesCost.vehicleViolationCostAssume = choose[0].dictValue
      } else {
        this.formobj.loanSecondarySalesCost.vehicleViolationCostAssume = ''
      }
    },
    inspectYearCostChange(value) {
      const choose = this.bearer_list.filter((item) => item.dictKey === value)
      if (choose.length > 0 && choose !== null) {
        this.formobj.loanSecondarySalesCost.inspectYearCostAssume = choose[0].dictValue
      } else {
        this.formobj.loanSecondarySalesCost.inspectYearCostAssume = ''
      }
    },
    insureCostChange(value) {
      const choose = this.bearer_list.filter((item) => item.dictKey === value)
      if (choose.length > 0 && choose !== null) {
        this.formobj.loanSecondarySalesCost.insureCostAssume = choose[0].dictValue
      } else {
        this.formobj.loanSecondarySalesCost.insureCostAssume = ''
      }
    },
    ownershipCostChange(value) {
      const choose = this.bearer_list.filter((item) => item.dictKey === value)
      if (choose.length > 0 && choose !== null) {
        this.formobj.loanSecondarySalesCost.ownershipCostAssume = choose[0].dictValue
      } else {
        this.formobj.loanSecondarySalesCost.ownershipCostAssume = ''
      }
    },
    stopCostChange(value) {
      const choose = this.bearer_list.filter((item) => item.dictKey === value)
      if (choose.length > 0 && choose !== null) {
        this.formobj.loanSecondarySalesCost.stopCostAssume = choose[0].dictValue
      } else {
        this.formobj.loanSecondarySalesCost.stopCostAssume = ''
      }
    },
    otherCostChange(value) {
      const choose = this.bearer_list.filter((item) => item.dictKey === value)
      if (choose.length > 0 && choose !== null) {
        this.formobj.loanSecondarySalesCost.otherCostAssume = choose[0].dictValue
      } else {
        this.formobj.loanSecondarySalesCost.otherCostAssume = ''
      }
    },
    resetState() {
      this.viewState = 1
    },
    saveOrUpdate() {
      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: '保存成功' })
              // 子页面向父级页面传递值(关闭弹框)
              window.parent.postMessage({
                cmd: 'returnHeight',
                params: {
                  // 操作成功，告诉父级页面关闭弹框
                  code: 1
                }
              }, '*')
            } else {
              this.submitdisabled = false
            }
          }).catch(() => {
            this.submitdisabled = false
          })
        }
      })
    },
    submit() {
      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: '操作成功' })
              // 子页面向父级页面传递值(关闭弹框)
              window.parent.postMessage({
                cmd: 'returnHeight',
                params: {
                  // 操作成功，告诉父级页面关闭弹框
                  code: 1
                }
              }, '*')
            } else {
              this.submitdisabled = false
            }
          }).catch(() => {
            this.submitdisabled = false
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.span-sty {
  width: 200px !important;
}
.addinputInfo {
  margin-left: 190px !important;
}
.formaddcopy02 .el-row .el-col /deep/ .el-form-item .addinputw {
  margin-left: 190px !important;
  width: calc(100% - 185px);
}
.titleOne {
  padding: 7px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}
</style>
