<template>
  <div class="list">
    <div class="list-content">
      <div class="item" :id="'id'+item.label"  v-for="(item, index) in list" :key="index">
        <div class="title">{{item.label}}</div>
        <div class="phone-list">
          <div class="item-info" v-for="(e, indexs) in item.dataList" :key="indexs">
            <p>{{e.name}}</p>
            <div class="phone">
              <span>{{e.type}}</span>{{e.phone}}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="id-list">
      <a class="item" :href="'#id'+item.label" v-for="(item, index) in list" :key="index">{{item.label}}</a>
    </div>
    <div class="footer-btn" @click="toAddList">我添加的</div>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {

  data() {
    return {
      list: [],
    }
  },
  computed: { ...mapState(['user']) },
  mounted() {
    this.getList()
  },

  methods: {
    getList() {
      this.$http.post(`/app/appconvenientaddressbook/list`, null, {
        params: {
          areaId: this.user.areaId,
        }
      }).then(res => {
        if (res.code == 0) {
          var list = []
          var data = []
          res.data.records.map((item) => {
            if(list.indexOf(item.nameInitials)) {
              list.push(item.nameInitials)
            }
          })
          list.map((item) => {
            var obj = {
              label: item,
              dataList: []
            }
            data.push(obj)
          })
          data.map((item, index) => {
            res.data.records.map((items) => {
              if(item.label == items.nameInitials) {
                data[index].dataList.push(items)
              }
            })
          })
          this.list = data
        }
      })
    },
    toAddList() {
      this.$emit('change', {
        type: 'MyAddList',
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.list {
  background-color: #F3F6F9;
  .list-content{
    padding-bottom: 112px;
    .title{
      padding-left: 48px;
      line-height: 64px;
      font-size: 26px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #999;
    }
    .phone-list{
      background-color: #fff;
      width: 100%;
      .item-info{
        width: 100%;
        padding: 32px 48px;
        box-sizing: border-box;
        box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.02);
        p{
          font-size: 32px;
          font-family: PingFangSC-Medium, PingFang SC;
          font-weight: 500;
          color: #333;
          line-height: 44px;
          word-break: break-all;
          margin-bottom: 8px;
        }
        .phone{
          font-size: 26px;
          font-family: PingFangSC-Regular, PingFang SC;
          color: #333;
          line-height: 36px;
          span{
            display: inline-block;
            margin-right: 16px;
            color: #999;
          }
        }
      }
    }
  }
  .id-list{
    width: 50px;
    text-align: center;
    position: fixed;
    top: 160px;
    right: 32px;
    z-index: 99;
    .item{
      display: block;
      font-size: 24px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #CCC;
      line-height: 40px;
    }
  }
  .footer-btn{
    width: 100%;
    text-align: center;
    height: 112px;
    line-height: 112px;
    background: #3975C6;
    box-shadow: 0px 1px 0px 0px #EEEEEE;
    position: fixed;
    bottom: 0;
    left: 0;
    font-size: 32px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #FFF;
    z-index: 999;
  }
  a {
    text-decoration: none;
  }
}
</style>