<template>
	<view class="car">
		<!-- 列表 -->
		<view class="carlists">
			<car-list :datainfo="list"  :wtdt="wtdt" type='feeset' @getDetail="getDetail" @getDelFn="getDelFn"></car-list>
		</view>
		<block v-if="checkPermi(['wuYe:fee:settings:add'])">
			<view style="height: 100rpx;"></view>
			<view class="rfbtn" @click="getFeeSetFn">添加设置</view>
		</block>
		<loading></loading>
	</view>
</template>

<script>
	import config from '@/config'
	const baseUrl = config.baseUrl
	import carList from "@/work/components/car/list.vue"
	import {feesetList,feesetDel} from "@/api/work/manage.js"
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	export default{
		components:{carList},
		data(){
			return{
				list:[],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
			}
		},
		onUnload() {
			uni.$off('refsetList')
		},
		onLoad: function() {
			uni.$on('refsetList',(res)=>{
				this.getrefreshData()
			})
			this.getDataFn()
		},
		// 上拉触底加载更多触发事件
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			getDetail(id){
				this.$tab.navigateTo("/work/pages/fee/set?id="+id)
			},
			getFeeSetFn(){
				this.$tab.navigateTo("/work/pages/fee/set")
			},
			getAddFn(){
				
			},
			getrefreshData(){
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn()
			},
			getDelFn(data){
				var that=this;
				feesetDel(data).then(res=>{
					if(res.code==200){
						this.$toast("删除成功");
						setTimeout(function(){
							that.getrefreshData()
						},1500)
					}
				})
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
				}
				feesetList(params).then(res=>{
					if(res.code==200){
						if (res.rows.length < this.pageSize) {
							this.reachflag = false
							this.wtdt = '到底了~';
						} else {
							var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -	1)
							if (num < res.total) {
								this.reachflag = true
								this.wtdt = ''
							} else {
								this.reachflag = false
								this.wtdt = '到底了~';
							}
						}
						var newArr=JSON.parse(JSON.stringify(res.rows))
						newArr.forEach(ite=>{
							ite.right=0;
						})
						if (this.pageNum == 1) {
							this.list = newArr;
						} else {
							this.list = this.list.concat(newArr)
						}
					}else{
						this.$toast(res.msg)
					}
				})
				
			},
		}
	}
</script>
<style>
	page{background: #F3F3F0;}
</style>
<style lang="scss" scoped>
.car{padding: 24rpx 0 10rpx;}
.carlists{padding: 0 18rpx;}
</style>