<template>
  <div class="template-list-cmp">
    <van-radio-group :value="selectedId" class="template-list">
      <van-radio
        v-for="(template, index) in list"
        :name="template.id"
        :key="index"
        class="template-radio"
        @click="handleSelectItem(template.id)"
      >
        <div class="template-item">
          <van-image
            round
            :src="
              template.s_image_url || require('@/assets/defaulttemplate.png')
            "
            width="44px"
            height="44px"
            fit="contain"
          >
          </van-image>
          <div class="van-ellipsis icon-name" style="width: 96px">
            {{ template.name }}
          </div>
          <div
            v-show="selectedId === template.id"
            @click="handleClickEditTemplate(template.id)"
            class="edit-template"
          >
            编辑模板
          </div>
        </div>
        <template #icon="props">
          <common-svg
            class="icon-checked"
            :name="props.checked ? 'moban-xuanzhongzhuangtai1' : ''"
          ></common-svg>
        </template>
      </van-radio>
    </van-radio-group>
  </div>
</template>

<script lang="ts">
import { Prop, Vue, Component } from 'vue-property-decorator';
@Component
export default class Index extends Vue {
  @Prop() handleSelectItem!: (id: number) => void;
  @Prop() list!: any[];
  @Prop() selectedId!: number | null;
  @Prop() loading!: boolean;
  @Prop() folderId!: number;
  @Prop() isFolderList!: boolean;

  handleClickEditTemplate(templateId: number) {
    let query: any = {
      id: templateId.toString(),
    };
    if (this.isFolderList) {
      query = {
        ...query,
        folderId: this.folderId.toString(),
      };
    }else{
      query = {
        ...query,
        sys: true
      }
    }
    this.$router.push({
      name: 'EditTemplate',
      query,
    });
  }
  get noData() {
    return this.list.length === 0;
  }
}
</script>

<style lang="scss" scoped>
.template-list-cmp {
  .template-list {
    display: grid;
    grid-template-columns: repeat(3, 30%);
    row-gap: 30px;
    place-items: start center;
    justify-content: space-between;
    padding: 0 17px;
    .template-radio {
      position: relative;
      ::v-deep .van-radio__label {
        margin-left: 0px;
      }
      .template-item {
        height: 110px;
      }
      .icon-checked {
        position: absolute;
        right: 0;
        top: 0;
      }
    }

    .icon-name {
      margin-top: 7px;
    }
    .edit-template {
      display: inline-block;
      margin-top: 9px;
      width: 71px;
      height: 24px;
      border-radius: 12px;
      border: 1px solid #ededee;
      font-size: 12px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #818181;
      line-height: 24px;
    }
  }
}
</style>
