projectService.js 8.07 KB
Newer Older
Nature's avatar
Nature committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
export default {
  /**
   * 项目基本信息
   */
  carFlag: 0,
  clientInfoFlag: 0,
  offerFlag: 0,
  attachFlag: 0,
  project: {
    project_id: '',
    cdd_list_id: '',
    project_name: '',
    invoice_agent_id: null,
    invoice_agent_id_n: null,
    bp_class: null,
    bp_class_n: null,
    business_type: null,
    business_type_n: null,
    division: null,
    division_n: null,
    car_type: null,
    car_type_n: null,
    user_id: window.localStorage.user_id,
  },
  /**
   * 租赁物信息
   */
  lease: {
    project_id: '',
    business_type: '',
    user_id: window.localStorage.user_id,
    brand_id: null,
    brand_id_n: null,
    series_id: null,
    series_id_n: null,
    model_id: null,
    model_id_n: null,
    guide_price: null,
    objective_buy_car: null,
    objective_buy_car_n: null,
    invoice_price: null,
    lease_charge: 0,
    insurance_price: 0,
    gps_amount: 0,
    travel_tax: 0,
    purchase_tax: 0,
    product_name_write: null,
    down_payment: null,
    finance_amount: null,
    balloon: null,
    deposit: null,
    mouth_rental: null,
    first_amount: null,
    down_payment_ratio: null,
    deposit_ratio: null,
    balloon_ratio: null,
    annual_pay_times_n: null,
    annual_pay_times: null,
    lease_times: null,
    price_list: null,
    product_type: null,
    int_rate_display: null,
    lease_charge_ratio: null,
  },
  /**
   * 项目申请人信息
   */
  prjBp: {
    prj_bp_id: '',
    project_id: '',
    bp_id: '',
    // 客户姓名
    bp_name: null,
    // 手机号
    cell_phone: null,
    // 证件类型
    id_type_n: null,
    id_type: null,
    // 证件号码
    id_card_no: null,
    // 住房情况
    ownship_of_house: null,
    ownship_of_house_n: null,
    // 是否住房贷款
    house_loans_flag: null,
    house_loans_flag_n: null,
    // 户籍地址
    address_on_resident_booklit: null,
    // 居住地址
    living_address: null,
    // 单位名称
    work_unit: null,
    // 单位地址
    work_unit_address: null,
    // 单位电话
    work_unit_phone: null,
    // 职务
    position: null,
    position_n: null,
    user_id: window.localStorage.user_id,
  },

  cashFlows: [],

  prjItemList: null,

  prjUpdataFlag: false,

  getCarFlag () {
    return this.carFlag
  },
  setCarFlag (carFlag) {
    this.carFlag = carFlag
  },

  getClientInfoFlag () {
    return this.clientInfoFlag
  },
  setClientInfoFlag (clientInfoFlag) {
    this.clientInfoFlag = clientInfoFlag
  },
  getOfferFlag () {
    return this.offerFlag
  },
  setOfferFlag (offerFlag) {
    this.offerFlag = offerFlag
  },
  getAttachFlag () {
    return this.attachFlag
  },
  setAttachFlag (attachFlag) {
    this.attachFlag = attachFlag
  },
  /**
   *
   * @returns {project|{project_id, project_name, bp_class, division, car_type, business_type, invoice_agent_id, invoice_agent_name, user_id, create_for, times, finance, lastrental, balloon, pmt, total_amount}}
   */
  getProject () {
    return this.project
  },

  setProject (project) {
    this.project = Object.assign(this.project, project)
  },
  /**
   *
   */
  cleanProject () {
    for (let key in this.project) {
      this.project[key] = ''
    }
  },
  /**
   *
   * @returns {*}
   */
  getPrjbp: function () {
    return this.prjBp
  },
  /**
   *
   * @param prjBp
   */
  setPrjbp: function (prjBp) {
    this.prjBp = Object.assign(this.prjBp, prjBp)
  },
  /**
   *
   */
  cleanPrjBp () {
    for (let key in this.prjBp) {
      this.prjBp[key] = ''
    }
  },
  /**
   *
   * @returns {default.lease|{project_id, user_id, business_type}}
   */
  getLease: function () {
    return this.lease
  },
  /**
   *
   * @param lease
   */
  setLease: function (lease) {
    this.lease = Object.assign(this.lease, lease)
  },
  /**
   *
   */
  cleanLease () {
    for (let key in this.lease) {
      this.lease[key] = ''
    }
  },
  /**
   *
   * @returns {Array}
   */
  getCashflows: function () {
    return this.cashFlows
  },

  /**
   *
   * @param cashFlows
   */
  setCashflows: function (cashFlows) {
    this.cashFlows = cashFlows
  },
  getPrjItemList: function () {
    return this.prjItemList
  },
  setPrjItemList: function (prjItemList) {
    this.prjItemList = prjItemList
  },
  cleanPrjItemList: function () {
    this.prjItemList = ''
  },

  setProjectId: function (projectId) {
    this.project.project_id = projectId
  },
  setCddListId: function (cddListId) {
    this.project.cdd_list_id = cddListId
  },
  getCddListId: function () {
    return this.project.cdd_list_id
  },
  setProjectBpId: function (bpId) {
    this.prjBp.bp_id = bpId
  },
  setProjectBpProId: function (prjBpId) {
    this.prjBp.prj_bp_id = prjBpId
  },
  setProjectLeaseItemId: function (projectLeaseItemId) {
    this.lease.project_lease_item_id = projectLeaseItemId
  },
  getPrjUpdataFlag () {
    return this.prjUpdataFlag
  },
  setPrjUpdataFlag (flag) {
    this.prjUpdataFlag = flag
  },

  /**
   *
   * @param invoic  车价款
   * @param pay_times 还款频率
   * @param lease_times  期限
   * @param int_rato  年利率
   * @param down_payment_ratio  首付比例
   * @param balloon_ratio  尾款比例
   * @param deposit_ratio  保证金比例
   * @param lease_charge  手续费
   * @param insurance_price  保险费
   * @param gps_amount  GPS费
   * @param travel_tax  车船税
   * @param gz  购置税
   * @param pay_type  付款方式
   */
  calcQuotation: function (invoic, payTimes, leaseTimes, intRato, downPaymentRatio, balloonRatio, depositRatio, leaseCharge, insurancePrice, gpsAmount, travelTax,
    gz, payType) {
    invoic = parseFloat(invoic)
    leaseCharge = parseFloat(leaseCharge)
    insurancePrice = parseFloat(insurancePrice)
    gpsAmount = parseFloat(gpsAmount)
    travelTax = parseFloat(travelTax)
    gz = parseFloat(gz)
    if (!leaseCharge) {
      leaseCharge = 0
    } else if (!insurancePrice) {
      insurancePrice = 0
    } else if (!gpsAmount) {
      gpsAmount = 0
    } else if (!travelTax) {
      travelTax = 0
    } else if (!gz) {
      gz = 0
    }
    // 首付金额  融资额  尾付款  保证金 月供 首次支付
    let result = {
      down_payment: 0, finance_amount: 0, balloon: 0, deposit: 0, mouth_rental: 0, first_amount: 0, cash_flows: [],
    }
    let cashFlows = result.cash_flows
    result.lease_charge = leaseCharge
    result.down_payment = hlsUtil.toDecimal((invoic * downPaymentRatio))
    result.finance_amount = hlsUtil.toDecimal((invoic - result.down_payment + leaseCharge + insurancePrice + gpsAmount + travelTax + gz))
    result.balloon = hlsUtil.toDecimal((invoic * balloonRatio))
    result.deposit = hlsUtil.toDecimal(((invoic + leaseCharge + insurancePrice + gpsAmount + travelTax + gz) * depositRatio))
    result.mouth_rental = hlsUtil.toDecimal(hlsUtil.PMT(intRato / payTimes, leaseTimes, -(result.finance_amount), 0, 0))
    // result.mouth_rental = 2113.9;
    result.first_amount = hlsUtil.toDecimal((result.down_payment + result.deposit + leaseCharge + insurancePrice + gpsAmount + travelTax))

    // 剩余本金
    let outstandingPrincipal
    for (var i = 0; i <= leaseTimes; i++) {
      // 每期现金流
      var cashFlow = {
        time: 0,
        due_amount: 0,
        principal: 0,
        interest: 0,
        outstanding_principal: 0,
      }
      // 期数
      cashFlow.time = i
      if (i === 0) {
        outstandingPrincipal = result.finance_amount
        cashFlow.outstanding_principal = outstandingPrincipal
      } else if (i > 0 && i < leaseTimes) {
        // 租金
        cashFlow.due_amount = result.mouth_rental
        // 利息
        cashFlow.interest = hlsUtil.toDecimal(outstandingPrincipal * (intRato / payTimes))
        // 本金
        cashFlow.principal = hlsUtil.toDecimal((cashFlow.due_amount - cashFlow.interest))

        outstandingPrincipal = hlsUtil.toDecimal((outstandingPrincipal - cashFlow.principal))
        cashFlow.outstanding_principal = outstandingPrincipal
      } else {
        cashFlow.due_amount = result.mouth_rental
        cashFlow.principal = outstandingPrincipal
        cashFlow.interest = hlsUtil.toDecimal((cashFlow.due_amount - cashFlow.principal))
      }
      cashFlows.push(cashFlow)
    }
    return result
  },

}