<template>
  <div class="message-list">
    <van-nav-bar title="短信代收" left-arrow :border="true" @click-left="onNavBack" />
    <div class="newsNotData" v-show="list.length == 0">宝贝暂时还没有短信记录~</div>
    <!-- 下拉加载 -->

    <!-- todo -->
    <van-tabs v-model="tabActive" v-show="false">
      <van-tab>
        <template #title> <van-icon name="more-o" />选项 </template>
        内容 {{ tabActive }}
      </van-tab>
      <van-tab>
        <template #title> <van-icon name="more-o" />选项 </template>
        内容 {{ tabActive }}
      </van-tab>
    </van-tabs>

    <van-list
      v-model="loading"
      class="call-list-container"
      :finished="finished"
      finished-text
      :immediate-check="false"
      @load="onLoad"
    >
      <!-- 有短信的样式 -->
      <div v-for="(item, index) in list" class="call-list" :key="index">
        <van-row type="flex" justify="center" class="date-row">
          <van-col span="12"></van-col>
        </van-row>
        <div class="call-list-content">
          <van-row type="flex" justify="center">
            <van-col span="12">
              <p class="send-number">
                <span style="color: #999">发送方：</span>
                {{ item.sendNumber || '' }}
              </p>
            </van-col>
            <van-col span="11" offset="1">
              <p class="time">{{ item.createTime || '' }}</p>
            </van-col>
          </van-row>
          <van-row type="flex" justify="center">
            <van-col span="24">
              <p class="call-list-detail">{{ item.smsContent || '' }}</p>
            </van-col>
          </van-row>
          <van-row type="flex" justify="center">
            <van-col span="14">
              <p class="receive-number" v-show="item.receiveNumber">接收方：{{ item.receiveNumber || '' }}</p>
            </van-col>
            <van-col span="9" offset="1">
              <p class="time" v-show="item.readFlag">宝贝{{ item.readFlag ? '已读' : '未读' }}</p>
            </van-col>
          </van-row>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import DialogService from '../../services/dialog-service';
import ToastService from '../../services/toast-service';
// 引入List
import APIDevice from '../../api/device';
export default {
  data() {
    return {
      loading: false,
      finished: false, //没有更多了  加载完
      list: [],
      pageNumber: 8,
      begNumber: 1,
      tabActive: 0
    };
  },
  methods: {
    // 返回
    onNavBack() {
      this.$router.push({ name: 'Myself' });
    },
    // 上拉加载
    onLoad() {
      this.loading = false;
      // setTimeout(()=>{
      // console.log('触发了加载');
      // this.pageNumber=this.pageNumber+=2;
      // this.getCallList(this.pageNumber);
      // this.loading=false;
      // if(this.list.length<=8){
      //   this.loading = false;
      //   this.finished=true;
      // }
      // },1500)
    },
    // 获取数据
    getCallList() {
      ToastService.loading();
      /* let url = `/api/DeviceCommunication/SetSMSLog`;
        let jsonData = {
          deviceId: this.$store.getters.deviceId,
          pageNumber: this.pageNumber,
          begNumber: this.begNumber
        }; */
      /* this.$axios.post(url, jsonData) */
      APIDevice.setSMSLog({
        deviceId: this.$store.getters.deviceId,
        pageNumber: this.pageNumber,
        begNumber: this.begNumber
      }).then(res => {
        if (res.data.stateCode === 1) {
          // console.log(res.data);
          this.list = res.data.smsLogList || [];
          this.assembleData();
          ToastService.clear();
          ToastService.success({
            message: '获取成功'
          });
        } else {
          DialogService.confirm({
            title: res.data.message
          });
        }
      });
    },
    assembleData() {
      if (this.list.length > 0) {
        this.list = this.list.map(item => {
          if (item.createTime) {
            let pastTime = item.createTime;
            // eslint-disable-next-line no-useless-escape
            let lastTime = pastTime.replace(/\-/g, '/');
            item.createTime = lastTime;
          }
          return item;
        });
      }
    }
  },

  created() {
    this.getCallList();
  }
};
</script>

<style lang="scss">
//    上拉加载样式
.message-list {
  .van-list__finished-text,
  .van-loading__text {
    font-size: 36px !important;
    margin-top: 20px !important;
  }

  .van-tab {
    font-size: 28px;
    display: flex;
    justify-content: center;
    .van-tab__text {
      margin: auto;
    }
  }
  .newsNotData {
    height: calc(100vh - 160px);
    font-size: 32px;
    @include flexbox(center, center, column, nowrap);
  }
  .call-list-container {
    height: calc(100vh - 160px);
    overflow: scroll;
    padding-bottom: 20px;
    background-color: $background;
  }

  .call-list {
    padding: 20px;
    .date-row {
      background-color: $background;
    }
    .call-list-date {
      color: #999;
      font-size: 24px;
      text-align: center;
      margin-bottom: 30px;
    }
    .call-list-content {
      background-color: #fff;
      padding: 40px;
      border-radius: 30px;
      .send-number {
        font-size: 28px;
        color: #999;
      }
      .time {
        text-align: right;
        font-size: 28px;
        color: #999;
      }
      .receive-number {
        text-align: left;
        font-size: 28px;
        color: #999;
      }
      .call-list-record {
        color: #313131;
        font-size: 30px;
        margin-bottom: 20px;
      }
      .call-list-detail {
        color: #999;
        font-size: 24px;
      }
    }
    .record {
      color: #313131;
      font-size: 26px;
    }
    .detail {
      color: #666;
      font-size: 28px;
    }
  }
}
</style>
