<template>
	<view class="content">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="wrap">
				<view class="item-title">物资信息</view>
				<view class="list">
					<view class="item u-flex u-row-between" v-for="item in dataList" :key="item.id">
						<view class="left u-flex">
							<image :src="item.imgUrl" mode="aspectFill"></image>
							<view class="text">
								<view class="name u-m-b-10">{{item.mateName}}</view>
								<view class="u-tips-color">规格：{{item.specCode}}{{filterUnitName(item.unitCode)}}</view>
							</view>
						</view>
						<view class="right">
							<view class="" v-if="askforStatus==1" style="color: #003bff;">
								{{item.askforNum}}{{filterUnitName(item.unitCode)}}
							</view>
						</view>
					</view>
				</view>
			</view>	
		</mescroll-body>
	</view>
</template>

<script>
	import {otherApiUrl} from '@/common/apiurl.js';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			
		},
		data() {
			return {
				id:'',
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {
				},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					}
				},
				// 列表数据
				dataList: [],
				unitNameList:[],
				paymentList:[],
				askforStatus:'',
			}
		},
		onLoad(page) {
			this.id = page.id;
			this.askforStatus = page.askforStatus;
			this.unitNameDict();
			this.getpaymentList();
		},
		computed:{
			filterUnitName(){
				return function(value){
					let v = '';
					for (let i = 0; i < this.unitNameList.length; i++){
						// console.log('value',value);
						// console.log('value',this.unitNameList[i]);
						let item = this.unitNameList[i];
						if (value == item.value) {
						  v = item.label;
						  break;
						}
					}
					return v
				}
			},
			filterPaymentName(){
				return function(value){
					let v = '';
					for (let i = 0; i < this.paymentList.length; i++){
						console.log('value',value);
						console.log('value',this.paymentList[i]);
						let item = this.paymentList[i];
						if (value == item.value) {
						  v = item.label;
						  break;
						}
					}
					return v
				}
			}
		},
		methods: {
			/*上拉加载的回调*/
			upCallback(page) {
				let params ={
					pageNum:page.num,
					pageSize:page.size,
					askfoId:this.id,
				} 
				this.$u.api.applyDetailsProduct(params).then(curPageData=>{
					console.log('curPageData',curPageData)
					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					// this.mescroll.endSuccess(curPageData.data.total);
					this.mescroll.endBySize(curPageData.rows.length, curPageData.total);
					//设置列表数据
					if(page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList=this.dataList.concat(curPageData.rows); //追加新数据
				}).catch((err)=>{
					uni.showToast({
						title:'链接失败'
					});
					console.log('err',err)
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
				
			},
			/*若希望重新加载列表,只需调用此方法即可(内部会自动page.num=1,再主动触发up.callback)*/
			reloadList(){
				this.mescroll.resetUpScroll();
			},
			async unitNameDict() {
				let { code, data, msg} = await this.$u.get(otherApiUrl.getDict + 'goods_unit_name')
				if(code === 200) {
					this.unitNameList = data.map(item => {
						return {
							label: item.dictLabel,
							value: item.dictValue
						}
					})
				}
			},
			async getpaymentList() {
				let { code, data, msg} = await this.$u.get(otherApiUrl.getDict + 'payment')
				if(code === 200) {
					this.paymentList = data.map(item => {
						return {
							label: item.dictLabel,
							value: item.dictValue
						}
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
.item{
	margin: 24rpx;
	padding: 24rpx;
	border: 1px solid #ddd;
	border-radius: 10rpx;
	.left image {
		width: 120rpx;
		height: 120rpx;
		border-radius: 8rpx;
		margin-right: 12rpx;
	}
}
.info-item{
	margin-bottom: 10rpx;
}
</style>
