step-three.vue 4.04 KB
<template>
    <view class="pageBox">
        <view class="width-calc">
            <view class="content-title">
                品牌偏好<span class="content-title-span"> (多选)</span>
                <view v-if="vehicleBrandList.length" @click="handleClear()" class="clearBox">
                    <uni-icons type="trash" size="13" color="#141E34" />
                    <span class="clear-text">清空</span>
                </view>
            </view>

            <view class="reason-select" @click="handleBrandSelect()">
                <text v-if="vehicleBrandList.length"> 已选 {{ vehicleBrandList.length }} 个品牌</text>
                <text v-else class="placeholder">请选择品牌偏好</text>
                <uni-icons type="right" size="14" color="#999999" />
            </view>

            <view class="brandListBox">
                <view v-for="(item, index) in vehicleBrandList" :key="index" class="brand-item">
                    {{ item.name }}
                    <uni-icons type="closeempty" size="12" color="#828CA0" @click="handleRemove(item)" />
                </view>
            </view>
        </view>
    </view>
</template>

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


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

    vehicleBrandList: any = []

    //初始化数据
    initData(data: any) {
        this.vehicleBrandList = data.brandList || [];
    }

    //清空选择的品牌
    handleClear() {
        this.vehicleBrandList = [];
        this.$emit('threeData', { brandList: this.vehicleBrandList });
    }

    //删除选中的品牌
    handleRemove(item: any) {
        const index = this.vehicleBrandList.indexOf(item);
        if (index !== -1) {
            this.vehicleBrandList.splice(index, 1);
        }
        this.$emit('threeData', { brandList: this.vehicleBrandList });
    }

    //选择偏好品牌
    handleBrandSelect() {
        const that = this;
        uni.setStorageSync('storagVehicleBrandList', JSON.stringify(that.vehicleBrandList));
        uni.navigateTo({
            url: '/module/preference/selectVehicleBrand', events: {
                onReturnData: function (res: any) {
                    that.vehicleBrandList = res.data || [];
                    that.$emit('threeData', { brandList: that.vehicleBrandList });
                }
            },
        });
    }
}
</script>


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

.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;
    position: relative;
}

.content-title-span {
    color: #333333;
    font-size: 14px;
}

.reason-select {
    width: 100%;
    height: 52px;
    line-height: 52px;
    float: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    border-bottom: 1px solid #e6ebf5;
    cursor: pointer;
    color: #333333;
}

.placeholder {
    color: #999999;
    font-size: 14px;
}

.clearBox {
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
    height: 20px;
    cursor: pointer;
}

.clear-text {
    height: 20px;
    line-height: 20px;
    color: #333333;
    font-size: 14px;
    text-align: center;
    padding-left: 4px;
}

.brandListBox {
    width: 100%;
    float: left;
    margin-top: 6px;
}

.brand-item {
    max-width: 180px;
    height: 36px;
    line-height: 36px;
    border-radius: 4px;
    background: #f8f9fb;
    font-size: 14px;
    color: #333333;
    float: left;
    margin-top: 10px;
    margin-right: 10px;
    align-items: center;
    padding: 0 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand-item uni-icons {
    margin-left: 2px;
    flex-shrink: 0;
}
</style>