<template>
	<MeScroll  :up="up" :down="down" @up="upFn" :fixed="false" @down="downFn" @init="initMeScroll">
		<card @deleteItem="deleteItem" :list="list" @cancel="cancel"></card>
	</MeScroll>
</template>
<script>
	import MeScroll from '@/comps/mescroll-body/mescroll-uni.vue'
	import card from './card.vue'
	var app=getApp()
	export default {
		components:{
			MeScroll,card
		},
		props: {
			refresh:Boolean,
			type: Number,
			i: Number,
			item:Object
		},
		data() {
			return {
				isInit: false, // 是否初始化
				list: [], // 列表数据
				mescroll: null, // mescroll 对象
				// 上拉配置参数
				up: {
					noMoreSize: 5, 
					auto: false,
					page: {
						page: 0,
						size: 10
					}
				},
				// 下拉配置参数
				down: {
					use: true, 
					auto: false
				}
			}
		},
		watch:{
			refresh() {
				console.log("我要刷新了");
				this.mescroll.resetUpScroll()
			},
			type(val) {
				if(!this.isInit && val === this.i) {
					this.mescroll.resetUpScroll()
				}
			}
		},
		mounted() {
			if(!this.isInit && this.i === 0) {
				this.mescroll.resetUpScroll()
			}
		},
		methods: {
			/**
			 * @param {Object} item 删除订单
			 */
			deleteItem(item){
				let that=this
				app.globalData.twoFailHint("确定要取消该工单？",function(){
					//删除状态
					item.status=-1
					// let operation='estateRepair/addEstateRepair'
					that.$http.addEstateRepair(item).then(res =>{
						if (res.data.add_result==true) {
							app.globalData.oneFailHint("删除成功成功");
							that.mescroll.resetUpScroll()
						}else{
							app.globalData.oneFailHint(res.data.add_result);
						}
						
					});
				})
			},
			/**
			 * 取消订单
			 * @param {Object} item 订单实体
			 */
			cancel(item){
				let that=this
				app.globalData.twoFailHint("确定要取消该工单？",function(){
					item.jobStatus=-1
					// let operation='estateRepair/addEstateRepair'
					that.$http.addEstateRepair(item).then (res =>{
						if (res.data.add_result==true) {
							app.globalData.oneFailHint("取消成功");
							that.mescroll.resetUpScroll()
						}else{
							app.globalData.oneFailHint(res.data.add_result);
						}
						
					});
				})
			},
			/**
			 * @param {Object} mescroll 初始化组件
			 */
			initMeScroll(mescroll) {
				this.mescroll = mescroll
			},
			/**
			 * @param {Object} mescroll 上拉回调
			 */
			upFn(mescroll) {
				let that=this
				let data={
					"page":{
						current:mescroll.num,
						size:mescroll.size,
					},
					memberId:getApp().globalData.member.id,
					jobStatus:this.item.value
				}
				//已处理,待评价
				if (this.item.value==2) {
					//已处理
					data.jobStatus=1
					//待评价
					data.estimateStatus=0
				}
				// let operation='estateRepair/estateRepairList'
				try{
					that.$http.estateRepairList(data).then (res=>{
						console.log("repairList",JSON.stringify(res))
						let estateRepairList=res.data.estateRepairList
						let length=estateRepairList.records.length
						let data=estateRepairList.records
						mescroll.endBySize(length, estateRepairList.total);
						if(mescroll.num == 1) that.list = []; //如果是第一页需手动制空列表
						that.list=that.list.concat(data); //追加新数据
						
					});
				}catch(e){
					mescroll.endErr();
				}
			},
			/**
			 * 下拉回调
			 * */
			downFn(mescroll) {
				setTimeout(()=>{
					this.list=[]
					this.mescroll.resetUpScroll()
				},1500)
			},
		}
	}
</script>

<style lang="scss" scoped>
	view{
		box-sizing: border-box;
	}
</style>
