<template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  <seller-base :show="false"><view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view-wrapper div container">
    <view class="div common-header-wrap">
      <view class="status-holder"></view>
      <view :style="'height:'+navHeight+'px'"></view>
      <view class="common-header-holder"></view>
      <view class="common-header-fixed">
      <title-header />
      <uni-nav-bar title="通知消息" class="common-header" left-icon="back" @clickLeft="goBack()">
      </uni-nav-bar>
    </view>
    </view>
<view class="scroll-view div" style="position:relative">
      <scroll-view style="position: absolute;top:0;right:0;left:0;bottom:0" class="div" v-infinite-scroll="loadMore" infinite-scroll-disabled="loading" infinite-scroll-distance="10">
    <view
      class="div body"
      v-if="notice_list && notice_list.length"

    >
      <view
        class="div notice-message-body"
        v-for="(item, index) in notice_list"
        :key="item.storemsg_id"
      >
          <view class="p">{{$moment.unix(item.storemsg_addtime).format('YYYY-MM-DD HH:mm')}}</view>
          <view class="div notice-track">
              <view class="div notice-status">
                  <view class="p title">{{ item.storemt_name }}</view>
                  <view class="p content">{{ item.storemsg_content }}</view>
              </view>

          </view>

      </view>
    </view>
    <empty-record v-else-if="notice_list && !notice_list.length"></empty-record>
  </scroll-view>
  </view>
</view>
</seller-base>
</template>

<script>
import {getFontSize} from '@/util/common'
import TitleHeader from '../../TitleHeader'
import SellerBase from '../SellerBase'
import { getNoticeList } from '../../../api/sellerNotice'

import EmptyRecord from '../../EmptyRecord'
export default {
  name: 'NoticeList',
  components:{
    TitleHeader,
    SellerBase,
    EmptyRecord
  },
  computed:{
  fontSize(){
    return getFontSize()
  },
  },
  data(){
    return {
        navHeight: 0,
        params: { 'page': 0, 'per_page': 10 },
        loading: false, // 是否加载更多
        isMore: true, // 是否有更多
      message_type_text: ['私信', '系统消息', '留言'],
      notice_list: false,
    }
  },
  created () {
	this.loadMore()
  },

  mounted(){
    // #ifdef  MP-WEIXIN
    this.navHeight = uni.getMenuButtonBoundingClientRect().height
    // #endif
  },
  methods:{
    goBack(){uni.navigateBack({delta:1})},
      loadMore () {
          this.loading = true
          this.params.page = ++this.params.page
          if (this.isMore) {
              this.loading = false
              this.getNoticeList(true)
          }
      },
    getNoticeList () {
      uni.showLoading({ title: '加载中' })

          getNoticeList(this.params).then(res => {
            uni.hideLoading()
              if (res.result.hasmore) {
                  this.isMore = true
              } else {
                  this.isMore = false
              }

            let temp = res.result.notice_list
            if (temp) {
              if (!this.notice_list) {
                this.notice_list = temp
              } else {
                this.notice_list = this.notice_list.concat(temp)
              }
            }
          }).catch(function (error) {
            uni.hideLoading()
            uni.showToast({icon:'none',title: error.message})
          })


    }
  }
}
</script>

<style scoped lang="scss">
	.scroll-view-wrapper{display: flex;flex-direction: column;}
	.scroll-view{flex:1}
    .container {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        .header {

            border-bottom: 1px solid #e8eaed;
            position: fixed;
            width: 100%;
            z-index: 1;
        }
        .body {
            width: 100%;
            .notice-message-body {
                width: 100%;
                height: 100%;
                > .p {
                    text-align: center;
                    margin-top: 1rem;
                    margin-bottom: 0.5rem;
                    font-size:$fontSize;
                    color: #7c7f88;
                }
                .notice-track {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    height: 100%;
                    background: rgba(255, 255, 255, 1);
                    border-radius: 0.1rem;
                    margin:0 0.5rem;
                    .notice-status {
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        flex-wrap: wrap;
                        margin: 0.6rem 0.75rem 0.7rem 0.75rem;
                        .title {
                            font-size:$subFontSize;
                            color: #333;
                            margin:0 0 0.7rem 0;
                        }
                        .content {
                            font-size:$fontSize;
                            color: #666;
                            width: 100%;
                            height: 100%;
                        }
                    }
                    .arrow-right {
                        width:0.25rem;
                        height: 0.5rem;
                        margin-right: 0.6rem;
                        margin-left: 0.65rem;
                    }
                }
            }
        }
    }
</style>
