<template>
	<view class="warp">
		<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>
		<u-toast ref="uToast" />
		<view style='padding:10px;' class='flex bottom-btn'>
			<u-button  @click='reject' type="error" class="btn1">驳回</u-button>
			<u-button  @click='audit' type="success" class="btn2">通过</u-button>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		name: "task",
		data() {
			return {
				show: false,
				id: 0,
				list: {},
				form: {
					name: '',
					intro: '',
					sex: ''
				},
				radio: '',
				pcUserInfo: uni.getStorageSync('pcUserInfo'),
				switchVal: false,
				contractNoList: []
			};
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		onLoad(options) {
			this.id = options.id
		},
		onShow() {
			var that = this
			this.$nextTick(function() {
				that.getData()
			})
		},
		methods: {
			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
				uni.showModal({
					content: "是否确定通过审核？",
					showCancel: true,
					confirmText: '确定',
					success: function(res) {
						if (res.confirm) {
							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: "",
										needReapply: true,
										taskId:  that.list.taskId,
									}).then(res1 => {
										if (res1.data.code == 200) {
											that.$api.msg('审核成功');
											that.setTimeout(function() {
													uni.navigateBack()
											}, 1000);
										} else {
											that.$api.msg(res1.data.message);
										}
									})
								} else {
									that.$api.msg('系统异常，请联系管理员');
								}
							})
						}
					}
				})
			},
			reject() {
				var that = this
				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: '已驳回',
								needReapply: true,
							}).then(res1 => {
								if (res1.data.code == 200) {
									that.$api.msg('驳回成功');
									// that.$nextTick(function() {
									// 	uni.navigateBack()
									// })
									this.setTimeout(function() {
											uni.navigateBack()
									}, 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;
	}
</style>
