<template>
  <view class="flex card">
    <view>
      <uv-checkbox-group
        v-model="selectCheckboxValue"
        @change="onSelectChange"
      >
        <uv-checkbox
          size="36rpx"
          icon-size="36rpx"
          activeColor="#00A9FF"
          :name="1"
        ></uv-checkbox>
      </uv-checkbox-group>
    </view>
    <view class="info">
      <view class="flex name">
        <view>{{ data.name }}</view>
        <view :class="['tag', `tag-${type}`]">{{ typeDesc }}</view>
      </view>
      <view class="id">{{ data.cerNo }}</view>
    </view>
  </view>
</template>

<script>
  
  export default {
    props: {
      data: {
        type: Object,
        default() {
          return {}
        }
      },
    },
    data() {
      return {
        selectCheckboxValue: [],
      }
    },
    computed: {
      isSelected: {
        set(val) {
          this.selectCheckboxValue = val ? [1]: []

          if (this.data.isSelected == val) {
            return
          }

          this.$emit('selectChange', val)
        },
        get() {
          return this.selectCheckboxValue.length ? true : false
        }
      },
      typeDesc() {
        const { periodId } = this.data

        return this.configList.periodList?.find?.(item => item.id === periodId)?.title
      },
      type() {
        if (this.typeDesc == '青少年') {
          return 1
        }
        if (this.typeDesc == '儿童') {
          return 2
        }

        return 0
      },
    },
    watch: {
      data: {
        handler(val) {
          this.isSelected = val.isSelected
        },
        immediate: true,
        deep: true,
      }
    },
    methods: {
      onSelectChange(val) {
        this.isSelected = val.length ? true : false
      },
    }
  }
</script>

<style scoped lang="scss">
  .card {
    justify-content: flex-start;
    column-gap: 24rpx;
    padding: 24rpx;
    background: #F9F9F9;
  }

  .info {
    .name {
      justify-content: flex-start;
      column-gap: 24rpx;
      font-size: 32rpx;
      color: #181818;

      .tag {
        padding: 2rpx 14rpx;
        font-size: 24rpx;
        color: #00A9FF;
        background: #E9F8FF;
        border: 2rpx solid #00A9FF;
        border-radius: 8rpx;

        &-1 {
          color: #03C25C;
          background: #E9FFF5;
          border-color: #03C25C;
        }

        &-2 {
          color: #EE6E05;
          background: #FFEFE9;
          border-color: #EE6E05;
        }

      }
    }

    .id {
      margin-top: 8rpx;
      font-size: 28rpx;
      color: #9B9B9B;
    }
  }
</style>