<template>
  <div class="bg" style="min-width: 1800px">
    <div class="top-btn">
      <div class="top-item moren">荆州市红十字会欢迎您！</div>
      <div class="top-item">
        <span class="hand" style="padding-right: 6px" @click="goHome()">返回首页</span
        ><img src="../../assets/img/backhome.png" alt="" class="hand" @click="goHome()"/>
      </div>
    </div>
    <div class="base-bg" style="min-width: 1800px; max-width: 1920px">
      <img
        src="../../assets/img/mourn-bg.png"
        alt=""
        style="min-width: 1800px; max-width: 1920px"
      />
    </div>
    <div class="list-wrap">
      <div
        class="list"
        style="height: (318 * boxHeight + 500) + 'px'; min-height: 1500px"
      >
        <div class="list-tit moren">器官/遗体捐献网上纪念堂</div>
        <div class="serch-wrapper">
          <div class="search-left">
            <img src="../../assets/img/flower-black.png" alt="" />
            <div class="moren">悼念总数：{{mournAll || 0}}</div>
          </div>
          <div class="search">
            <input
              type="text"
              v-model="keyword"
              placeholder="请输入捐献者"
              class=""
              @keyup.enter="getList()"
            />
            <img
              src="../../assets/img/search.png"
              class="hand"
              @click="getList()"
            />
          </div>
        </div>
        <div class="list-item" v-for="item in list" :key="item.image">
          <div class="item-logo">
            <img class="logo-pepo" :src="item.image" />
            <img class="logo-hq" src="../../assets/img/hq.png" />
          </div>
          <div class="item-name moren">{{item.name}}</div>
          <div class="item-btn hand" @click="goDaonian(item)">在线悼念</div>
        </div>
        <div class="page-wrap">
          <el-pagination
            layout="prev, pager, next"
            :total="total"
            background
            prev-text="上一页"
            next-text="下一页"
            @current-change="currentChange"
            :page-size="20"
          ></el-pagination>
        </div>
      </div>
    </div>
    <audio id="audio" :src="require('../../assets/music/bg-music.mp3')" loop ref="music" controls hidden></audio>
    <page-bottom :backgroundBg="'#fff'" :textcolor="'#031A2A'"></page-bottom>
  </div>
</template>
<script>
import PageBottom from "../../components/pageBottom/PageBottom.vue";
import { getMournList, getAllNum } from '../../request/api.js'
export default {
  data() {
    return {
      list: [],
      page: 1,
      limit: 20,
      total: 0,
      keyword: "",
      mournAll: ''
    };
  },
  components: {
    PageBottom,
  },
  mounted() {
    // this.$nextTick(()=> {
    //   this.$refs.music.play()
    // })
    this.getMournList()
    this.getAllNum()
    // let oAudio = document.querySelector('#audio')
    // oAudio.onended = function() {
    //   oAudio.load()
    //   oAudio.play()
    // }
    // this.audioAutoPlay()
    // setTimeout(() => {
    //   this.$refs.music.currentTime = 0;
    //   this.$refs.music.play();
    // }, 100);
     
  },
  methods: {
    // 自动播放
    audioAutoPlay() {
      let audio = document.getElementById('audio')
      audio.play()
      document.removeEventListener('touchstart',this.audioAutoPlay)
    },
    // 获取全部数据
    getAllNum() {
      getAllNum().then(res => {
        console.log(res)
        this.mournAll = res.data
      })
    },
    // 获取捐献列表
    getMournList() {
      let obj = this
      getMournList({
        page: obj.page,
        search: obj.keyword,
        rows:  obj.limit
      }).then(res => {
        console.log(res)
        obj.list = []
        obj.list = res.data.data
        obj.total = res.data.total
      })
    },
    goHome() {
      this.$router.push('/home')
    },
    // 页码改变触发
    currentChange(e) {
      this.page = e;
      this.getMournList()
      // console.log()
      // this.list = e;
      // this.getList();
    },
    // 获取捐献列表
    getList() {
      this.page = 1
      this.getMournList()
    },
    // 在线悼念
    goDaonian(item) {
      this.$refs.music.play();
      this.$router.push("/mourn/detail?id=" + item.id);

    },
  },
  computed: {
    boxHeight() {
      console.log(Math.round(this.list / 4), "Math.round(this.list/4)");
      return Math.round(this.list / 4);
    },
  },
};
</script>
<style scoped lang="scss">
div {
  box-sizing: border-box;
}
.bg {
  background: #dbe2ee;
}
.base-bg {
  width: 100%;
  margin: auto;
  //   padding-top: 66%;
  img {
    // position: absolute;
    width: 100%;
    top: 0;
    left: 0;
  }
}
.list-wrap {
  position: relative;
  width: 1082px;
  // min-height: 1845px;
  height: auto;
  background: #ffffff;
  margin: auto;
  margin-top: -508px;
  padding: 18px 13px;
  margin-bottom: 126px;
  .list {
    width: 100%;
    // min-height: 1845px;
    padding-bottom: 100px;
    // height: 100%;
    // min-height: 100%;
    border: 8px solid #006061;
    position: relative;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-content: flex-start;
    padding-top: 62px;
    .list-tit {
      width: 258px;
      height: 52px;
      line-height: 52px;
      background: #006061;
      text-align: center;
      font-size: 19px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #ffffff;
      position: absolute;
      top: -8px;
      left: -8px;
    }
    .list-item {
      text-align: center;
      width: 203px;
      height: 278px;
      //   margin-bottom: 40px;
      margin: 40px 20px;
      .item-logo {
        width: 203px;
        height: 203px;
        position: relative;
        .logo-pepo {
          width: 160px;
          height: 160px;
          border-radius: 50%;
          position: absolute;
          top: 0;
          left: 0;
          bottom: 0;
          right: 0;
          margin: auto;
        }
        .logo-hq {
          width: 203px;
          height: 203px;
          position: absolute;
          top: 0;
          left: 0;
        }
        // background-image: url(../../assets/img/hq.png);
      }
      .item-name {
        padding: 13px 0;
        font-size: 21px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #071b2a;
      }
      .item-btn {
        width: 97px;
        line-height: 29px;
        background: #006061;
        border-radius: 5px;
        font-size: 15px;
        font-family: PingFang SC;
        font-weight: bold;
        color: #ffffff;
        margin: auto;
      }
    }
  }
}
.serch-wrapper {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  height: 33px;
  position: absolute;
  top: 5px;
  right: 10px;
  .search-left {
    display: flex;
    align-items: center;
    height: 33px;
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: bold;
    color: #031a2a;
    margin-right: 10px;
  }
  .search {
    padding-left: 13px;
    padding-right: 13px;
    width: 295px;
    height: 33px;
    line-height: 33px;
    background: #ffffff;
    border: 1px solid #cccccc;
    border-radius: 10px;
    // margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    input {
      width: 235px;
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: bold;
      outline: none;
      border: none;
    }

    img {
      width: 20px;
      height: 20px;
    }
  }
}
.page-wrap {
  position: absolute;
  bottom: 30px;
  display: flex;
  width: 100%;
  justify-content: center;
}
.top-btn {
  width: 100%;
  min-width: 1800px;
  height: 40px;
  background: rgba($color: #ffff, $alpha: 0.85);
  position: absolute;
  // opacity: 0.85;
  display: flex;
  // justify-content: ;
  align-items: center;
  text-align: center;
  font-size: 13px;
  font-family: PingFang SC;
  font-weight: bold;
  color: #031a2a;
  .top-item {
    width: 50%;
    img {
      width: 15px;
      height: 15px;
      // margin-left: 6px;
    }
  }
}
</style>