<template>
  <div class="mobile-center">
    <div class="com-mobile-header mobile-center-header">
      <a @click="goLastPage"><i class="iconfont icon-fanhui"></i></a>
      <p>消息</p>
      <p class="en-name"><img :src="`/images/mobile/center/${user.data.enterprise.uu ? 'en' : 'self'}.png`" alt="">{{currentEnName}}</p>
    </div>
    <div class="mobile-content">
      <div v-if="messageList.content && messageList.content.length" class="message-list" v-bind:key="item.id" v-for="item in messageList.content">
        <div class="content">
          <div class="new-dot">
            <b v-if="item.isRead === 0"></b>
            <img src="/images/mobile/center/user/message.png" alt="">
          </div>
          <div class="message">
            <p>{{item.createTime | time}}</p>
            <a :href="item.type === 'MALL跳转卖家待报价页面' ? '/vendor#/seekPurchase?type=1' : item.type === 'MALL公共询价' ? '/user#/seekPurchase' : item.type === '商城公共询价采纳结果' ? '/vendor#/vendorPurchaseOffer' : ''"
               v-if="item.type"
               :title="item.content" class="info" target="_blank">{{item.content}}</a>
            <a v-else :title="item.content" class="noLink info">{{item.content}}</a>
          </div>
        </div>
      </div>
      <empty-status v-if="!messageList.content.length"  :showLink="true" :text="'抱歉，暂无消息'"></empty-status>
    </div>
    <pull-up :searchMore="fetching" :allPage="allPage" :page="page" @pullUpAction="onPullUpAction"></pull-up>
  </div>
</template>
<script>
  import { RemindBox, PullUp, EmptyStatus } from '~components/mobile/common'
  export default {
    middleware: 'authenticated',
    layout: 'mobileNoHeader',
    data () {
      return {
        count: 10,
        page: 1
      }
    },
    fetch ({ store }) {
      let user = store.state.option.user.data
      return Promise.all([
        // 获取消息列表
        store.dispatch('messageShow/getAllMessage', { receiverUu: user.userUU, receiverEnuu: user.enterprise.uu, consumerApp: 'MALL', count: 10, page: 1, sorting: {'createTime': 'DESC'} })
      ])
    },
    computed: {
      user () {
        return this.$store.state.option.user
      },
      messageList () {
        return this.$store.state.messageShow.messageList.list.data
      },
      fetching () {
        return this.messageList.fetching
      },
      allPage () {
        return Math.floor(this.messageList.totalElements / this.messageList.size) + Math.floor(this.messageList.totalElements % this.messageList.size > 0 ? 1 : 0)
      }
    },
    components: {
      RemindBox,
      PullUp,
      EmptyStatus
    },
    methods: {
      reloadList: function () {
        this.$store.dispatch('messageShow/getAllMessage', { receiverUu: this.user.data.userUU, receiverEnuu: this.user.data.enterprise.uu, consumerApp: 'MALL', page: this.page, count: this.count, sorting: {'createTime': 'DESC'} })
      },
      onPullUpAction: function () {
        this.page++
        this.reloadList()
      }
    }
  }
</script>
<style lang="scss" scoped>
  .mobile-content {
    margin-top: .6rem !important;
    padding: .2rem;
    background: #f1f3f6;
    .com-none-state {
      padding-bottom: 100%;
    }
    .message-list {
      background: #fff;
      padding: 0 .15rem 0 .2rem;
      .content {
        padding: .14rem 0;
        overflow: hidden;
        border-bottom: 1px solid #d3d3d3;
        .new-dot {
          position: relative;
          b{
            position: absolute;
            left: .2rem;
            top: .25rem;
            width: .16rem;
            height: .16rem;
            border-radius: 50%;
            background: #fc0405;
          }
        }
        img{
          margin: .3rem 0 0 .12rem;
          float: left;
          width: .8rem;
          height: .8rem;
        }
        .message{
          margin-left: .24rem;
          float: left;
          width: 5.4rem;
          p{
            display: inherit;
            margin-bottom: .1rem;
            text-align: right;
            font-size: .24rem;
            color: #666;
          }
          a.info{
            font-size: .28rem;
            color: #333;
          }
        }
      }
    }
  }
  .message-list:last-child .content{
     border-bottom: none;
   }
</style>
