<template>
	<view class="container">
		<view class="content">
			<view class="top">
				<view>合同编号</view>
				<view>{{contractNo}}</view>
			</view>
			<view class="car-container" v-for="(item,index) in list">
				<view class="car-num title">{{item.carNo}}({{item.tranCarNo}})</view>
				<view class="car-type-item">
					<view class="left">净重</view>
					<view class="left">{{item.netWeight}}吨</view>
				</view>
				<view class="car-type-item">
					<view class="left">结重</view>
					<view class="left">120.4{{item.settlementWeight}}吨</view>
				</view>
				<view class="car-type-item">
					<view class="left">扣款</view>
					<view class="left">{{item.deductionAmountchange}}元/吨</view>
				</view>
				<view class="car-type-item">
					<view class="left">应付</view>
					<view class="left">{{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> -->
			 <u-button type="primary" class="submit" hover-class="none" >???</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 {
		margin: 10rpx;
		padding: 20rpx 20rpx 140rpx 20rpx;
		border-radius: 20rpx;
		background: white;
	}

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

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

		.car-type-item {
			display: inline-flex;
			// justify-content: center;
			width: 50%;
		}
	}

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

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