<template>
	<view> 
		<uni-list>
			<uni-list-item v-for="(item, index) in listData" :key="index" @click="goDetail(item.id)" clickable>
				<view slot="body" class="slot-box">
					<view class="row">
						<view class="column-left">编号：</view>
						<view class="column-right section-title">{{item.id}}</view>
					</view>
					<view class="row">
						<view class="column-left">标题：</view>
						<view class="column-right">{{item.title}}</view>
					</view>
					<view class="row">
						<view class="column-left">原因：</view>
						<view class="column-right">{{item.reason}}</view>
					</view>
					<view class="row">
						<view class="column-left">项目：</view>
						<view class="column-right">{{item.projectName}}</view>
					</view>					
					<view class="row" >
						<view class="column-left">申请日期：</view>
						<view class="column-right">{{item.createDateStr}}</view>
					</view>
					<view class="row">
						<view class="column-left">当前状态：</view>
						<view class="column-right">{{item.stateName}}</view>
					</view>
				</view>
			</uni-list-item>
		</uni-list>
		<view style="bottom: 15px;right:10px;position: fixed;z-index: 50;"  v-show="isAdd">
			<router-link :to="'/pages/template/InsertzzSupplierEx/InsertzzSupplierEx'" style="text-decoration: none;" title="申请添加">
				<uni-icons type="plus-filled" size="80" color="#5678FE"></uni-icons>
			</router-link>
		</view>
		
		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
	</view>
</template>

<script>
	
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import {
		GetzzSupplierExList,GetzzSupplierExListByProject
	} from "@/common/api/requisitionApi.js";

	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				listData: [],
				last_id: '',
				reload: false,
				status: 'more',
				adpid: '',
				type:0,
				isAdd:true,
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				}
			};
		},
		onLoad() {
			console.info("当前登录状态:" + this.$store.state.isLogin);
			//console.info(this);
			this.$util.persistLogin(this);
			this.adpid = this.$adpid;
            
			//this.getList();
		},
		onPullDownRefresh() {
			this.reload = true;
			this.last_id = '';

			this.getList();
		},
		onReachBottom() {
			this.status = 'more';
			this.getList();
		},
		created: function() {
			if(!this.$util.isEmpty(this.$util.getQuery("projectCode")))
			{
				uni.setNavigationBarTitle({
					title:"供应商申请"
				});
			}
			else{
				uni.setNavigationBarTitle({
					title:"我提交的信息"
				});
			}
			this.getList();
			//console.info("usercode",this.$store.state.user.userCode);
			console.info("aa");
		},
		methods: {

			getList() {
				let that = this;
				let supplierCode=this.$util.getState(this,'user').supplierCode;
				let projectCode=this.$util.getQuery("projectCode");
				console.info('projectCode',projectCode);
				if(!this.$util.isEmpty(projectCode))
				{
					this.isAdd=false;
					GetzzSupplierExListByProject(projectCode).then((res) => {
					console.info(res);
					if(typeof res=="string"){
						uni.showToast({
							title:res,
							duration:4000,
							icon:'none'
						});
						return;
					}
					
					res.forEach(function(item, index, array) {
						that.$set(that.listData, index, item);
					});
					console.info(that.listData);
					});
				}
				else{
					this.isAdd=true;
					//let type=this.$util.getQuery("type")-0;
					GetzzSupplierExList(supplierCode).then((res) => {
						console.info(res);
						if(res=="-1"){
							uni.showToast({
								title:'供应商编号不能为空',
								duration:4000,
								icon:'none'
							});
							return;
						}
						if(res=="-2"){
							uni.showToast({
								title:'执行过程中出现系统错误，执行中断',
								duration:4000,
								icon:'none'
							});
							return;
						}
						res.forEach(function(item, index, array) {
							that.$set(that.listData, index, item);
						});
						console.info(that.listData);
					});
				}
				
			},
			goDetail: function(id) {
				console.info('godetail',id);
				//console.info(id);			    
				uni.navigateTo({
					// requisitiondetail
					url: '../zzSupplierExDetail/zzSupplierExDetail?id=' + id
				});
			},
			
		}
	};
</script>

<style scoped lang="scss">
	.uni-list-item{
		border-bottom: $BgColorBlue;
	} 
	
</style>
