<template>
	<view class="warp">
		<view class='content1'>
			<view class='row'>
				<view class="left">仓库</view>
				<view class="right">鲅鱼圈一号库</view>
			</view>
			<view v-for="(item,index) in List">
				<view class='row row1'>
					<view class="left">{{item.paymentNo}}</view>
					<view class="right">{{item.carNo}}</view>
				</view>
				<view class='row'>
					<view class="left">{{item.goodsName}}({{item.netWeight}} - {{item.tidalGrainPrice}})</view>
					<view class="right">{{item.amountIngPayable}}</view>
				</view>
			</view>

		</view>
		<u-toast ref="uToast" />
		<view class="bottom-btn">
			<u-button type="primary" class="submit" hover-class="none" @click="rejectSubmit()">驳回</u-button>
			<u-button type="primary" class="submit" hover-class="none" @click="passSubmit()">通过</u-button>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				id: "",
				currentPage: 1,
				pageSize: 10,
				List: [],
			}
		},
		onLoad(options) {
			this.id = options.id
		},
		onShow(options) {
			this.getList()
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		methods: {
			getList() {
				// this.$api.doRequest('get', '/stockPurchaseReceiptReport/getInfo', {
				// id:this.id
				// }).then(res => {
				// 	if (res.data.code == 200) {
				// 		console.log("hdshfuiehfiuo",res)
				// 	}
				// })
				this.$api.doRequest('get', '/paymentManagement/selectPaymentManagement', {
					currentPage: this.currentPage,
					pageSize: this.pageSize,
					// warehouseName: this.warehouseName,
					managementType: 1
				}).then(res => {
					if (res.data.code == 200) {
						this.List = res.data.data.records
					}
				})
			},
			//駁回
			rejectSubmit() {
				if(this.List.length > 0){
					uni.showModal({
						content: "确定驳回付款申请?",
						success(res) {
							// this.$api.doRequest('get', '/paymentManagement/api/openAuditFlow', {
							// 	compId: "2710b21efc1e4393930c5dc800010dc4",
							// 	id: item.id
							// }).then(res => {
							// 	if (res.data.code == 200) {
							// 		this.List = res.data.data.records
							// 	}
							// })
							 this.audit(this.List[0], 0, false, '', '')
						}
					})
				}
			},
			//通過
			passSubmit() {
				if(this.List.length > 0){
					uni.showModal({
					content: "确定通过付款申请?",
					success(res) {
						 this.audit(this.List[0], 0, true)
					}
				})
				}
			},
			audit(item, index, status, status2, reason) {
				if (this.List.length > 0) {
					if (status == true && item.status == "已驳回") {
						this.$api.doRequest('get', '/paymentManagement/api/openAuditFlow', {
							compId: "2710b21efc1e4393930c5dc800010dc4",
							id: item.id
						}).then(res => {
							if (res.data.code == 200) {
								this.audit(this.List[index + 1], index + 1, status, status2, reason)
							}
						})
					} else {
						this.$api.doRequest('get', '/workflow/api/handle', {
							taskId: item.taskId,
							approved: status,
							auditMind: reason != undefined ? '已驳回' : '34',
							needReapply: status2 != undefined ? true : false
						}).then(res => {
							if (res.data.code == 200) {
								this.audit(this.List[index + 1], index + 1, status, status2, reason)
							}
						})
					}
				} else {
					if (status == true) {
						this.$message.success('通过成功')
						this.getList()
					} else if (status == false) {
						this.$message.success('驳回成功')
						this.getList()
					}
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.warp {
		margin: 10rpx;
		padding: 20rpx 20rpx 140rpx 20rpx;
	}

	.content1,
	.content2 {
		border-radius: 20rpx;
		background: white;
		padding: 20rpx;

		.title {
			font-size: 28rpx;
			font-weight: 600;
			color: #333333;
			text-align: center;
		}

		.row {
			display: flex;
			justify-content: space-between;
			border-bottom: 1px solid #EEEEEE;
			padding: 21rpx 0;

			.right,
			input {
				font-size: 28rpx;
				color: #333333;
			}
		}
	}

	.content2 {
		margin-top: 20rpx;
	}

	.bottom-btn {
		width: 92%;
		position: fixed;
		bottom: 40rpx;
		display: flex;
		z-index: 2;
	}

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

	.row1 {
		border-bottom: 0 !important;
	}
</style>
