/* 全部一行两个 */
<template>
  <div class="tab_content abroad">
    <div class="padding_box">
      <template v-for="(item, index) in list">
        <div class="uni_item_mini" :key="index" @click="handleStoryDetail(item)">
          <div class="img_box" :style="{ backgroundImage: 'url(' + item.coverUrl + ')' }"></div>
          <div class="content">
            <p class="title">{{ item.title }}</p>
            <div class="name">
              {{ item.name }}
              <p class="like" @click.prevent="zanbtn(item.id, item.likeId)">
                <img v-if="item.likeId > 0" src="@/assets/service/like_on.png" alt="" />
                <img v-else src="@/assets/service/like_off.png" alt="" />
                <span>{{ item.likeCount }}</span>
              </p>
            </div>
          </div>
        </div>
      </template>
      <van-empty v-if="list.length == 0" :image="require('@/assets/empty.png')" description="暂无游记" />
    </div>
  </div>
</template>
<script>
export default {
  props: {
    list: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      active: 0,
      defaultImg: require('@/assets/service/defCoure.jpg'),
    }
  },
  methods: {
    zanbtn(id, likeId) {
      if (likeId > 0) {
        this.DeleteStoryLike(id)
      } else {
        this.AddStoryLike(id)
      }
    },
    AddStoryLike(id) {
      var that = this
      this.http
        .AddStoryLike({
          type: 1,
          storyId: id,
          userId: this.userInfo ? this.userInfo.centerNo : 0,
        })
        .then(function (res) {
          if (res.status == 1) {
            let newList = list
            for (let i in newList) {
              if (newList[i].id == id) {
                newList[i].likeId = 1
              }
            }
          }
        })
    },
    DeleteStoryLike(id) {
      var that = this
      this.http
        .DeleteStoryLike({
          type: 1,
          id: id,
          userId: this.userInfo ? this.userInfo.centerNo : 0,
        })
        .then(function (res) {
          if (res.status == 1) {
          }
        })
    },
    handleStoryDetail(item) {
      this.$router.push({ name: 'StoryDetail', query: { id: item.id } })
    },

  },
}
</script>
<style lang="scss" scoped>
.tab_content {
  box-sizing: border-box;
  overflow: auto;
}
.tab_btn_box {
  .tab_btn {
    width: 178px;
    height: 52px;
    border-radius: 16px;
    border: none;
    background: rgba(255, 255, 255, 0.36);
    color: #666666;
    padding: 0;
    margin-right: 16px;
    &.active {
      background: #ffffff;
      color: #4092ff;
    }
  }
}
.abroad {
  padding: 18px 0;
  .padding_box {
    padding: 0 28px;
    padding-bottom: 16px;
  }
  .uni_item_mini {
    position: relative;
    margin-top: 16px;
    display: inline-block;
    width: 336px;
    vertical-align: top;
    &:nth-of-type(2n-1) {
      margin-right: 22px;
      clear: both;
    }
    .img_box {
      position: relative;
      border-radius: 16px;
      overflow: hidden;
      width: 342px;
      height: 248px;
      background-size: cover;
      background-position: center;
    }
    .content {
      margin-top: 6px;
      .title {
        display: -webkit-box;
        font-size: 28px;
        line-height: 40px;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
        overflow: hidden;
        -webkit-box-orient: vertical;
        margin-top: 20px;
      }
      .name{
        font-size: 24px;
        color: #333;
        padding: 10px 0;
        .like {
            display: inline-block;
            position: absolute;
            right: 0;
            img {
              width: 32px;
              margin-right: 10px;
            }
            span {
              font-size: 26px;
              margin-right: 10px;
              vertical-align: top;
            }
        }
      }
      .address {
        font-size: 24px;
        margin-top: 20px;
        color: #999999;
      }
      .tag_box {
        padding-top: 6px;
        .tag {
          display: inline-block;
          margin-bottom: 10px;
          margin-right: 10px;
          color: #4092ff;
          font-size: 20px;
          border-radius: 4px;
          border: 2px solid #4092ff;
          padding: 0px 6px;
        }
      }
    }
  }
  .line {
    width: 100%;
    height: 16px;
    background: #f5f6fa;
  }
}
</style>
