<template>
  <layout bgImgName="second-reward-img" bgColor="#f64d5d" bgHeight="188">
    <div class="second-reward">
      <div class="second-reward-title">
        请搜索您希望在云机内运行的应用为您安装至云机
      </div>
      <div>
        <div class="application">
          <div
            v-for="item in applicationList"
            :key="item"
            :class="{ active: item === imgName }"
            @click="selectApplication(item)"
          >
            <img
              src="@/assets/image/claimCloudPhone/active-checked.png"
              alt=""
              v-if="item === imgName"
            />
            {{ item }}
          </div>
        </div>
      </div>
      <img
        :src="
          require(`@/assets/image/claimCloudPhone/${
            this.imgIndex
              ? `installApps_${this.imgIndex}`
              : 'second-reward-empty'
          }.png`)
        "
        alt=""
        class="install-apps-img"
      />
      <img
        :src="
          require(`@/assets/image/claimCloudPhone/${
            imgName
              ? 'claim-mobile-phone-btn'
              : 'claim-mobile-phone-btn-prohibit'
          }.png`)
        "
        alt=""
        class="btn"
        @click="toPurchase"
      />
    </div>
  </layout>
</template>

<script>
import layout from './components/layout';
export default {
  auth: false,
  name: 'secondReward',
  head: {
    title: '0元购机，尽情享受',
  },
  data() {
    return {
      applicationList: [
        '飞书',
        '钉钉',
        '企业微信',
        '梦幻西游',
        '闲鱼之王',
        '寻道大千',
        '部落冲突',
        '传奇',
        '倩女幽魂',
      ], //  应用数组
      imgIndex: '',
      imgName: '',
    };
  },
  components: { layout },
  methods: {
    selectApplication(name) {
      this.imgIndex = this.applicationList.indexOf(name) + 1;
      this.imgName = name;
    },
    toPurchase() {
      if (!this.imgName) return;
      // 埋点
      this.$axios
        .$post('public/v5/User/selects/addApplication', {
          applicationName: this.imgName,
        })
        .then((res) => {});
      this.$router.push('/claimCloudPhone/purchase');
    },
  },
};
</script>

<style lang="less" scoped>
.second-reward {
  height: 100%;
  box-sizing: border-box;
  padding-top: 188px;
  .second-reward-title {
    font-family: AlibabaPuHuiTi, AlibabaPuHuiTi;
    font-weight: bold;
    font-size: 15px;
    color: #fefefe;
    line-height: 18px;
    text-align: center;
    font-style: normal;
  }

  .application {
    padding: 0 16px;
    margin-top: 24px;
    display: grid;
    grid-gap: 16px;
    grid-template-columns: repeat(3, 1fr);
    & > div {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 14px;
      color: #742428;
      line-height: 20px;
      text-align: center;
      font-style: normal;
      background: #fff1e1;
      border-radius: 14px;
      opacity: 0.8;
      padding: 11px 0;
      &.active {
        opacity: 1;
        position: relative;
        & > img {
          position: absolute;
          top: -5px;
          right: 0px;
          width: 16px;
          height: 16px;
          z-index: 1;
        }
      }
    }
  }

  .btn {
    display: block;
    margin: 0 auto;
    height: 56px;
  }

  .install-apps-img {
    height: 130px;
    width: 95%;
    display: block;
    margin: 24px auto 20px;
  }
}
</style>
