<template>
  <view class="flex card">
    <view>
      <uv-checkbox-group
        v-model="checkboxValue"
        shape="circle"
        @change="onChange"
      >
        <uv-checkbox
          size="36rpx"
          icon-size="36rpx"
          activeColor="#7451DE"
          :name="1"
        ></uv-checkbox>
      </uv-checkbox-group>
    </view>
    <view class="img-box">
      <image class="img" :src="data.url" mode="aspectFit"></image>
    </view>
    <view class="info">
      <view class="title">{{ data.name }}</view>
      <view class="desc">{{ data.desc }}</view>
      <view class="flex price-box">
        <view class="flex price">¥<text class="highlight">{{ data.price.toFixed(2) }}</text>/次</view>
        <view class="price-origin">{{ `¥${data.originalPrice}/次` }}</view>
      </view>
      <view class="flex tool">
        <view class="flex count">规格：<text class="highlight">{{ `x${data.count}` }}</text></view>
        <button class="flex btn" @click="jumpToProductDetail">详情</button>
      </view>
    </view>
    
    <view v-if="data.customized" class="sup customized">
      定制组合
    </view>
    <view v-else-if="data.free" class="sup free">
      自定组合
    </view>
  </view>
</template>

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

          if (this.data.selected == val) {
            return
          }
          this.$emit('select', val)
        },
        get() {
          return this.checkboxValue[0] == 1 ? true : false
        }
      }
    },
    watch: {
      data: {
        handler(val) {
          this.checked = val.selected
        },
        immediate: true,
        deep: true,
      }
    },
    methods: {
      onChange(arr) {
        this.checked = arr[0] == 1 ? true : false
      },
      jumpToProductDetail() {
        this.$utils.navigateTo(`/pages_order/product/productDetail?id=${this.data.id}`)
      },
    },
  }
</script>

<style scoped lang="scss">
.card {
  position: relative;
  height: 272rpx;
  padding: 0 32rpx;
  background-image: linear-gradient(#FAFAFF, #F3F3F3);
  border: 2rpx solid #FFFFFF;
  border-radius: 32rpx;
  box-sizing: border-box;
  column-gap: 24rpx;
  overflow: hidden;

  /deep/ .uv-checkbox__label-wra {
    padding: 0;
  }
}

.img {
  &-box {
    width: 144rpx;
    height: 144rpx;
    border-radius: 16rpx;
    overflow: hidden;
  }

  width: 100%;
  height: 100%;
}

.info {
  flex: 1;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 1.4;
  font-size: 26rpx;
  color: #8B8B8B;

  .title {
    font-weight: 600;
    font-size: 28rpx;
    color: #000000;
  }

  .desc {
    margin-top: 8rpx;
    line-height: 1.5;
  }

  .price {
    &-box {
      margin-top: 8rpx;
      justify-content: flex-start;
      column-gap: 20rpx;
    }

    font-weight: 600;
    font-size: 24rpx;
    color: #7451DE;

    .highlight {
      margin: 0 8rpx;
      font-size: 32rpx;
    }

    &-origin {
      font-size: 28rpx;
      line-height: 1;
      text-decoration: line-through;
    }
  }

  .tool {
    margin-top: 8rpx;
    justify-content: space-between;

    .count {
      .highlight {
        margin-left: 8rpx;
        color: #252545;
      }
    }

    .btn {
      padding: 8rpx 22rpx;
      font-size: 28rpx;
      color: #252545;
      border: 2rpx solid #252545;
      border-radius: 30rpx;
    }
  }
}

.sup {
  position: absolute;
  top: 28rpx;
  right: -60rpx;
  padding: 5rpx 52rpx;
  font-family: PingFang SC;
  font-weight: 400;
  font-size: 28rpx;
  line-height: 1.5;
  white-space: nowrap;
  transform: rotate(45deg);
  
  &.customized {
    color: #FFFFFF;
    background: #252545;
  }

  &.free {
    color: #252545;
    background: #D7D7FF;
  }
}
</style>