<template>
	<view class="container">
		<view class="content">
			<view class="top content-item">
				<view>{{contractNo}}({{list[0].goodsName}})</view>
				<view>元/吨</view>
			</view>
			<view class="content-item">
				<view class="car-container" v-for="(item,index) in list">
					<view class="car-num title">{{item.carNo}}</view>
					<view class="row">
						<view class="left car-type-item">净重</view>
						<view class="right weightInfoCss">{{item.netWeight}} 吨</view>
					</view>
					<view class="row">
						<view class="left car-type-item">结重</view>
						<view class="right weightInfoCss">{{item.settlementWeight}} 吨</view>
					</view>
					<view class="row">
						<view class="left car-type-item">扣款</view>
						<view class="right weightInfoCss">￥{{item.deductionAmountchange?item.deductionAmountchange:"0"}}/吨</view>
					</view>
					<view class="row ">
						<view class="left money">应付</view>
						<view class="right moneyInfo">￥{{item.amountIngPayable}}元</view>
					</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 style='padding:10px;' class='flex bottom-btn'>
			<u-button  @click='rejectSubmit' type="error" class="btn1">驳回</u-button>
			<u-button  @click='passSubmit' type="success" class="btn2">通过</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: "",
				currentPage: 1,
				pageSize: 10,
				list: [],
				contractNo: "",
			}
		},
		onLoad(options) {
			this.id = options.id
			this.getList()
		},
		methods: {
			getList(id) {
				this.$api.doRequest('get', '/stockPurchaseReceiptReport/getInfo', {
					id: this.id
				}).then(res => {
					this.contractNo = res.data.data.contractNo
					if (res.data.code == 200) {
						this.$api.doRequest('get', '/stockPurchaseReceiptReport/selectPurchaseOrder', {
							compId: "2710b21efc1e4393930c5dc800010dc4",
							currentPage: this.currentPage,
							pageSize: this.pageSize,
							contractNo: this.contractNo,
						}).then(res => {
							if (res.data.code == 200) {
								this.list = res.data.data.records
							}
						})
					}
				})
			},
			//驳回
			rejectSubmit() {
				var that = this
				if (this.list.length == 0) {
					that.$api.msg('没有要审核的条目！')
				} else {
					// uni.showModal({
					// 	content: "是否确定驳回?",
					// 	success(res) {
					// 		if(res)
					// 		this.audit(this.list[0], 0, false, true, '已驳回')
					// 	}
					// })


					uni.showModal({
						content: "是否确定驳回？",
						showCancel: true,
						confirmText: '确定',
						success: function(res) {
							if (res.confirm) {
								that.audit(that.list[0], 0, false, true, '已驳回')
							}
						}
					})
				}
			},
			//通过
			passSubmit() {
				var that = this
				if (this.list.length == 0) {
					that.$api.msg('没有要审核的条目！')
				} else {
					// uni.showModal({
					// 	content: "是否确定通过?",
					// 	success(res) {
					// 		if(res)
					// 		this.audit(this.list[0], 0, true, 2)
					// 	}
					// })
					uni.showModal({
						content: "是否确定通过？",
						showCancel: true,
						confirmText: '确定',
						success: function(res) {
							if (res.confirm) {
								that.audit(that.list[0], 0, true, 2)
							}
						}
					})
				}
			},
			//审核方法
			audit(item, index, status, status2, reason) {
				if (index < this.list.length) {
					this.$api.doRequest('post', '/workflow/api/handle', {
						taskId: item.taskId,
						approved: status,
						auditMind: reason != undefined ? '已驳回' : '34',
						needReapply: status2 != undefined ? true : false,
					}).then(res => {
						this.audit(this.list[index + 1], index + 1, status)
					})
				} else {
					if (status == true) {
						that.$api.msg('通过成功')
						this.getList()
					} else if (status == false) {
						that.$api.msg('驳回成功')
						this.getList()
					}
				}
			},
		}
	}
</script>

<style scoped lang="scss">
	.container {
		padding: 20rpx 20rpx 250rpx 20rpx;
	}

	.content {
		.top {
			display: flex;
			justify-content: space-between;
		}

		.content-item {
			border-radius: 20rpx;
			background: white;
			padding: 40rpx 20rpx;
			margin-bottom: 30rpx;
		}

		.title {
			font-size: 32rpx;
			font-weight: 600;
			color: #333333;
			text-align: left;
			margin: 20rpx 0;
		}
		.car-container{
			border-bottom: 2rpx solid #EEEEEE;
		}

		.car-type-item {
			font-size: 28rpx;
			margin: 20rpx 0;
			color: #878C9C;
		}

		.weightInfoCss {
			font-size: 28rpx;
			color: #333333;
			font-weight: 500;
		}

		.row {
			display: flex;
			justify-content: space-between;
			// .right,
			// input {
			// 	font-size: 28rpx;
			// 	// color: #333333;
			// }
		}

		.money {
			font-size: 32rpx;
			font-weight: 500;
			margin-bottom: 30rpx ;
		}

		.moneyInfo {
			color: #22C572;
			font-size: 32rpx;
		}
	}
.bottom-btn {
		width: 100%;
		position: fixed;
		bottom:0;
		display: flex;
		z-index: 2;
		left: 0;
		background-color: #f8f8f8;
		flex-direction: column;
		.btn1,.btn2{
			width: 100%;
			margin-bottom: 26rpx;
			border-radius: 90rpx;
		}
		.btn1{
			background: white;
			color: #00C265;
		}
		}
</style>
