<template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  <member-base :show="false"><view style="position: absolute;top:0;right:0;left:0;bottom:0" class="scroll-view-wrapper div container member-arrivalnotice">
    <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" @scrolltolower="loadMore" scroll-y="true">
    <view class='div item-wrapper' v-if="arrivalnotice_list && arrivalnotice_list.length">
		<view class='div item-list' v-for="(item, index) in arrivalnotice_list" :key='index' @click="onDelete(item.arrivalnotice_id)">
			<view class="div info" @click="goGoods(item.goods_id)">
			  <view class="div title" >{{ item.goods_name }}</view>
			  <view class="div time">{{ $moment.unix(item.arrivalnotice_addtime).format('YYYY.MM.DD') }}</view>
			</view>
			<view class="div right" :class="item.arrivalnotice_state==2?'number':'diture'">{{ item.arrivalnotice_state==2?'已通知':'未通知' }}</view>
		</view>
	</view>
    <empty-record v-else-if="arrivalnotice_list && !arrivalnotice_list.length"></empty-record>
  </scroll-view>
  </view>
</view>
</member-base>
</template>

<script>
import {getFontSize} from '@/util/common'
import TitleHeader from '../../TitleHeader'
import { urlencode } from '@/util/common'
import MemberBase from '../MemberBase'
import { getArrivalnoticeList, delArrivalnotice } from '../../../api/memberArrivalnotice'
import EmptyRecord from '../../EmptyRecord'
export default {
  components:{
    TitleHeader,
    MemberBase,
    EmptyRecord
  },
  computed:{
  fontSize(){
    return getFontSize()
  },
  },
  data(){
    return {
      navHeight: 0,
      params: { 'page': 0, 'per_page': 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      wrapperHeight: 0,

      arrivalnotice_list: false
    }
  },
  created () {

  this.loadMore()

  },

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

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

        let temp = res.result.arrivalnotice_list
        if (temp) {
          if (!this.arrivalnotice_list) {
            this.arrivalnotice_list = temp
          } else {
            this.arrivalnotice_list = this.arrivalnotice_list.concat(temp)
          }
        }
      }).catch(function (error) {
        uni.hideLoading()
        uni.showToast({icon:'none',title: error.message})
      })
    },
    reload () {
      this.params = { 'page': 0, 'per_page': 10 }
      this.loading = false
      this.isMore = true
      this.arrivalnotice_list = false
      this.loadMore()
    },
    goGoods (goods_id) {
      uni.navigateTo({ url: '/pages/home/goodsdetail/Goodsdetail'+'?'+urlencode( { 'goods_id': goods_id } )})
    }
  }
}
</script>

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

}
.header {
  border-bottom: 1px solid #e8eaed;
}
.item-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  .item-list {
    background-color: #fff;
    border-bottom: 1px solid #e8eaed;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.55rem 0.75rem;
    .right{width:2.5rem;}
    .info {
      flex:1;
      .title {
        font-size:$subFontSize;
        color: #333;
      }
      .time {
        font-size:$fontSize;
        color: #999;
        margin-top:0.25rem;
      }
    }
    .number {
      font-size:$h2;
      color:$primaryColor;
    }
    .diture {
      font-size:$h2;
      color: rgba(102, 102, 102, 1);
    }
  }
}

</style>
