<template>
	<MeScroll  :up="up" :down="down" @up="upFn" :fixed="false" @down="downFn" @init="initMeScroll">
		<u-toast ref="uToast"/>
		<card @pass="pass" @fail="fail" :list="list" ></card>
	</MeScroll>
</template>
<script>
	import MeScroll from '@/components/mescroll-body/mescroll-uni.vue'
	import card from './card.vue'
	export default {
		components:{
			MeScroll,card
		},
		props: {
			type: Number,
			i: Number,
			item:Object
		},
		data() {
			return {
				//审核不通过时展示
				modelShow:false,
				//审核不通过的原因
				dataDetail:{},
				
				isInit: false, // 是否初始化
				list: [], // 列表数据
				mescroll: null, // mescroll 对象
				// 上拉配置参数
				up: {
					noMoreSize: 5, 
					auto: false,
					page: {
						page: 0,
						size: 10
					}
				},
				// 下拉配置参数
				down: {
					use: false, 
					auto: false
				}
			}
		},
		created() {
			
		},
		watch:{
			type(val) {
				if(!this.isInit && val === this.i) {
					this.mescroll.resetUpScroll()
				}
			}
		},
		mounted() {
			if(!this.isInit && this.i === 0) {
				this.mescroll.resetUpScroll()
			}
		},
		methods: {
			/**
			 * 通过审核
			 */
			pass(data){
				let that=this
				let item=this.$u.deepClone(data)
				this.$dialog.showModal("确定通过？").then(res=>{
					item.auditStatus=1
					this.$api.shop.submit(item).then(res=>{
						if (res.success==true) {
							this.$u.toast(res.msg)
							that.mescroll.resetUpScroll()
						}
					})
				})
			},
			/**
			 * 显示审核不通过的意见框
			 * @param {Object} item
			 */
			fail(item){
				this.$emit('showOpinion',item)
			},
			/**
			 * @param {Object} mescroll 初始化组件
			 */
			initMeScroll(mescroll) {
				this.mescroll = mescroll
			},
			/**
			 * @param {Object} mescroll 上拉回调
			 */
			upFn(mescroll) {
				let params={
					mallId:this.vuex_mallId,
					current:mescroll.num,
					size:mescroll.size
				}
				if (this.item.value!=-1) {
					params.auditStatus=this.item.value
				}
				try{
					this.$api.mall.getShopList(params).then(res=>{
						let data=res.data.records
						let length=data.length
						let total=res.data.total
						mescroll.endBySize(length, total);
						if(mescroll.num == 1) this.list = []; //如果是第一页需手动制空列表
						this.list=this.list.concat(data); //追加新数据
					})
				}catch(e){
					mescroll.endErr();
				}
			},
			/**
			 * 下拉回调
			 * */
			downFn(mescroll) {
				setTimeout(()=>{
					this.$u.toast('刷新成功')
					this.mescroll.resetUpScroll()
				},1500)
			},
		}
	}
</script>

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