<template>
  <div>
    <ModalTransition :show="show">
      <div class="prizelist">
        <div class="prizelist-wrapper" v-show="prizelist.length > 0">
          <div class="prizelist-wrapper-scroll">
            <div class="prizelist-item" v-for="item in prizelist" :key="item.id">
              <div class="prizelist-cover" :class="'USER_' + item.prize_code"></div>
              <div class="prizelist-title">{{ item.prize_name }}</div>
              <div class="prizelist-btngroup">
                <template v-if="item.coupon_type === 'scene'">
                  <div class="btn-goto" :class="{ noaddress: item.pushed !== 1 }" v-html="sceneBtnHtml"
                    @click="handleItemBtn(item.id, $event)">
                  </div>
                </template>
                <template v-else="item.coupon_type === 'coupon'">
                  <div class="btn-goto" v-html="couponBtnHtml"></div>
                </template>
              </div>
            </div>
          </div>
        </div>
        <div class="prizelist-close" @click="$emit('close')"></div>
      </div>
    </ModalTransition>
  </div>
</template>

<script setup>
import { ref } from "vue"
import { isWeixinPlatform, miniJumpToScene, getMiniPageBtnHack } from "../libs/utils"
import ModalTransition from "./ModalTransition.vue";
const props = defineProps({
  show: false,
  prizelist: {
    type: Array,
    default: () => []
  }
})

const emit = defineEmits(['address', 'close'])
const sceneBtnHtml = ref('')
const couponBtnHtml = ref('')
sceneBtnHtml.value = getMiniPageBtnHack("/pages/unify/unify?orgId=58929586649432064&targetUrl=%2Fpages%2Fmember%2Forder%2Forder-list%3FtopTab%3D1")

couponBtnHtml.value = getMiniPageBtnHack("/pages/unify/unify?orgId=58929586649432064&targetUrl=%2Fpages%2Fcoupon%2Fcoupons-list")

const handleItemBtn = (id, event) => {
  const target = event.currentTarget

  if (target.classList.contains("noaddress")) {
    emit("address", id)
  } else {
    if (isWeixinPlatform()) {
      miniJumpToScene()
    } else {
      weui.alert("请前往「泸州老窖会员中心」小程序进行查询")
    }
  }
}
</script>

<style>
.prizelist {
  position: relative;
  width: 100vw;
  height: 110vw;
  background-image: url("../assets/images/new/prizelist-bg.webp");
  background-repeat: no-repeat;
  background-size: 100% auto;
  background-position: 0 0;
  display: flex;
  align-items: flex-end;
}

.prizelist-wrapper {
  width: 100%;
  height: 74vw;
  overflow: auto;

}

.prizelist-wrapper-scroll {
  display: flex;
  flex-direction: column;
}

.prizelist-item {
  display: flex;
  margin-bottom: 4vw;
  margin-left: 2.5vw;
  padding-left: 3vw;
  width: 95.833333vw;
  height: 20.648148vw;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  background-image: url("../assets/images/new/prizelist-item-bg.webp");
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

.prizelist-cover {
  width: 15vw;
  margin-right: 3vw;
  height: 15vw;
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

.prizelist-title {
  font-size: 4.444444vw;
  flex: 1;
  display: flex;
  font-weight: 700;
  color: #48260a;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  display: -webkit-box;
  -webkit-box-orient: vertical;
}

.prizelist-close {
  position: absolute;
  width: 11vw;
  height: 11vw;
  right: 3vw;
  top: -14vw;
  background-image: url("../assets/images/new/close-btn.webp");
  background-repeat: no-repeat;
  background-size: 100%;
}

.btn-goto {
  margin-right: 4vw;
  width: 23.981481vw;
  height: 9.074074vw;
  background-size: 100% 100%;
  background-image: url("../assets/images/new/btn-goto.webp");
  background-repeat: no-repeat;
  background-size: 100%;
}
wx-open-launch-weapp{
  width: 100%;
  height: 100%;
}
.btn-goto wx-open-launch-weapp {
  display: block;
}
wx-open-launch-weapp,
.btn-goto.noaddress wx-open-launch-weapp {
  display: none;
}



.btn-goto.noaddress {
  background-image: url("../assets/images/new/btn-address.webp");
}

.prizelist-cover.USER_GJ1573_55_SSYX {
  background-image: url("../assets/images/prizelist/USER_GJ1573_55_SSYX.webp");
}

.prizelist-cover.USER_QLL_WQSBLH {
  background-image: url("../assets/images/prizelist/USER_QLL_WQSBLH.webp");
}

.prizelist-cover.USER_MJZTZXS {
  background-image: url("../assets/images/prizelist/USER_MJZTZXS.webp");
}

.prizelist-cover.USER_HYJJ {
  background-image: url("../assets/images/prizelist/USER_HYJJ.webp");
}

.prizelist-cover.USER_43I1_100ML {
  background-image: url("../assets/images/prizelist/USER_43I1_100ML.webp");
}

.prizelist-cover.USER_43A2_100ML_6 {
  background-image: url("../assets/images/prizelist/USER_43A2_100ML_6.webp");
}

.prizelist-cover.USER_43A6_100ML_6 {
  background-image: url("../assets/images/prizelist/USER_43A6_100ML_6.webp");
}

.prizelist-cover.USER_52A6_100ML_6 {
  background-image: url("../assets/images/prizelist/USER_52A6_100ML_6.webp");
}

.prizelist-cover.USER_DZCZ {
  background-image: url("../assets/images/USER_DZCZ.webp");
}

.prizelist-cover.USER_DZSCZ {
  background-image: url("../assets/images/USER_DZSCZ.webp");
}

.prizelist-cover.USER_66_POINTS {
  background-image: url("../assets/images/USER_66_POINTS.webp");
}
</style>