<template>
  <div class="app-container">
    <div class="tab-header webtop">
      <div>{{ viewTitle }}</div>
      <div>
        <el-button type="primary" size="small" :disabled="submitdisabled" @click="saveOrUpdate()">保存</el-button>
        <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
      </div>
    </div>
    <div class="listconadd">、
      <div class="titwu">金融产品政策</div>
      <el-form ref="form_obj" :model="formobj" :rules="rules" class="formaddcopy02">
        <el-row style="border-left: 0px">
          <el-col :span="9" style="border-right: 0px" class="tlineheightb">
            <div class="span-sty" style="border-right: 0px"><span>产品政策名称:</span></div>
            <el-form-item>
              <span class="addinputInfo">{{ formobj.bankShortName }} {{ formobj.period !== '' ? formobj.period + '期' : '' }} {{ formobj.guaranteeTypeValue !== '' ? '( ' + formobj.guaranteeTypeValue + '、' : '' }} {{ formobj.isPack == '1' ? '打包 )' : formobj.isPack == '0' ? '不打包 )' : '' }} {{ formobj.downPayRatio }} {{ formobj.bondRatio !== '' ? '+ ' + formobj.bondRatio : '' }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="15" style="border-right: 0px">
            <div class="span-sty" style="border-right: 0px"><span>适用销售部门:</span></div>
            <el-form-item>
              <el-select class="addinputInfo" v-model="useDept_list" placeholder="请选择" style="width: 60%" clearable filterable multiple>
                <el-option v-for="item in orgList" :key="item.orgDeptSid" :label="item.orgDeptName" :value="item.orgDeptSid"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>资方简称</span></div>
            <el-form-item prop="bankSid">
              <el-select class="addinputInfo" v-model="formobj.bankSid" @change="bankShortChange" placeholder="请选择" clearable filterable>
                <el-option v-for="item in bankShort_list" :key="item.sid" :label="item.name" :value="item.sid"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span>业务类型</span></div>
            <el-form-item>
              <el-select class="addinputInfo" v-model="formobj.busTypeKey" placeholder="请选择" @change="busTypeChange" clearable filterable>
                <el-option v-for="item in busType_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span>车辆大类</span></div>
            <el-form-item>
              <el-select class="addinputInfo" v-model="formobj.vehCategoryKey" placeholder="请选择" @change="vehCategoryChange" clearable filterable>
                <el-option v-for="item in vehCategory_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>车辆功能</span></div>
            <el-form-item>
              <el-select class="addinputInfo" v-model="formobj.vehTypeKeyList" placeholder="请选择" clearable filterable multiple>
                <el-option v-for="item in vehicleFunction_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="6">
            <div class="span-sty"><span><span class="icon">*</span>担保类型</span></div>
            <el-form-item prop="guaranteeTypeKey">
              <el-select class="addinputInfo" v-model="formobj.guaranteeTypeKey" @change="guaranteeTypeChange" placeholder="请选择" clearable filterable>
                <el-option v-for="item in guaranteeType_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>是否打包</span></div>
            <el-form-item prop="isPack">
              <el-radio-group class="addinputInfo" style="font-size: 1px" v-model="formobj.isPack">
                <el-radio label="1">是</el-radio>
                <el-radio label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>首付比例</span></div>
            <el-form-item prop="downPayRatioKey">
              <el-select class="addinputInfo" v-model="formobj.downPayRatioKey" @change="downPayRatioChange" placeholder="请选择" clearable filterable>
                <el-option v-for="item in downPayRatio_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>最低首付比例</span></div>
            <el-form-item prop="downPayRatioLeastKey">
              <el-select class="addinputInfo" v-model="formobj.downPayRatioLeastKey" @change="downPayRatioLeastChange" placeholder="请选择" clearable filterable>
                <el-option v-for="item in downPayRatioLeast_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="6">
            <div class="span-sty"><span><span class="icon">*</span>保证金比例</span></div>
            <el-form-item prop="bondRatioKey">
              <el-select class="addinputInfo" v-model="formobj.bondRatioKey" @change="bondRatioChange" placeholder="请选择" clearable filterable>
                <el-option v-for="item in bondRatio_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>保证金类型</span></div>
            <el-form-item prop="bondTypeKey">
              <el-select class="addinputInfo" v-model="formobj.bondTypeKey" @change="bondTypeChange" placeholder="请选择" clearable filterable>
                <el-option v-for="item in bondType_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>期数</span></div>
            <el-form-item prop="periodKey">
              <el-select class="addinputInfo" v-model="formobj.periodKey" @change="periodChange" placeholder="请选择" clearable filterable>
                <el-option v-for="item in period_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>标准年利率(%)</span></div>
            <el-form-item prop="yearRatio">
              <el-input v-model="formobj.yearRatio" @keyup.native="UpNumber" class="addinputInfo" clearable placeholder=""/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>服务费类型</span></div>
            <el-form-item prop="serviceAmountTypeKey">
              <el-select class="addinputInfo" v-model="formobj.serviceAmountTypeKey" @change="serviceAmountTypeChange" placeholder="请选择" clearable filterable>
                <el-option v-for="item in serviceAmountType_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>服务费<span v-show="formobj.serviceAmountTypeValue !== '固定金额'">(%)</span><span v-show="formobj.serviceAmountTypeValue === '固定金额'">(元)</span></span></div>
            <el-form-item prop="serviceAmount">
              <el-input v-model="formobj.serviceAmount" @keyup.native="UpNumber" class="addinputInfo" clearable placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span>保险保证金(元)</span></div>
            <el-form-item>
              <el-input v-model="formobj.depositPremium" @keyup.native="UpNumber" class="addinputInfo" clearable placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span>落户保证金(元)</span></div>
            <el-form-item>
              <el-input v-model="formobj.depositSettle" @keyup.native="UpNumber" class="addinputInfo" clearable placeholder=""/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <div class="span-sty"><span>单车意外险/年(元)</span></div>
            <el-form-item>
              <el-input v-model="formobj.vehAccidentAmount" @keyup.native="UpNumber" class="addinputInfo" clearable placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span>名义/留购价款(元)</span></div>
            <el-form-item>
              <el-input v-model="formobj.nominalPrice" @keyup.native="UpNumber" class="addinputInfo" clearable placeholder=""/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>贴息放款类型</span></div>
            <el-form-item prop="discountUseTypeKey">
              <el-select class="addinputInfo" v-model="formobj.discountUseTypeKey" @change="discountUseTypeChange" placeholder="请选择" clearable filterable>
                <el-option v-for="item in discountUseType_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="span-sty"><span><span class="icon">*</span>有效期至</span></div>
            <el-form-item prop="validDateTo">
              <el-date-picker class="addinputInfo" value-format="yyyy-MM-dd" format="yyyy-MM-dd" v-model="formobj.validDateTo" type="date" placeholder="选择日期"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="span-sty"><span>备注</span></div>
            <el-form-item>
              <el-input v-model="formobj.remarks" class="addinputw addinputInfo" clearable placeholder=""/>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="title"><el-checkbox v-model="formobj.isOtherProduct" @change="changeIsOtherProduct" style="padding-right: 5px"/>其它融信息</div>
        <div v-if="formobj.isOtherProduct">
          <el-row>
            <el-col :span="6">
              <div class="span-sty"><span><span class="icon">*</span>产品类别</span></div>
              <el-form-item prop="productTypeKey">
                <el-select class="addinputInfo" v-model="formobj.loanFinOtherPolicy.productTypeKey" @change="productTypeChange" placeholder="请选择" clearable filterable>
                  <el-option v-for="item in productType_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <div class="span-sty"><span><span class="icon">*</span>最高融资比例(%)</span></div>
              <el-form-item prop="maxLoanRatio">
                <el-input v-model="formobj.loanFinOtherPolicy.maxLoanRatio" @keyup.native="UpNumber" class="addinputInfo" clearable placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <div class="span-sty"><span><span class="icon">*</span>最高融资额(元)</span></div>
              <el-form-item prop="maxLoanAmount">
                <el-input v-model="formobj.loanFinOtherPolicy.maxLoanAmount" @keyup.native="UpNumber" class="addinputInfo" clearable placeholder=""/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <div class="span-sty"><span><span class="icon">*</span>期数</span></div>
              <el-form-item>
                <el-select class="addinputInfo" v-model="formobj.loanFinOtherPolicy.periodKey" @change="periodQTRChange" placeholder="请选择" clearable filterable>
                  <el-option v-for="item in period_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <div class="span-sty"><span><span class="icon">*</span>年利率(%)</span></div>
              <el-form-item>
                <el-input v-model="formobj.loanFinOtherPolicy.yearRatio" @keyup.native="UpNumber" class="addinputInfo" clearable placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :span="12" />
          </el-row>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
import req from '@/api/financialpolicymanagement/financialpolicymanagement'
import { typeValues, selectOrgList, selectListByOrgPath } from '@/api/Common/dictcommons'

export default {
  name: 'FinancialPolicyManagementAdd',
  data() {
    return {
      viewTitle: '',
      submitdisabled: false,
      orgList: [],
      useDept_list: [],
      bankShort_list: [],
      busType_list: [],
      vehCategory_list: [],
      vehicleFunction_list: [],
      serviceAmountType_list: [],
      discountUseType_list:[],
      guaranteeType_list: [],
      downPayRatio_list: [],
      bondRatio_list: [],
      bondType_list: [],
      period_list: [],
      downPayRatioLeast_list: [],
      productType_list: [],
      formobj: {
        bankShortName: '',
        bankSid: '',
        bondRatio: '',
        bondRatioKey: '',
        bondType: '',
        bondTypeKey: '',
        busTypeKey: '',
        busTypeValue: '',
        depositPremium: '',
        depositSettle: '',
        downPayRatio: '',
        downPayRatioKey: '',
        downPayRatioLeast: '',
        downPayRatioLeastKey: '',
        guaranteeTypeKey: '',
        guaranteeTypeValue: '',
        isOtherProduct: false,
        discountUseType: '',
        discountUseTypeKey: '',
        isPack: '',
        loanFinOtherPolicy: {
          maxLoanAmount: '',
          maxLoanRatio: '',
          period: '',
          periodKey: '',
          productTypeKey: '',
          productTypeValue: '',
          yearRatio: ''
        },
        nominalPrice: '',
        orgPath: '',
        period: '',
        periodKey: '',
        policyName: '',
        remarks: '',
        serviceAmount: '',
        serviceAmountTypeKey: '',
        serviceAmountTypeValue: '',
        sid: '',
        useDeptList: [],
        userSid: '',
        validDateTo: '',
        vehAccidentAmount: '',
        vehCategoryKey: '',
        vehCategoryValue: '',
        vehTypeKeyList: [],
        vehTypeValueList: [],
        yearRatio: ''
      },
      rules: {
        bankSid: [{ required: true, message: '资方简称不能为空', trigger: 'change' }],
        guaranteeTypeKey: [{ required: true, message: '担保类型不能为空', trigger: 'change' }],
        isPack: [{ required: true, message: '是否打包不能为空', trigger: 'change' }],
        downPayRatioKey: [{ required: true, message: '首付比例不能为空', trigger: 'change' }],
        downPayRatioLeastKey: [{ required: true, message: '最低首付比例不能为空', trigger: 'change' }],
        bondRatioKey: [{ required: true, message: '保证金比例不能为空', trigger: 'change' }],
        bondTypeKey: [{ required: true, message: '保证金类型不能为空', trigger: 'change' }],
        periodKey: [{ required: true, message: '期数不能为空', trigger: 'change' }],
        yearRatio: [{ required: true, message: '标准年利率不能为空', trigger: 'blur' }],
        serviceAmountTypeKey: [{ required: true, message: '服务费类型不能为空', trigger: 'change' }],
        serviceAmount: [{ required: true, message: '服务费不能为空', trigger: 'blur' }],
        discountUseTypeKey: [{ required: true, message: '贴息放款类型不能为空', trigger: 'change' }],
        validDateTo: [{ required: true, message: '有效期不能为空', trigger: 'change' }]
      }
    }
  },
  methods: {
    init() {
      typeValues({ type: 'busType' }).then((resp) => {
        if (resp.success) {
          this.busType_list = resp.data
        }
      })
      typeValues({ type: 'vehCategory' }).then((resp) => {
        if (resp.success) {
          this.vehCategory_list = resp.data
        }
      })
      typeValues({ type: 'vehicleFunction' }).then((resp) => {
        if (resp.success) {
          this.vehicleFunction_list = resp.data
        }
      })
      typeValues({ type: 'serviceAmountType' }).then((resp) => {
        if (resp.success) {
          this.serviceAmountType_list = resp.data
        }
      })
      typeValues({ type: 'discountUseType' }).then((resp) => {
        if (resp.success) {
          this.discountUseType_list = resp.data
        }
      })
      typeValues({ type: 'guaranteeType' }).then((resp) => {
        if (resp.success) {
          this.guaranteeType_list = resp.data
        }
      })
      typeValues({ type: 'downPayRatio' }).then((resp) => {
        if (resp.success) {
          this.downPayRatio_list = resp.data
        }
      })
      typeValues({ type: 'bondRatio' }).then((resp) => {
        if (resp.success) {
          this.bondRatio_list = resp.data
        }
      })
      typeValues({ type: 'bondType' }).then((resp) => {
        if (resp.success) {
          this.bondType_list = resp.data
        }
      })
      typeValues({ type: 'period' }).then((resp) => {
        if (resp.success) {
          this.period_list = resp.data
        }
      })
      typeValues({ type: 'downPayRatioLeast' }).then((resp) => {
        if (resp.success) {
          this.downPayRatioLeast_list = resp.data
        }
      })
      typeValues({ type: 'productType' }).then((resp) => {
        if (resp.success) {
          this.productType_list = resp.data
        }
      })
      selectOrgList({ userSid: window.sessionStorage.getItem('userSid'), orgPath: window.sessionStorage.getItem('defaultOrgPath') }).then((res) => {
        if (res.success) {
          this.orgList = res.data
        }
      })
      selectListByOrgPath({ orgPath: window.sessionStorage.getItem('defaultOrgPath') }).then((res) => {
        if (res.success) {
          this.bankShort_list = res.data
        }
      })
    },
    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() {
      this.viewTitle = '【新增】金融产品政策'
      this.init()
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      this.formobj.isOtherProduct = false
      this.formobj.userSid = window.sessionStorage.getItem('userSid')
      this.formobj.orgPath = window.sessionStorage.getItem('defaultOrgPath')
    },
    showEdit(row) {
      this.viewTitle = '【编辑】金融产品政策'
      this.init()
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      req.fetchBySid({ sid: row.sid }).then((resp) => {
        if (resp.success) {
          this.formobj = resp.data
          this.formobj.isPack = this.formobj.isPack.toString()
          if (this.formobj.useDeptSids !== '' && this.formobj.useDeptSids !== null) {
            this.useDept_list = this.formobj.useDeptSids.split(',')
          }
        }
      })
    },
    bankShortChange(value) {
      const choose = this.bankShort_list.filter((item) => item.sid === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.bankShortName = choose[0].name
      } else {
        this.formobj.bankShortName = ''
      }
    },
    busTypeChange(value) {
      const choose = this.busType_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.busTypeValue = choose[0].dictValue
      } else {
        this.formobj.busTypeValue = ''
      }
    },
    vehCategoryChange(value) {
      const choose = this.vehCategory_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.vehCategoryValue = choose[0].dictValue
      } else {
        this.formobj.vehCategoryValue = ''
      }
    },
    guaranteeTypeChange(value) {
      const choose = this.guaranteeType_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.guaranteeTypeValue = choose[0].dictValue
      } else {
        this.formobj.guaranteeTypeValue = ''
      }
    },
    downPayRatioChange(value) {
      const choose = this.downPayRatio_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.downPayRatio = choose[0].dictValue
      } else {
        this.formobj.downPayRatio = ''
      }
    },
    bondRatioChange(value) {
      const choose = this.bondRatio_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.bondRatio = choose[0].dictValue
      } else {
        this.formobj.bondRatio = ''
      }
    },
    bondTypeChange(value) {
      const choose = this.bondType_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.bondType = choose[0].dictValue
      } else {
        this.formobj.bondType = ''
      }
    },
    periodChange(value) {
      const choose = this.period_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.period = choose[0].dictValue
      } else {
        this.formobj.period = ''
      }
    },
    serviceAmountTypeChange(value) {
      const choose = this.serviceAmountType_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.serviceAmountTypeValue = choose[0].dictValue
      } else {
        this.formobj.serviceAmountTypeValue = ''
      }
    },
    discountUseTypeChange(value) {
      const choose = this.discountUseType_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.discountUseType = choose[0].dictValue
      } else {
        this.formobj.discountUseType = ''
      }
    },
    downPayRatioLeastChange(value) {
      const choose = this.downPayRatioLeast_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.downPayRatioLeast = choose[0].dictValue
      } else {
        this.formobj.downPayRatioLeast = ''
      }
    },
    productTypeChange(value) {
      const choose = this.productType_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.loanFinOtherPolicy.productTypeValue = choose[0].dictValue
      } else {
        this.formobj.loanFinOtherPolicy.productTypeValue = ''
      }
    },
    periodQTRChange(value) {
      const choose = this.period_list.filter((item) => item.dictKey === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.loanFinOtherPolicy.period = choose[0].dictValue
      } else {
        this.formobj.loanFinOtherPolicy.period = ''
      }
    },
    changeIsOtherProduct(value) {
      if (value) {
        this.formobj.loanFinOtherPolicy.period = this.formobj.period
        this.formobj.loanFinOtherPolicy.periodKey = this.formobj.periodKey
      }
    },
    saveOrUpdate() {
      this.$refs['form_obj'].validate((valid) => {
        if (valid) {
          if (this.formobj.isOtherProduct) {
            if (this.formobj.loanFinOtherPolicy.productTypeKey === '') {
              this.$message({ showClose: true, type: 'error', message: '其它融中产品类别不能为空' })
              return
            }
            if (this.formobj.loanFinOtherPolicy.maxLoanRatio === '') {
              this.$message({ showClose: true, type: 'error', message: '其它融中最高融资比例不能为空' })
              return
            }
            if (this.formobj.loanFinOtherPolicy.maxLoanAmount === '') {
              this.$message({ showClose: true, type: 'error', message: '其它融中最高融资额不能为空' })
              return
            }
            if (this.formobj.loanFinOtherPolicy.periodKey === '') {
              this.$message({ showClose: true, type: 'error', message: '其它融中期数不能为空' })
              return
            }
            if (this.formobj.loanFinOtherPolicy.yearRatio === '') {
              this.$message({ showClose: true, type: 'error', message: '其它融中年利率不能为空' })
              return
            }
          }
          if (this.useDept_list.length > 0) {
            const aa = []
            for (var i = 0; i < this.orgList.length; i++) {
              for (var k = 0; k < this.useDept_list.length; k++) {
                if (this.orgList[i].orgDeptSid === this.useDept_list[k]) {
                  aa.push({
                    deptName: this.orgList[i].orgDeptName,
                    deptSid: this.orgList[i].orgDeptSid
                  })
                }
              }
            }
            this.formobj.useDeptList = aa
          }
          if (this.formobj.vehTypeKeyList.length > 0) {
            const aa = []
            for (var m = 0; m < this.vehicleFunction_list.length; m++) {
              for (var n = 0; n < this.formobj.vehTypeKeyList.length; n++) {
                if (this.vehicleFunction_list[m].dictKey === this.formobj.vehTypeKeyList[n]) {
                  aa.push(this.vehicleFunction_list[m].dictValue)
                }
              }
            }
            this.formobj.vehTypeValueList = aa
          } else {
            this.$message({ showClose: true, type: 'error', message: '车辆功能不能为空' })
            this.formobj.vehTypeValueList = []
            return
          }
          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
          })
        }
      })
    },
    handleReturn(isreload) {
      if (isreload === 'true') this.$emit('reloadlist')
      this.formobj = {
        bankShortName: '',
        bankSid: '',
        bondRatio: '',
        bondRatioKey: '',
        bondType: '',
        bondTypeKey: '',
        busTypeKey: '',
        busTypeValue: '',
        depositPremium: '',
        depositSettle: '',
        downPayRatio: '',
        downPayRatioKey: '',
        downPayRatioLeast: '',
        downPayRatioLeastKey: '',
        guaranteeTypeKey: '',
        guaranteeTypeValue: '',
        isOtherProduct: false,
        isPack: '',
        discountUseType: '',
        discountUseTypeKey: '',
        loanFinOtherPolicy: {
          maxLoanAmount: '',
          maxLoanRatio: '',
          period: '',
          periodKey: '',
          productTypeKey: '',
          productTypeValue: '',
          yearRatio: ''
        },
        nominalPrice: '',
        orgPath: '',
        period: '',
        periodKey: '',
        policyName: '',
        serviceAmount: '',
        serviceAmountTypeKey: '',
        serviceAmountTypeValue: '',
        sid: '',
        useDeptList: [],
        userSid: '',
        validDateTo: '',
        vehAccidentAmount: '',
        vehCategoryKey: '',
        vehCategoryValue: '',
        vehTypeKeyList: [],
        vehTypeValueList: [],
        yearRatio: ''
      }
      this.useDept_list = []
      this.submitdisabled = false
      this.$refs['form_obj'].resetFields()
      this.$emit('doback')
    }
  }
}
</script>

<style scoped>
.span-sty {
  width: 140px !important;
}
.addinputInfo {
  margin-left: 130px !important;
  width: calc(100% - 135px);
}
.tlineheightb {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
}
/deep/ .tlineheightb .el-form-item .el-form-item__content .addinputInfo {
  line-height: 15px !important;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: center;
}
/deep/ .el-form-item__error {
  margin-left: 130px !important;
}
</style>
