<template>
  <view
    class="combine-goods-list"
  >
    <view class="title-bar">
      <view class="tag">
        组合
      </view>
      <view class="name">
        {{ prodItem.comboName }}
      </view>
    </view>
    <view
      v-for="(combine, combineIndex) in prodItem.skuComboList"
      :key="combineIndex"
      class="prod-item"
    >
      <view
        class="info"
        @tap="toProdDetail(combine.spuId)"
      >
        <view class="prod-img">
          <img-show
            :src="combine.pic"
            img-mode="aspectFit"
          />
        </view>
        <view class="text-box">
          <view class="name">
            {{ combine.spuName }}
          </view>
          <view class="sku">
            <view
              class="activity-logo"
            >
              组合
            </view>
            <view
              v-if="combine.skuName"
              class="sku-text"
            >
              {{ combine.skuName }}
            </view>
          </view>
          <view class="price-box">
            <view class="price">
              <view
                v-if="orderType===orderTypeConstant.SCORE && combine.comboPrice"
                class="symbol"
              >
                +
              </view>
              <view
                v-if="orderType!==orderTypeConstant.SCORE"
                class="symbol"
              >
                ￥
              </view>
              <view
                v-if="combine.price"
                class="big"
              >
                {{ wxs.parsePrice(combine.price)[0] }}
              </view>
              <view
                v-if="combine.price"
                class="symbol"
              >
                .{{ wxs.parsePrice(combine.price)[1] }}元
              </view>
            </view>
            <view class="count">
              ×{{ combine.count }}
            </view>
            <view
              v-if="status!==orderStatusConstant.UNPAY"
              class="action"
            >
              <view
                v-if="!combine.finalRefundId && orderType!==orderTypeConstant.SCORE && status!==orderStatusConstant.CANCEL && (!combine.refundStatus || combine.refundStatus===refundStatusConstant.DISAGREE) && canRefund && combine.isRefund!==0 && (orderMold !== 1 ||
                  (orderMold === 1 && ((writeOffNum !== 0 && unusedCount) || writeOffNum === 0)))"
                class="btn"
                @tap.stop="toApplyRefund(combine)"
              >
                申请售后
              </view>
              <view
                v-if="combine.finalRefundId || (combine.refundStatus && combine.refundStatus !==refundStatusConstant.DISAGREE)"
                class="btn"
                @tap.stop="toRefundDetail(combine.finalRefundId)"
              >
                查看退款
              </view>
            </view>
            <!-- 待付款时不显示action,已取消时显示“加购物车”,待发货、待收货、已完成显示“申请售后”和“加购物车” -->
          </view>
        </view>
      </view>
      <!-- 赠品：多个商品时展示 -->
      <view
        v-if="combine.giveawayList && combine.giveawayList.length"
        class="gift-prods"
      >
        <view
          v-for="giftItem in combine.giveawayList"
          :key="giftItem.orderItemId"
          class="gift-item"
          @tap="toProdDetail(giftItem.spuId)"
        >
          <text class="name">
            【赠品】{{ giftItem.spuName }}
          </text>
          <text class="num">
            ×{{ giftItem.count }}
          </text>
        </view>
      </view>
    </view>
    <view class="bottom-box">
      <view class="price-box">
        <view class="price">
          <view class="symbol">
            销售价￥
          </view>
          <view class="big">
            {{ wxs.parsePrice(totalPrice)[0] }}
          </view>
          <view class="symbol">
            .{{ wxs.parsePrice(totalPrice)[1] }}
          </view>
          <view class="count">
            x{{ prodItem.mainComboCount }}
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { OrderStatus, ProdType, RefundStatus } from '@/utils/constant'
import { countComboPrice } from '@/utils/combo'

const props = defineProps({
  prodItem: {
    type: Object,
    default: () => {
      return {}
    }
  },
  status: {
    type: Number,
    default: 0
  },
  orderType: {
    type: Number,
    default: 0
  },
  canRefund: {
    type: Boolean,
    default: false
  },
  orderMold: {
    type: Number,
    default: 0
  },
  writeOffNum: {
    type: Number,
    default: 0
  },
  unusedCount: {
    type: Number,
    default: 0
  },
  toApplyRefund: {
    type: Function,
    default: () => {}
  },
  toRefundDetail: {
    type: Function,
    default: () => {}
  },
  toProdDetail: {
    type: Function,
    default: () => {}
  }
})

// 各种状态常量
const orderStatusConstant = reactive(OrderStatus)
const refundStatusConstant = reactive(RefundStatus)
const orderTypeConstant = reactive(ProdType)

const totalPrice = computed(() => {
  return countComboPrice(props.prodItem.skuComboList, 'price', 'count')
})

const wxs = number()

</script>

<style scoped lang="scss">
.title-bar {
  display: flex;
  align-items: center;
  padding-top: 10rpx;
  .tag {
    padding: 2rpx 5rpx;
    background-color: #fc1b35;
    color: #FFF;
    border-radius: 5rpx;
    font-size: 22rpx;
  }
  .name {
    margin-left: 10rpx;
  }
}

.combine-goods-list {
  padding-bottom: 20rpx;
  border-bottom: 2rpx solid #f2f3f7;

  .prod-item {
    border-bottom: none !important;
  }
}

.bottom-box {
  .price-box {
    .price {
      width: 100%;
    }
    .count {
      flex: 1 ;
      color: grey;
      text-align: right;
      margin-right: 30rpx;
    }
  }
  .sku {
    color: grey;
  }
}

.prod-item {
  padding: 30rpx 0;
  border-bottom: 2rpx solid #f2f3f7;
  &:last-child {
    box-shadow: none;
    padding-bottom: 0;
  }
  .info {
    display: flex;
    .prod-img {
      width: 160rpx;
      height: 160rpx;
      border-radius: 10rpx;
      overflow: hidden;
      font-size: 0;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .text-box {
      flex: 1;
      margin-left: 20rpx;
      align-self: flex-start;
      position: relative;
      height: 160rpx;
      .name {
        max-height: 64rpx;
        line-height: 32rpx;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        text-overflow: ellipsis;
        word-break: break-word;
      }
      .sku {
        margin-top: 10rpx;
        font-size: 20rpx;
        display: flex;
        align-items: center;
        .sku-text {
          color: #999;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 1;
          overflow: hidden;
          text-overflow: ellipsis;
          word-break: break-word;
          max-width: 50%;
        }
        .activity-logo {
          margin-top: 4rpx;
          background: #fc1b35;
          color: #fff;
          padding: 4rpx 8rpx;
          border-radius: 6rpx;
          width: auto;
          margin-right: 10rpx;
          white-space: nowrap;
        }
      }
      .price-box {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 4rpx;
        display: flex;
        align-items: baseline;
        line-height: 1;
        .price {
          color: #333;
          margin-right: 30rpx;
          .big {
            font-size: 24rpx;
          }
        }
        .count {
          color: #999;
          margin-right: 10rpx;
        }
      }
    }
  }
  .action {
    display: flex;
    margin-left: auto;
    .btn {
      padding: 10rpx 26rpx;
      border: 2rpx solid #ddd;
      border-radius: 60rpx;
      margin-left: 20rpx;
    }
  }
}

/* 赠品 */
.prod-item {
  .gift-prods {
    margin: 20rpx 0 20rpx 174rpx;
    .gift-item {
      display: inline-block;
      width: 100%;
      color: #333;
      &:not(:last-child) {
        margin-bottom: 12rpx;
      }
      .name {
        display: inline-block;
        vertical-align: middle;
        padding-right: 10rpx;
        width: 85%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .num {
        display: inline-block;
        vertical-align: middle;
        padding-right: 10rpx;
      }
      &::after {
        content: '';
        display: inline-block;
        width: 12rpx;
        height: 12rpx;
        border-top: 2rpx solid #333333;
        border-right: 2rpx solid #333333;
        -webkit-transform: rotate(45deg);
        transform: rotate(45deg);
        vertical-align: middle;
      }
    }
  }
}

</style>
