step-two.vue 6.62 KB
<template>
    <view class="pageBox">
        <view class="width-calc">

            <view class="content-title">
                偏好车况<span class="validate">*</span>
            </view>
            <view class="select-list">
                <view v-for="(item, index) in situationList" :key="index" @click="handleSelect('situationList', index)"
                    :class="{ 'select-but': true, 'ml-12': item.value == '2', 'w-100': item.value == '3', 'pitchOn': item.select }">
                    {{ item.label }}
                    <view v-if="item.select" class="pitchOn-img"></view>
                </view>
            </view>

            <view class="content-title">
                偏好车龄<span class="validate">*</span>
            </view>
            <view class="select-list">
                <view v-for="(item, index) in vehicleAgeList" :key="index"
                    @click="handleSelect('vehicleAgeList', index)"
                    :class="{ 'select-but': true, 'ml-12': item.value == '2' || item.value == '4', 'pitchOn': item.select }">
                    {{ item.label }}
                    <view v-if="item.select" class="pitchOn-img"></view>
                </view>
            </view>

            <view class="content-title">
                燃油类型<span class="validate">*</span>
            </view>
            <view class="select-list">
                <view v-for="(item, index) in vehicleFuelTypeList" :key="index"
                    @click="handleSelect('vehicleFuelTypeList', index)"
                    :class="{ 'select-but': true, 'ml-12': item.value == '2', 'pitchOn': item.select }">
                    {{ item.label }}
                    <view v-if="item.select" class="pitchOn-img"></view>
                </view>
            </view>

            <view class="content-title">
                收车车型<span class="validate">*</span>
            </view>
            <view class="select-list">
                <view v-for="(item, index) in vehicleTypeList" :key="index"
                    @click="handleSelect('vehicleTypeList', index)"
                    :class="{ 'select-but2': true, 'ml-12': item.value == '2' || item.value == '3' || item.value == '5', 'pitchOn': item.select }">
                    {{ item.label }}
                    <view v-if="item.select" class="pitchOn-img"></view>
                </view>
            </view>
        </view>
    </view>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-facing-decorator';


@Component({})
export default class stepTwo extends Vue {

    situationList = [
        { label: '精品(A/B级)', value: '1', select: false },
        { label: '瑕疵(C级)', value: '2', select: false },
        { label: '重大事故/水泡/火烧(D级)', value: '3', select: false }
    ]

    vehicleAgeList = [
        { label: '1-3年', value: '1', select: false },
        { label: '3-6年', value: '2', select: false },
        { label: '6-10年', value: '3', select: false },
        { label: '>10年', value: '4', select: false }
    ]

    vehicleFuelTypeList  = [
        { label: '燃油', value: '1', select: false },
        { label: '新能源', value: '2', select: false },
    ]

    vehicleTypeList = [
        { label: '轿车', value: '1', select: false },
        { label: 'SUV', value: '2', select: false },
        { label: 'MPV', value: '3', select: false },
        { label: '跑车', value: '4', select: false },
        { label: '皮卡', value: '5', select: false },
    ]

    initData(data: any) {
        const vehicleCondition = (data.vehicleCondition || '').split(',').filter(Boolean);
        const vehicleAge = (data.vehicleAge || '').split(',').filter(Boolean);
        const vehicleFuelType = (data.vehicleFuelType || '').split(',').filter(Boolean);
        const vehicleType = (data.vehicleType || '').split(',').filter(Boolean);
        this.situationList = this.situationList.map(item => ({ ...item, select: vehicleCondition.includes(item.value) }))
        this.vehicleAgeList = this.vehicleAgeList.map(item => ({ ...item, select: vehicleAge.includes(item.value) }))
        this.vehicleFuelTypeList = this.vehicleFuelTypeList.map(item => ({ ...item, select: vehicleFuelType.includes(item.value) }))
        this.vehicleTypeList = this.vehicleTypeList.map(item => ({ ...item, select: vehicleType.includes(item.value) }))
    }

    handleSelect(key: string, index: number) {
        this[key][index].select = !this[key][index].select;
        this.$emit('twoData', {
            vehicleCondition: this.situationList.filter(item => item.select).map(item => item.value).join(','),
            vehicleAge: this.vehicleAgeList.filter(item => item.select).map(item => item.value).join(','),
            vehicleFuelType: this.vehicleFuelTypeList.filter(item => item.select).map(item => item.value).join(','),
            vehicleType: this.vehicleTypeList.filter(item => item.select).map(item => item.value).join(',')
        });
    }
}
</script>

<style scoped lang="scss">
.pageBox {
    width: 100%;
    background: #fff;
    float: left;
}

.width-calc {
    width: -webkit-calc(100% - 40px);
    width: -moz-calc(100% - 40px);
    width: calc(100% - 40px);
    float: left;
    margin: 0 20px;
}

.content-title {
    width: 100%;
    height: 24px;
    color: #141e34;
    font-size: 16px;
    font-weight: 中黑体;
    font-family: "苹方-简";
    line-height: 24px;
    float: left;
    margin-top: 16px;
    margin-bottom: 10px;
}

.validate {
    color: #ee3040;
    font-size: 16px;
    padding-left: 2px;
}

.select-but {
    width: -webkit-calc(50% - 6px);
    width: -moz-calc(50% - 6px);
    width: calc(50% - 6px);
    height: 40px;
    line-height: 40px;
    border-radius: 4px;
    background: #f5f9ff;
    color: #333333;
    font-size: 14px;
    text-align: center;
    float: left;
    cursor: pointer;
    position: relative;
    margin-bottom: 12px;
}

.select-but2 {
    width: -webkit-calc(33.333333% - 8px);
    width: -moz-calc(33.333333% - 8px);
    width: calc(33.333333% - 8px);
    height: 40px;
    line-height: 40px;
    border-radius: 4px;
    background: #f5f9ff;
    color: #333333;
    font-size: 14px;
    text-align: center;
    float: left;
    cursor: pointer;
    position: relative;
    margin-bottom: 12px;
}

.pitchOn {
    background: #f5f9ff !important;
    color: #185efe !important;
}

.pitchOn-img {
    position: absolute;
    top: 0;
    right: 0;
    width: 16px;
    height: 16px;
    z-index: 99;
    background-image: url("https://img02.glsx.com.cn/aus/images/preference/pitchOn.png");
    background-repeat: no-repeat;
    background-size: 100%;
}

.ml-12 {
    margin-left: 12px;
}

.mt-16 {
    margin-top: 16px;
}

.w-100 {
    width: 100% !important;
}
</style>