<template>
	<MeScroll  :up="up" :down="down" @up="upFn" :fixed="false" @down="downFn" @init="initMeScroll">
		<card @showDetail="showDetail" @pass="pass" @fail="fail" :list="list" ></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: {
			params:Object,
			type: Number,
			i: Number,
			item:Object
		},
		data() {
			return {
				//审核不通过时展示
				modelShow:false,
				//审核不通过的原因
				opinion:'',
				dataDetail:{},
				
				memberId:'',
				isInit: false, // 是否初始化
				list: [], // 列表数据
				mescroll: null, // mescroll 对象
				// 上拉配置参数
				up: {
					noMoreSize: 3, 
					auto: true,
					page: {
						page: 0,
						size: 10
					}
				},
				// 下拉配置参数
				down: {
					use: true, 
					auto: false
				}
			}
		},
		created() {
			this.memberId=getApp().globalData.member.id
		},
		methods: {
			showDetail(item){
				this.$emit('test',item)
			},
			/**
			 * 通过审核
			 */
			pass(item){
				let that=this
				let {rootOrgId,orgPosition,orgId,...params}=item
				params.auditStatus=1
				let operation="guestRecord/updateGuestRecord"
				uni.showModal({
					title:"提示",
					content:"确定审核通过该访客信息吗？",
					showCancel:true,
					success: (res) => {
						if (res.confirm) {
							getApp().globalData.postRequest(params,operation,function(res){
								console.log(res);
								that.mescroll.resetUpScroll()
							})
						}
					}
				})
			},
			/**
			 * 审核不通过
			 * @param {Object}
			 */
			submitFailAudit(){
				let that=this
				let {rootOrgId,orgPosition,orgId,...params}=item
				params.auditStatus=2
				let operation="guestRecord/updateGuestRecord"
				uni.showModal({
					title:"提示",
					content:"确定审核不通过该访客信息吗？",
					showCancel:true,
					success: (res) => {
						if (res.confirm) {
							getApp().globalData.postRequest(params,operation,function(res){
								console.log(res);
								that.mescroll.resetUpScroll()
							})
						}
					}
				})
			},
			/**
			 * 显示审核不通过的意见框
			 * @param {Object} item
			 */
			fail(item){
				this.dataDetail=item
				this.modelShow=true
			},
			/**
			 * @param {Object} mescroll 初始化组件
			 */
			initMeScroll(mescroll) {
				this.mescroll = mescroll
			},
			/**
			 * @param {Object} mescroll 上拉回调
			 */
			upFn(mescroll) {
				try{
					let that=this
					let params={
						member_id:that.memberId,
						current:mescroll.num,
						size:mescroll.size,
					}
					if (this.item.value!=-1) {
						params.auditStatus=this.item.value
					}
					if (!this.$isEmpty(this.params.id)) {
						params.id=this.params.id
					}
					if (!this.$isEmpty(this.params.guestName)) {
						params.guestName=this.params.guestName
					}
					if (!this.$isEmpty(this.params.guestTel)) {
						params.guestTel=this.params.guestTel
					}
					let operation='guestRecord/getListByMemberId'
					getApp().globalData.postRequest(params,operation,function(res){
						let data=res.data.list
						let length=data.length
						let total=res.data.total
						mescroll.endBySize(length, total);
						if(mescroll.num == 1) that.list = []; //如果是第一页需手动制空列表
						that.list=that.list.concat(data); //追加新数据
					})
				}catch(e){
					mescroll.endErr();
				}
			},
			/**
			 * 下拉回调
			 * */
			downFn(mescroll) {
				setTimeout(()=>{
					this.mescroll.resetUpScroll()
					uni.showToast({
						title:"刷新成功",
						icon:"none",
						position:"top"
					})
				},1500)
			},
		}
	}
</script>

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