编辑代码

//JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
const carString = `批发价:17.9
【车辆款型】奔驰CLA200
【上牌日期】19-1
【出厂日期】2017.2
【新车指导价
【排       量】1.6
【排放标准】5
【真实公里】82000
【手动自动】自动
【车辆配置】17年动感版
【详细车况】和记录一样,水箱框架更换,大灯
【过户次数】0
【联系电话】15165923323
【车辆所在地】德州`

const priceResult = carString.match(/价格*(:|:)(\d+.*\d*)(\n|\r)/)
const priceOne = (priceResult && priceResult[2]) || ''
let priceValue = priceOne
if (parseFloat(priceOne) >= 10000) {
    priceValue = (priceOne / 10000)
    if (/\./.test(priceOne)) {
        priceValue = priceOne.toFixed(2)
    }
}

const seriesResult = carString.match(/(款型|型号|名称)】(.*?)(\n|\r)/)
const seriesValue = (seriesResult && seriesResult[2]) || ''

const configureResult = carString.match(/配置】(.*?)(\n|\r)/)
const configureValue = (configureResult && configureResult[1]) || ''

const plResult = carString.match(/量】(\d+.*\d*)(\n|\r)/)
const plValue = (plResult && plResult[1]) || ''

const ghResult = carString.match(/过户次数】(.*?)(\n|\r)/)
let ghOne = (ghResult && ghResult[1]) || ''
let ghValue = '未知'
if (/\d+/.test(ghOne)) { // 数字
    ghValue = ghOne.match(/\d+/)[0]
} else {
    if (/(一手|车主名下)/.test(ghOne)) {
        ghValue = 0
    }
}

const kmResult = carString.match(/公里】(\d+.*\d*)(\n|\r)/)
const kmOne = (kmResult && kmResult[1]) || ''
let kmValue = kmOne
if (parseFloat(kmOne) >= 10000) {
    kmValue = (kmOne / 10000)
    if (/\./.test(kmValue)) {
        kmValue = kmValue.toFixed(1)
    }
}

const dateResult = carString.match(/上牌日期】(.*?)(\n|\r)/)
let dateOne = (dateResult && dateResult[1]) || ''
let dateValue = dateOne || '未上牌'
if (/\./.test(dateOne)) { // 根据.分割
    dateValue = formatYearMonth(dateOne.split('.').slice(0, 2))
} else if (/\-/.test(dateOne)) { // 根据-分割
    dateValue = formatYearMonth(dateOne.split('-').slice(0, 2))
}
function formatYearMonth(arr) {
    let dateValue = ''
    if (/\d+/.test(arr[0])) { // 年
        dateValue = arr[0].match(/\d+/)[0] + '年'
    }
    if (/\d+/.test(arr[1])) { // 月
        dateValue += arr[1].match(/\d+/)[0] + '月'
    }
    return dateValue
}

const bsxResult = carString.match(/手动自动】(.*?)(\n|\r)/)
const bsxValue = (bsxResult && bsxResult[1]) || ''

const ckResult = carString.match(/车况】(.*?)(\n|\r)/)
const ckValue = (ckResult && ckResult[1]) || ''

const telResult = carString.match(/电话】(.*?)(\n|\r)/)
const telValue = (telResult && telResult[1]) || ''

const proResult = carString.match(/地】(.*?)((\n|\r)|$)/)
const proValue = (proResult && proResult[1]) || ''

const data = {
    carValue: seriesValue,
    carType: seriesValue,
    carAllName: seriesValue,
    // guidePrice: priceValue + '万',
    desc: true, // 开启补充说明
    bcsmtxt: configureValue, // 补充说明
    date: dateValue, // 上牌时间
    km: kmValue, // 公里数
    ghnum: ghValue, // 过户次数
    checked: true, // 排量选择为T
    pl: plValue + 'T', // 排量  
    bsx: bsxValue, // 变速箱
    price: priceValue, // 批发一口价
    currentZk: '其他', // 损伤状况选择其他(UI)
    damageValue: '', // 损伤状况提交空
    currentCk: '其他', // 整体状况选择其他(UI)
    ztckValue: ckValue, // 整体状况提交空
    telValue, // 电话
    proValue, // 所在地
}

console.log(data)