<template>
  <child-view>
    <div ref="box" class="sub-page mx-4">
      <div class="bg-app-dark-2 border border-app-blue-3 border-solid rounded-lg">
        <div class="p-4 border-0 border-b border-app-blue-3 border-solid">
          <community-card />
        </div>
        <div class="p-4 border-0 border-b border-app-blue-3 border-solid" :class="{'mb-36': hide}">
          <div
            v-for="(item, index) in lists"
            :key="index"
            class="mb-3 py-3 flex flex-col border border-app-blue-3 border-solid rounded-lg"
            >
            <div ref="content" class="text-sm px-3">
              <span class="inline-block" v-if="item.type1 === 0">{{ item.content }}</span>
              <div v-else class="flex items-end" @click="triggle(index, item.type1)">
                <span class="inline-block transition-all duration-300 delay-100 ease-in-out overflow-hidden" :class="{ 'initial-height': item.type1 === 1, 'max-h-52': item.type1 === 2 }">
                  {{ item.content }}
                </span>
                <div class="transition-all duration-300 ease-in-out" :class="{'transform origin-center -rotate-90 mb-0': item.type1 === 2, 'mb-1': item.type1 === 1 }">
                  <app-icon customize type='icon-arrow-right-copy-copy'></app-icon>
                </div>
              </div>
              <!-- <div v-else class="flex items-end" @click="item.type1 = 1">
                <span>
                  {{ item.content }}
                </span>
                <div class="mb-0 transform origin-center -rotate-90">
                  <app-icon customize type='icon-arrow-right-copy-copy'></app-icon>
                </div>
              </div> -->
            </div>
            <div class="mt-4 px-4 pb-3 flex items-center justify-between text-xs border-0 border-b border-app-blue-3 border-solid">
              <div class="w-1/2 flex-grow-0">
                <van-progress pivot-text="红色" color="#FF7327" :percentage="60" :show-pivot="false" />
              </div>
              <div>1200票</div>
              <div>22%</div>
            </div>
            <div class="mt-3 px-3 flex items-center justify-between text-xs">
              <div>ID</div>
              <div class="flex items-center" @click="goProject">
                <span>jshhhdjsdfkdsKHLHJ94859837…yiyh</span>
                <app-icon customize type='icon-arrow-right-copy-copy'></app-icon>
              </div>
            </div>
          </div>
          <button class="w-full vote-btn h-10 leading-10 text-center text-sm rounded-lg opacity-30">已结束</button>
        </div>
      </div>
    </div>
  </child-view>
</template>

<script lang="ts">
import CommunityCard from '@/components/home/CommunityCard.vue'
import childView from '@/layouts/childView.vue'
import AppIcon from '@/components/common/Icon.vue'
import { Progress } from 'vant'
import Vue from 'vue'
Vue.use(Progress)
export default Vue.extend({
  components: {
    childView,
    CommunityCard,
    AppIcon
  },
  data() {
    return {
      lists: [
        {
          selected: true,
          content: '选项卡-选修课-选修课-'
        },
        {
          selected: false,
          content: '选项卡-选修课-选修课-选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课选项卡-选修课'
        },
        {
          selected: false,
          content: '选项卡-选修课-选修课-选项卡-选修课-选修课-选项卡-选修课-选修课-选项卡-选修课-选修课-选项卡-选修课-选修课-选项卡-选修课-选修课-选项卡-选修课-选修课-'
        },
        {
          selected: false,
          content: '选项卡-选修课-选修课-'
        },
      ],
      type1: true,
      voteNum: '',
      rest: 1111,
      hide: false
    }
  },
  methods: {
    goProject() {
      this.$router.push('/Browser/ProjectDetails')
    },
    triggle(i: number, v: number) {
      if (v === 1) {
        this.$set(this.lists[i], 'type1', 2)
      } else {
        this.$set(this.lists[i], 'type1', 1)
      }
    }
  },
  mounted() {
    const content = this.$refs.content as any[]
    for (let i = 0; i < content.length; i++) {
      if (content[i].offsetHeight > 72) {
        this.$set(this.lists[i], 'type1', 1)
      } else {
        this.$set(this.lists[i], 'type1', 0)
      }
    }
  }
})
</script>

<style scoped>
  .x-input {
    width: 100%;
    height: 40px;
    border-radius: 10px;
    margin-bottom: 10px;
    padding-left: 12px;
    padding-right: 12px;
    font-weight: 500;
    color: rgba(36, 36, 37, 0.8);
    box-shadow: 0px 3px 4px 0px #BCB3DC inset;
  }
  .vote-btn {
    background: #6870F1;
  }
  .type-1 {
    display: -webkit-box;
    overflow: hidden;  
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
  }
  .initial-height {
    max-height: 60px;
  }
</style>