<template>
	<view>
		<view class="" style="padding-bottom: 150rpx;">
			<view class='wrap' v-for="(item, index) in tableData" :key="index">
				<view class="" style="display: flex;">
					<view class="c-row top_type_left">
						<view class="title">{{item.purpose}}—{{item.expensesType=='1'?'收款':'请款'}}
							<!-- <view @click="requestFunds(1)" v-if="item.expensesType == '1'">收款</view>
							<view @click="requestFunds(2)" v-else-if="item.expensesType == '2'">请款
							</view> -->
						</view>
					</view>
					<view class="top_type_right">
						<view class="wenzi audit1" v-if="item.approveStatus != null && item.status != '已驳回'  ">
							{{item.approveStatus}}
						</view>
						<view class="wenzi audit2" v-else-if="item.approveStatus == null ">{{item.status}}</view>
						<view class="wenzi audit3" v-else-if="item.status == '已驳回' ">{{item.status}}</view>
					</view>
				</view>
				<view class="c-row" style="color:#777e7d;">
					<view class="title">
						<view class="title1" v-if="item.expensesPurpose == '1'">{{item.contractNo}}</view>
						<view class="title1" v-else-if="item.expensesPurpose == '3'">{{item.warehouseName}}
						</view>
						<view class="title1" v-else-if="item.expensesPurpose == '5'">{{ }}</view>
					</view>
				</view>
				<view class="c-row" style="font-size: 35rpx;font-weight:550; padding-top:30rpx">
					<view class="title"> {{item.expenseName}}</view>
				</view>
				<view class="c-row" style="padding-top:10rpx">
					<view class="title" style="color:#777e7d;">{{item.createDate}}</view>
				</view>
				<view class="c-row1">
					<view class="title1"> {{item.amountMoney}} 元</view>
				</view>
				<view style="display: flex;justify-content: flex-end;margin-top: 30rpx;flex-wrap: wrap;">
					<!-- v-if="item.status == '已驳回'" -->
					<!-- v-if="item.status == '已驳回'" -->
					<!-- <view class="wenzi1 audit" v-if="!item.approveStatus && item.status =='已驳回' "  @click="rejecttext(item)">驳回原因</view> -->
					<view class="wenzi1 audit"v-if="item.approveStatus && item.approveStatus !='发起人撤回' " @click="withdraw(item)">撤回</view>
					<view class="wenzi1 audit" @click="deleExpense(item)"
						v-if="item.status=='已驳回'||item.approveStatus=='发起人撤回'">删除</view>
					<view class="wenzi1 audit" @click="requestFunds(3,item)"
						v-if="item.status=='已驳回'||item.approveStatus=='发起人撤回'">编辑</view>
						<view class="wenzi1 audit" @click="gofujian(item)">补充附件</view>
					<view class="wenzi1 audit" @click="getRequestFunds(1,item)">查看</view>
				</view>
			</view>
			<view v-show="isLoadMore">
				<uni-load-more :status="loadStatus"></uni-load-more>
			</view>
		</view>
		<u-modal v-model="show" title="驳回原因">
			<view class="slot-content">
				<rich-text :nodes="rejectcontent"></rich-text>
			</view>
		</u-modal>
		<u-toast ref="uToast" />
		<view class="bottom-btn">
			<view class="btn" @click="requestFunds(1)">收款</view>
			<view class="btn" @click="requestFunds(2)">请款</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageSize: 10,
				currentPage: 1,
				tableData: [],
				reType: '',
				flag: '',
				rejectcontent:'',
				show:false,
				isLoadMore: false, //是否加载中
				loadStatus: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
			}
		},
		onShow() {
			this.tableData=[]
			this.getList()
		},
		//下拉刷新
		onPullDownRefresh() {
			this.currentPage = 1
			this.isLoadMore = false
			this.loadStatus = 'loading'
			this.getList()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() { //上拉触底函数
			if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
				this.isLoadMore = true
				this.currentPage += 1
				this.getList()
			}
		},
		methods: {
			rejecttext(val){
				this.$api.doRequest('get', '/commonUser/getReason', {
					id: val.id,
				}).then(res => {
					if (res.data.code == 200) {
						this.show=true
						this.rejectcontent=res.data.data
						that.getList()
					} else {
					}
				})
				
			},
			withdraw(val){
				
				var that = this
				uni.showModal({
					content: "撤回成功后，可再次提交，确定撤回吗？",
					showCancel: true,
					confirmText: '确定',
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '加载中',
								mask: true
							})
							that.$api.doRequest('post', '/newWorkflow/api/stopInstance', {
								businessKey: val.id,
								workflowId: val.workflowId,
							}).then(res => {
								if (res.data.code == 200) {
									uni.hideLoading()
									that.$api.msg('撤回成功')
									that.getList()
								} else {
									uni.hideLoading()
									that.$api.msg('撤回成功')
								}
							})
						}
					}
				})
			},
			gofujian(val){
				uni.navigateTo({
					url: '/pages/reimbursement/addaccessory?id=' + val.id + "&expensesType=" + val
						.expensesType
				})
			},
			getList() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.$api.doRequest('get', '/expenseInfo/selectInfo', {
					pageSize: this.pageSize,
					currentPage: this.currentPage,
					compId: uni.getStorageSync('pcUserInfo').compId,
					createUserId : uni.getStorageSync('userInfo').id
				}).then(res => {
					if (res.data.code == 200) {
						uni.hideLoading()
						if (res.data.data.records.length > 0) {
							this.isLoadMore = false
							this.loadStatus = 'loading'
						} else {
							this.isLoadMore = true
							this.loadStatus = 'nomore'
						}
						if (this.currentPage == 1) {
							this.tableData = res.data.data.records
						} else {
							this.tableData = this.tableData.concat(res.data.data.records)
						}

					}
				})
			},
			deleExpense(val) {
				var title
				var that = this
				if (that.expensesType == '1') {
					title = "确定删除收款信息？"
				} else {
					title = "确定删除请款信息？"
				}
				uni.showModal({
					content: title,
					showCancel: true,
					confirmText: '确定',
					success: function(res) {
						if (res.confirm) {
							that.$api.doRequest('post', '/expenseInfo/deleteInfo', {
								id: val.id,
							}).then(res => {
								if (res.data.code == 200) {
									that.$api.msg('删除成功')
									that.getList()
								} else {
									that.$api.msg('删除失败')
								}
							})
						}
					}
				})
			},
			requestFunds(e, val) {
				if (val) {
					uni.navigateTo({
						url: '/pages/reimbursement/request_funds?id=' + val.id + "&expensesType=" + val
							.expensesType
					})
				} else {
					uni.navigateTo({
						url: '/pages/reimbursement/request_funds?reType=' + e
					})
				}

			},
			getRequestFunds(e, val) {
				uni.navigateTo({
					url: '/pages/reimbursement/get_request_funds?id=' + val.id
				})
			},
		}
	}
</script>

<style lang='scss' scoped>
	page {
		background: #F5F6FA;
	}

	.wrap {
		padding-top: 30rpx;
		padding-bottom: 50rpx;
		font-size: 28rpx;
		background: #fff;
		margin: 20rpx;
		border-radius: 20rpx;

		input {
			font-size: 14px;
		}

		>.title {
			padding: 10px 16px;
		}

		>.title1 {
			padding: 10px 16px;
		}

	}

	.wenzi {
		border-radius: 10rpx;
		height: 42rpx;
		text-align: right;
		margin-right: 30rpx;
	}

	.audit1 {
		color: #ff5500;
	}

	.audit2 {
		color: #00df00;
	}

	.audit3 {
		color: red;
	}

	.wenzi1 {
		margin:10rpx 40rpx 10rpx 0;
		/* margin-top: 10rpx; */
		/* height: 50rpx;
		width: 100rpx; */
		border-radius: 50rpx;
		background-color: #ffffff;
		/* text-align: center; */
		border: 2rpx solid #AFB3BF;
		display: flex;
		justify-content: center;
		align-content: center;
		padding: 10rpx 20rpx;
	}

	.audit {
		color: #000000;
		text-align: center;
	}


	.c-row {
		display: flex;
		-webkit-box-align: center;
		align-items: center;
		padding: 5rpx 30rpx;
		position: relative;
	}

	.c-row1 {
		display: flex;
		-webkit-box-align: center;
		align-items: center;
		position: relative;
		padding: 0rpx 30rpx;
		justify-content: flex-end;
		margin-top: -21px;
		font-size: 18px;
	}

	.submit {
		width: 40%;
		background: #2c8ac5;
		border-radius: 10rpx;
	}

	.bottom-btn {
		padding: 30rpx;
		background: #FFFFFF;
		width: 100%;
		position: fixed;
		bottom: 0rpx;
		display: flex;
		z-index: 9999;
	}

	.top_type_right,
	.top_type_left {
		width: 50%;
	}

	.bottom-btn {
		display: flex;
		justify-content: space-between;

		.btn {
			border-radius: 50rpx;
			padding: 20rpx 120rpx;
			background: #22C572;
			color: #fff;
			font-size: 32rpx;
			box-sizing: border-box;
		}
	}
	.slot-content{
		text-align: center;
	}
</style>
