<template>
	<view class="container">
		<view class="list">
      
			<view class="item u-flex u-row-between u-col-top" v-for="(item,index) in list" :key="index"  @click="gotoDetail(item.id)">
				<view class="l">
					<view class="title u-l-1">{{item.goodsName}}</view>
					<view class="name">{{item.typeName}}</view>
				</view>
				<view class="r">
					 {{type == 0?'销售数量':'求购数量'}}：{{item.quantity}}{{item.measureUnit}}
				</view>
			</view>
      
    </view>
	</view>
</template>

<script>
  // import { listSalesDemandLish } from "@/api/lef/demandPublish.js";
  
  import {addSales,addPurchase} from '@/api/home.js'
	export default {
		data() {
			return {
				list: [],
				page: 1,
				pageSize: 10,
				total: 0,
				nolist: false,
				type: 0
			}
		},
		onLoad(o) {
			this.type = o.type
			uni.setNavigationBarTitle({
				title: this.type == 0 ? '销售需求详情' : '求购需求详情'
			});
			this.loadData()
		},
		methods: {
			gotoDetail(id){
				uni.navigateTo({
					url:`/pages/index/tradeList/sellDetail?id=${id}&type=${this.type}&add=true`
				})
			},
      loadData(callback) {
			  console.log('this',this.type)
		  if(this.type == 0){
				addPurchase({
				  page: this.page,
				  pageSize: this.pageSize 
				}).then((res) => {
				  if (res.code == 200) {
					if(this.page == 1){
						this.list = [];
					}
					this.list = this.list.concat(res.rows)
					if(res.rows.length < this.pageSize){
						// this.showNoData = true;
					}
				  } else {
					uni.showToast({
					  title: res.msg,
					  icon: "none",
					  duration: 1500
					});
				  }
				})
		  }else{
			  addSales({
			    page: this.page,
			    pageSize: this.pageSize 
			  }).then((res) => {
			    if (res.code == 200) {
			      if(this.page == 1){
			      	this.list = [];
			      }
			      this.list = this.list.concat(res.rows)
			      if(res.rows.length < this.pageSize){
			      	// this.showNoData = true;
			      }
			    } else {
			      uni.showToast({
			        title: res.msg,
			        icon: "none",
			        duration: 1500
			      });
			    }
			  })
		  }
      },
		},
    
    
    onPullDownRefresh(){
    	this.page=1;
    	this.loadData(()=>uni.stopPullDownRefresh());
    },
    onReachBottom(){
    	this.page=this.page+1;
    	this.loadData();
    },
	
  }
</script>

<style lang="scss" scoped>
	$color: #4892FD;

	.container {
		padding: 10rpx 30rpx 100rpx;
		background: #fff;

		.list {
			width:100%;
			.item {
				border-bottom: 2rpx solid #eee;
				padding: 25rpx 0;

				&:last-child {
					border-bottom: 0;
				}

				.l {
					flex: 1;
					width: 1rpx;
					margin-right: 20rpx;

					.title {
						font-size: 32rpx;
						font-weight: bold;
						color: #333333;
						line-height: 50rpx;
						height: 50rpx;
					}

					.name {
						margin-top: 20rpx;
						font-size: 26rpx;
						font-weight: 500;
						color: #777777;
						line-height: 40rpx;
						height: 40rpx;
					}
				}

				.r {
					font-size: 26rpx;
					font-weight: 500;
					color: #0D0D0D;
					line-height: 80rpx;
					height: 80rpx;
				}
			}
		}
	}
</style>