card-address.vue 2.3 KB
<template>
  <view class="card-address" @click="onClick">
    <view class="card-address__lf">
      <view class="title">
        <text>{{ district }}</text>
        <view class="tag" v-if="value.defaultFlag">默认</view>
      </view>
      <view class="content">
        <text>{{ value.address }}</text>
      </view>
      <view class="desc">
        <text class="name">{{ value.name }}</text>
        <text>{{ value.mobile | mobileMask }}</text>
      </view>
    </view>
    <view class="card-address__rt">
      <u-icon name="arrow-right" class="arrow"></u-icon>
    </view>
  </view>
</template>

<script>
export default {
  name: 'CardAddress',
  props: {
    value: {
      type: Object,
      default () {
        return {};
      },
    },
  },
  filters: {
    mobileMask(val) {
      const arr = (val || '').split('');
      arr.splice(3, 4, '*', '*', '*', '*');
      return arr.join('');
    },
  },
  computed: {
    district() {
      const {
        provinceName = '', cityName = '', areaName = ''
      } = this.value;
      return `${provinceName}${cityName}${areaName}`;
    },
  },
  methods: {
    onClick() {
      this.$emit('click');
    },
  },
};
</script>

<style lang="scss">
.card-address {
  background-color: $color-white;
  color: $color-text;
  padding: $padding-md;
  border-radius: $radius-md;
  box-shadow: $shadow-normal;
  font-size: $font-md;
  display: flex;
  justify-content: space-between;
  align-items: center;
  &__lf {
    .title {
      display: flex;
      flex-direction: row;
      align-items: center;
      font-size: $font-sm;
    }
    .tag {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      margin-left: $padding-base;
      height: $padding-md;
      padding: 0 $padding-base;
      line-height: 1;
      font-size: $font-sm;
      color: $color-red;
      border: 1px solid $color-red;
      border-radius: 8upx;
    }
    .content {
      font-weight: bold;
      line-height: 1.2;
      margin: $padding-xs 0;
    }
    .desc {
      color: $color-text-caption;
      font-size: $font-sm;
      .name {
        margin-right: $padding-xs;
      }
    }
  }
  &__rt {
    margin-left: $padding-lg;
    .arrow {
      font-size: $font-lg;
    }
  }
}
</style>