CarBrands.vue 3.04 KB
<template>
  <view>
    <MessageBox
      ref="carBrandListVisible"
      position="bottom"
      :isFooter="false"
      title="请选择车品牌"
      @close="$emit('close')"
    >
      <view class="select-box">
        <view
          class="select-item"
          :class="{ checked: carBrand == item.name }"
          @click="selectCar(item)"
          v-for="(item, index) in carBrandList"
          :key="index"
        >
          {{ item.name }}
        </view>
      </view>
    </MessageBox>
    <MessageBox
      ref="carBoxVisible"
      position="bottom"
      :isFooter="false"
      title="请选择车型"
      :maxHeight="1000"
      back
    >
      <view class="select-box">
        <view
          class="select-item"
          :class="{ checked: carModel == item.name }"
          @click="handleSelect(item)"
          v-for="(item, index) in carlist"
          :key="index"
        >
          {{ item.name }}
        </view>
      </view>
    </MessageBox>
  </view>

</template>

<script type='text/ecmascript-6'>
export default {
  name: 'CarBrands',
  data () {
    return {
      carlist: [],
      selectItem: {}
    }
  },
  watch: {
    watchStatus: {
      immediate: true,
      handler (newval) {
        this.close()
      }
    },
  },
  computed: {
    watchStatus () {
      return this.$store.state.user.historyStatus
    },
    carModel () {
      return this.$store.state.user.customerInfo.carModel
    },
    carBrandList () {
      return this.$store.state.user.carBrands
    },
    carBrand () {
      return this.$store.state.user.customerInfo.carBrand
    }
  },
  mounted () {
  },
  methods: {
    open () {
      this.$refs.carBrandListVisible.open()
    },
    selectCar (e) {
      uni.showLoading()
      const customerInfo = this.$store.state.user.customerInfo
      customerInfo.carBrand = e.name
      this.$store.dispatch('setCustomerInfo', customerInfo)
      this.selectItem = {
        carBrand: e.brandName,
        carBrandId: e.brandId,
        carChildsBrandName: e.name,
        carChildsBrandId: e.id
      }
      console.log(e)
      uni.$api.commonApi.getCarBrandsList({
        brandId: e.brandId,
        childBrandId: e.id
      }).then(res => {
        uni.hideLoading()
        this.carlist = res
        this.$refs.carBoxVisible.open()
      }).catch(() => uni.hideLoading())
    },
    handleSelect (item) {
      this.$refs.carBoxVisible.close();
      this.$emit('select', {
        ...item,
        ...this.selectItem
      })
    },
    close () {
      this.$refs?.carBoxVisible?.close();
      this.$refs?.carBrandListVisible?.close()
    }
  }
}
</script>

<style scoped lang='scss'>
.select-box {
  margin: 40rpx 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20rpx;
  overflow-y: scroll;
  max-height: 50vh;
  padding-bottom: 60rpx;
  .select-item {
    text-align: center;
    height: 68rpx;
    line-height: 68rpx;
    opacity: 1;
    border: 2rpx solid #dce0e6;
    color: #292d33;
    font-size: 28rpx;
    border-radius: 8rpx;
    &.checked {
      border: 2rpx solid #292d33;
    }
  }
}
</style>