<template>
	<view class='purchase-list'>
		<my-tabs @change="tapChange" :modelData="modelData" :initIndex="initIndex"></my-tabs>
		<scroll-view class="purchase-body" scroll-y="true" @scrolltolower="scrolltolower" @scrolltoupper="scrolltoupper" @scroll="scroll" @touchstart="touchstart" @touchend="touchend">
			<my-unit v-for="(item,index) in listData" :key="index" :info="item" :initIndex="initIndex"></my-unit>
		</scroll-view>
	</view>
</template>
<script>
	import { getTodoTaskPage, getDoneTaskPage,getMyProcessInstancePage } from "@/api/work/index"
	import myTabs from '@/components/myTabs/myTabs.vue'
	import myUnit from '@/components/myUnits/purchaseUnit/unit.vue'
	import myPull from '@/static/js/myPull.js'
	export default {
		components:{myTabs,myUnit},
		data() {
			return {
				pageNo: 1,
				pageSize: 10
			}
		},
		onLoad(){
			this.refresh();
		},
		methods: {
			/**
			 * @name 获取列表
			 */
			getList(page,done){
				console.log(`获取第${page}页数据`);
				if(this.initIndex==0){
					getTodoTaskPage({pageNo:page,pageSize: this.pageSize}).then(response => {
						let dataList = response.data.list;
						let list = []
						dataList.forEach(v => {
							list.push({
								title:v.processInstance.name,
								status: v.name,
								time:v.createTime,
								nickname:v.processInstance.startUser.nickname
							})
						})
						done(list);
					});
				}
				if(this.initIndex==1){
					getDoneTaskPage({pageNo:page,pageSize: this.pageSize}).then(response => {
						let dataList = response.data.list;
						let list = []
						dataList.forEach(v => {
							list.push({
								title:v.processInstance.name,
								status: v.name,
								time:v.createTime,
								nickname:v.processInstance.startUser.nickname
							})
						})
						done(list);
					});
				}
				if(this.initIndex==2){
					getMyProcessInstancePage({pageNo:page,pageSize: this.pageSize}).then(response => {
						let dataList = response.data.list;
						let list = []
						dataList.forEach(v => {
							list.push({
								title:v.name,
								status: v.status,
								time:v.startTime,
								nickname:v.currentAuditUser.nickname
							})
						})
						done(list);
					});
				}
				 
				
			},
			
			/**
			 * @name 触底加载
			 */
			scrolltolower(event){
				this.getList(this.page,this.__pulldone)
			},
			
			scroll(e){
				// 重新设置pulldown
				this.setPullDown(e.detail.scrollTop<10)
			},
			
			scrolltoupper(){
				
			},
			
			
			/**
			 * @name 改变tab
			 * @param val 索引
			 */
			tapChange(val){
				this.initIndex=val;
				this.page = 1;
				this.getList(this.page,this.__pulldone)
			}
		},
		mixins:[myPull({})],
		
	}
</script>
<style lang='scss' scoped>
	.purchase-list {
		background-color: #f5f5f5;
		height: 100%;
		overflow: hidden;
		
		.purchase-body{
			height: calc(100% - 88upx);
			overflow: auto
		}
	}
</style>
