<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 pb-30" @scrolltolower="loadMore" scroll-y="true">
        <view class="div" v-if="goods_list">
        <view class="div main-content" v-if="goods_list.length">
        <view v-for="item in goods_list" :key="item.goods_commonid"  class="div mt-5 inviter-item">
			<view class="div goods-info">
				<view class="div p-img" :style="'width:'+windowWidth+'px;height:'+windowWidth+'px'">
					<image mode="aspectFit" class="img" :src="item.goods_image"/>
				</view>
				<view class="div p-info">
				    <view class="div name">{{item.goods_name}}</view>
				    <view class="div price">￥{{item.goods_price}}</view>
				</view>
			</view>
			<view class="inviter-info">
				<view class="info-item">
					<view class="left">已分销</view>
					<view class="right">{{item.inviter_total_quantity}}件</view>
				</view>
				<view class="info-item">
					<view class="left">总金额</view>
					<view class="right">￥{{item.inviter_total_amount}}</view>
				</view>
				<view class="info-item">
					<view class="left">总佣金</view>
					<view class="right">{{item.inviter_amount}}</view>
				</view>
			</view>
			<view class="inviter-btn">
				<view class="common-btn" @click="onEdit(item.goods_commonid)">修改</view>
			</view>
        </view>
        </view>
        <empty-record v-else></empty-record>
        </view>
        </scroll-view>
		<view class='common-add-btn-wrapper'><view class="div common-btn common-add-btn"  @click="goAdd">新增</view></view>
		</view>
</view>
</seller-base>
</template>

<script>
import {getFontSize} from '@/util/common'
import TitleHeader from '../../TitleHeader'
import { urlencode } from '@/util/common'

import SellerBase from '../SellerBase'

import { getInviterGoodsList } from '../../../api/sellerInviter'
import EmptyRecord from '../../EmptyRecord'
import flexLine from '../../flexLine'
export default {
  name: 'GoodsList',
  computed:{
  fontSize(){
    return getFontSize()
  },
  windowWidth: function () {
	const res = uni.getSystemInfoSync()
	var width=res.windowWidth
	var size=getFontSize()
	return (width-3*.6*size)/3
  },
  },
  data(){
    return {
    navHeight: 0,
    params: { 'page': 0, 'per_page': 10 },
      loading: false, // 是否加载更多
      isMore: true, // 是否有更多
      // 分销商品列表
      goods_list: false
    }
  },
  components:{
    TitleHeader,
    SellerBase,
    flexLine,
    EmptyRecord
  },
  onShow: function () {
	this.reload()
  },
  mounted(){
  // #ifdef  MP-WEIXIN
  this.navHeight = uni.getMenuButtonBoundingClientRect().height
  // #endif
  },
  methods:{
    goBack(){uni.navigateBack({delta:1})},
    goAdd () {
      uni.navigateTo({url:'/pages/seller/inviter/GoodsForm'+'?'+urlencode({ action: 'add' })})
    },
    onEdit (goods_commonid) {
      uni.navigateTo({url:'/pages/seller/inviter/GoodsForm'+'?'+urlencode({ goods_commonid: goods_commonid })})
    },
    loadMore () {
      this.loading = true
      this.params.page = ++this.params.page
      if (this.isMore) {
        this.loading = false
        this.getGoodsList(true)
      }
    },
    reload () {
      // 重新加载数据
      this.params.page = 0
      this.isMore = true
      this.goods_list = []
      this.loadMore()
    },
    getGoodsList () {
      getInviterGoodsList(this.params).then(res => {
        if (this.goods_list) {
              this.goods_list = this.goods_list.concat(res.result.goods_list)
          } else {
              this.goods_list = res.result.goods_list
          }
        if (res.result.hasmore) {
          this.isMore = true
        } else {
          this.isMore = false
        }
      }).catch(function (error) {
        uni.showToast({icon:'none',title: error.message})
      })
    }
  }
}
</script>

<style scoped lang="scss">
.scroll-view-wrapper{display: flex;flex-direction: column;}
.scroll-view{flex:1}
.inviter-item{padding: 1rem $pageSpace .5rem;background-color: #fff;border-radius: .5rem;}
.goods-info{display: flex;box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.06);}
.goods-info .p-img{border-radius: .5rem;overflow: hidden;}
.goods-info .p-info{margin-left:.4rem;width: 45%;}
.goods-info .p-info .name{color: #333;font-size: .7rem; line-height: .8rem;height: 1.6rem;margin-top: .4rem;overflow: hidden;display: -webkit-box; -webkit-box-orient: vertical;-webkit-line-clamp: 2;padding: 0 .3rem;box-sizing: border-box;}
.goods-info .p-info .price{color:red;line-height:1rem;font-size:0.7rem;padding-top: 1rem;}
.inviter-info{padding: .5rem 0;}
.inviter-info .info-item{border-bottom: 1px dashed #DBDADF;display: flex;padding: .5rem 0;color: #666;font-size: .8rem;}
.inviter-info .info-item .right{margin-left: auto;}
.inviter-btn {display: flex;justify-content: flex-end;}
.inviter-btn .common-btn{border: 1px solid #333;border-radius: 1rem;padding: .2rem 1.3rem;}
</style>
