<template>
	<view class="warp">
		<view class="topInfo">
			<view class="topInfo-item">
				<view class="flex info">
					<view class="logo">
						<image src="../../../static/img/reject.png" mode="" v-if="list.status == '已驳回'"
							style="height: 40rpx;"></image><!-- 驳回 -->
						<image src="../../../static/img/tongguo.png" mode="" v-if="list.status == '已通过'"
							style="height: 40rpx;"></image><!-- 通过 -->
						<image src="../../../static/img/daishenhe.png" mode="" v-if="list.status == '审核中'"
							style="height: 40rpx;"></image><!-- 待审核 -->
					</view>
					<view class="infoText">{{list.status}}</view>
				</view>
				<view class="infoData">{{list.updateDate}}</view>
			</view>
		</view>
		<view class='content1'>
			<view class="title">基本信息</view>
			<view class='row'>
				<view class="left">仓库</view>
				<view class="right">{{list.warehouseName}}</view>
			</view>
			<view class='row'>
				<view class="left">货名</view>
				<view class="right">{{list.goodsName}}</view>
			</view>
			<view class='row'>
				<view class="left">基准水分（%）</view>
				<view class="right">{{list.waterBase}}</view>
			</view>
			<view class='row'>
				<view class="left">干粮水分（%）</view>
				<view class="right">{{list.waterMin}}</view>
			</view>
			<view class='row'>
				<view class="left">水分上限（%）</view>
				<view class="right">{{list.waterMax}}</view>
			</view>
			<view v-if="list.paramType == '2'" class='row'>
				<view class="left">扣重比</view>
				<view class="right">{{list.deductWeight}}</view>
			</view>
			<view class='row'>
				<view class="left">干粮收购价格（元/公斤）</view>
				<view class="right">{{list.dryGrainPrice}}</view>
			</view>
			<view class='row boder'>
				<view class="left">销售上限</view>
				<view class="right">{{list.saleLimit}}</view>
			</view>
		</view>
		<view class="content2">
			<view class="title">粮价设置</view>
			<view v-for="(item,index) in list.details" :key="index">
				<view class="row">
					<view class="left">等级</view>
					<view class="right">{{item.level}}</view>
				</view>
				<view v-if="list.paramType == '2'" class="row">
					<view class="left">基准单价（元/公斤）</view>
					<view class="right">{{item.basePrice}}</view>
				</view>
				<view class="row" v-for="(item1,index1) in item.modelList" :key="index1"
					:class="index1==item.modelList.length-1?'boder':''">
					<view v-if="list.paramType == '2'" class="left">{{item1.startWater}}-{{item1.endWater}}降幅（元/0.1%）
					</view>
					<view v-else class="left">{{item1.startWater}}-{{item1.endWater}}扣重比</view>
					<view class="right">{{item1.price}}</view>
				</view>
			</view>
		</view>
		<view v-if='show1' class="shade">
			<view class="wrap">
				<view class="alert-top">
					<view class="title">
						审核意见（驳回）
					</view>
					<u-icon name="close" class="close" color="#8890B1" @click="close()"></u-icon>
				</view>
				<view class="u-textarea-style">
					<view class="right-bottom">
						{{rejectInfo.length}}/100个字
					</view>
					<u-input class="" v-model='rejectInfo' placeholder="请在此输入审核意见" type="textarea" height="414"
						maxlength="100" />
				</view>
				<!-- 	<u-button @click="show1 = false"  class="cancel">取消</u-button>
				<u-button @click="reject()" class="confirm">确定</u-button> -->
				<view @click='show1 = false' class="cancel">取消</view>
				<view @click='reject()' class="confirm">确定</view>
			</view>
		</view>
		<view v-if='show2' class="shade">
			<view class="wrap">
				<view class="alert-top">
					<view class="title">
						审核意见（通过）
					</view>
					<u-icon name="close" class="close" color="#8890B1" @click="close()"></u-icon>
				</view>
				<view class="u-textarea-style">
					<view class="right-bottom">
						{{rejectInfo1.length}}/100个字
					</view>
					<u-input class="" v-model='rejectInfo1' placeholder="请在此输入审核意见" type="textarea" height="414"
						maxlength="100" />
				</view>
				<!-- <u-button @click="show2 = false" class="cancel">取消</u-button>
				<u-button @click="audit()"  class="confirm">确定</u-button> -->
				<view @click='show2 = false' class="cancel">取消</view>
				<view @click='audit()' class="confirm">确定</view>
			</view>
		</view>
		<u-toast ref="uToast" />
		<view style='padding:10px;' class='flex bottom-btn'>
			<u-button v-if='isSHowBtn' @click='show1 = true' type="error" class="btn1" hover-class='none'>驳回</u-button>
			<u-button v-if='isSHowBtn' @click='show2 = true' type="success" class="btn2">通过</u-button>
		</view>
	</view>
</template>

<script>
	import helper from '@/common/helper.js';
	import {
		mapState
	} from 'vuex';
	export default {
		name: "task",
		data() {
			return {
				everyCheck: '',
				isSHowBtn: true,
				show: false,
				height: 200,
				autoHeight: true,
				border: false,
				show2: false,
				show1: false,
				rejectInfo: "",
				rejectInfo1: "",
				id: 0,
				list: {},
				pcUserInfo: uni.getStorageSync('pcUserInfo'),
				switchVal: false,
				contractNoList: []
			};
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		onBackPress(e) {
			if (this.everyCheck) {
				uni.navigateTo({
					url: "/pages/task/my_task"
				})
				return true;
			}
		},
		onLoad(options) {
			this.everyCheck = uni.getStorageSync("everyTask")
			this.id = options.id
			this.isSHowBtn = options.isShowbtn
		},
		onShow() {
			var that = this
			this.$nextTick(function() {
				that.getData()
			})
		},
		methods: {
			close() {
				this.show1 = false
				this.show2 = false
			},
			getData() {
				var data = []
				this.$api.doRequest('get', '/purchasePrice/purchasePriceLook', {
					id: this.id
				}).then(res => {
					if (res.data.code == 200) {
						this.list = res.data.data
					}
				})
			},
			confirm(item) {
				this.list.contractNo = item[0].value
			},
			audit() {
				var that = this
				that.show2 = false
				uni.showModal({
					content: "是否确定通过审核？",
					showCancel: true,
					confirmText: '确定',
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title: "审核中"
							})
							// that.$api.doRequest('post', '/purchasePrice/purchasePriceEdit', that.list)
							// 	.then(res => {
							// 		if (res.data.code == 200) {
										that.$api.doRequest('post', '/workflow/api/handle', {
											approved: true,
											auditMind: that.rejectInfo1,
											needReapply: true,
											taskId: that.list.taskId,
										}).then(res1 => {
											if (res1.data.code == 200) {
												that.$api.msg('审核成功');
												setTimeout(function() {
													if (this.everyCheck) {
														helper.setAudit(that.list)
													} else {
														uni.navigateBack()
													}
													uni.hideLoading()
												}, 1000);
											} else {
												that.$api.msg(res1.data.message);
											}
										})
									// } else {
									// 	that.$api.msg('系统异常，请联系管理员');
									// }
								// })
						}
					}
				})

			},
			reject() {
				if (!this.rejectInfo) {
					this.$api.msg('驳回原因不能为空！')
				} else {
					var that = this
					that.show1 = false
					uni.showModal({
						content: "是否确定驳回？",
						showCancel: true,
						confirmText: '确定',
						success: function(res) {
							if (res.confirm) {
								that.$api.doRequest('post', '/workflow/api/handle', {
									taskId: that.list.taskId,
									approved: false,
									auditMind: that.rejectInfo,
									needReapply: true,
								}).then(res1 => {
									if (res1.data.code == 200) {
										that.$api.msg('驳回成功');
										setTimeout(function() {
											if (that.everyCheck) {
												helper.setAudit(that.list)
											} else {
												uni.navigateBack()
											}
											uni.hideLoading()
										}, 1000);
									} else {
										that.$api.msg(res1.data.message);
									}
								})
							}
						}
					})
				}
			}
		}
	}
</script>

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

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

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

		.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: 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;
		}
	}

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

	.boder {
		border: 0;
		border-bottom: 0 !important;
	}

	.topInfo {
		height: 210rpx;
		background: linear-gradient(270deg, #22C572 0%, #34DE8A 100%);
		padding: 30rpx;

		.topInfo-item {
			height: 150rpx;
			background-color: #FFFFFF;
			border-radius: 20rpx;
			padding: 40rpx;

			.logo {
				width: 40rpx;
				height: 40rpx;
				margin-top: 8rpx;
			}

			.infoText {
				font-size: 36rpx;
				font-weight: 600;
				margin-left: 20rpx;
			}

			.infoData {
				color: #878C9C;
				font-size: 26rpx;
				margin-top: 10rpx;
			}
		}
	}

	.shade {
		position: fixed;
		top: 0;
		left: 0;
		height: 100%;
		width: 100%;
		background: rgba(0, 0, 0, 0.4);
		z-index: 3;

		.wrap {
			position: absolute;
			left: 0;
			top: 0;
			right: 0;
			bottom: 0;
			margin: auto;
			background: #fff;
			width: calc(100% - 198rpx);
			height: 700rpx;
			border-radius: 20rpx;

			.alert-top {
				padding: 33rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				position: relative;
			}

			.title {
				font-size: 32rpx;
				font-weight: 600;
				color: #333333;
			}

			.close {
				position: absolute;
				right: 33rpx;
			}
		}
	}

	// .cancel,
	// .confirm {
	// 	position: absolute;
	// 	display: inline-block;
	// 	width: 50%;
	// 	text-align: center;
	// 	bottom: 0;
	// 	padding: 10px;
	// 	border-top: 1px solid #eee;
	// 	font-size: 34rpx;
	// }

	// .cancel {
	// 	left: 0;
	// 	border-right: 1px solid #eee;
	// 	color: #AFB3BF;
	// }

	// .confirm {
	// 	right: 0;
	// 	color: #22C572;
	// }
	.u-textarea-style {
		margin: 20rpx;
		background: #F9F9FA;
		border-radius: 10px;
		border: 1px solid #EEEEEE;
		padding: 10rpx 20rpx;
		position: relative;

		.right-bottom {
			position: absolute;
			right: 20rpx;
			bottom: 20rpx;
			color: #AFB3BF;
		}
	}

	/deep/.u-input__textarea {
		height: 300rpx !important;
	}

	.cancel,
	.confirm {
		position: absolute;
		display: inline-block;
		width: 50%;
		text-align: center;
		bottom: 0;
		padding: 10px;
		border-top: 1px solid #eee;
		font-size: 34rpx;
	}

	.cancel {
		left: 0;
		border-right: 1px solid #eee;
		color: #AFB3BF;
	}

	.confirm {
		right: 0;
		color: #22C572;
	}
</style>
