<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.approveStatus?list.approveStatus: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' v-if="list.bulkDensityStandard !=1">
				<view class="left">基准水分（%）</view>
				<view class="right">{{list.waterBase}}</view>
			</view>
			<view class='row' v-if="list.bulkDensityStandard !=1">
				<view class="left">干粮水分（%）</view>
				<view class="right">{{list.waterMin}}</view>
			</view>
			<view class='row' v-if="list.bulkDensityStandard !=1">
				<view class="left">水分上限（%）</view>
				<view class="right">{{list.waterMax}}</view>
			</view>
			<view v-if="list.paramType == '2' && list.bulkDensityStandard !=1" class='row'>
				<view class="left">扣重比</view>
				<view class="right">{{list.deductWeight}}</view>
			</view> -->
			<view class="form_view" style="background: #F9F9FA;" v-if="list.bulkDensityStandard ==1">
				<table border="1" width="100%" style="border-collapse: collapse;" cellspacing="0" cellpadding="0"
					class="table_css">
					<tr>
						<td>{{list.goodsName!='大豆' ? '容重(g/L)' : '蛋白(g/L)'}}</td>
						<td>价格(元/公斤)</td>
					</tr>
					<tr v-for="(item,index) in list.detailPrints">
						<td>{{item.bulkDensityMax }} ~ {{ item.bulkDensityMin}}</td>
						<td>{{item.bulkDensityPrice}}</td>
					</tr>
				</table>
			</view>
			<!-- <view class='row' v-if="list.bulkDensityStandard !=1">
				<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="form_view" v-if="list.bulkDensityStandard !=1">
			<table border="1" width="100%" style="border-collapse: collapse;" cellspacing="0" cellpadding="0"
				class="table_css">
				<tr>
					<td>水分</td>
					<td>一等</td>
					<td>二等</td>
					<td>三等</td>
					<td>等外</td>
				</tr>
				<tr v-for="(item,index) in list.detailPrints">
					<td>{{item.waterMin}}</td>
					<td>{{item.price1}}</td>
					<td>{{item.price2}}</td>
					<td>{{item.price3}}</td>
					<td>{{item.priceOther}}</td>
				</tr>
			</table>

		</view>
		<!-- <view class="content2" v-if="list.bulkDensityStandard !=1">
			<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> -->
		<flow ref='flow1' :auditList="auditList" @status='getStatus'></flow>
		<u-toast ref="uToast" />
		<view style='padding:10px;' class='flex bottom-btn'>
			<u-button @click='fanHui' type="success" class="btn2">返回</u-button>
		</view>
	</view>
</template>

<script>
	import flow from '@/components/flow.vue';
	import {
		mapState
	} from 'vuex';
	export default {
		components: {
			flow
		},
		name: "task",
		data() {
			return {
				show: false,
				id: 0,
				list: {},
				form: {
					name: '',
					intro: '',
					sex: ''
				},
				radio: '',
				pcUserInfo: uni.getStorageSync('pcUserInfo'),
				switchVal: false,
				contractNoList: [],
				auditList: [],
			};
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		onLoad(options) {
			this.id = options.id
		},
		onShow() {
			var that = this
			this.$nextTick(function() {
				that.getData()
			})
		},
		methods: {
			getStatus(val) {
				if (val == 200) this.getData()
			},
			showcontent(item) {
				item.showflow = !item.showflow
			},
			getData() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				var data = []
				var that = this
				this.$api.doRequest('get', '/purchasePrice/purchasePriceLook', {
					id: this.id
				}).then(res => {
					if (res.data.code == 200) {
						this.list = res.data.data
						this.$api.doRequest('get', '/workflow/query/workflowDefinitions', {
							businessCode: 'PROCUREMENT-PRICE-APPROVE',
							tmpCompId: uni.getStorageSync('pcUserInfo').compId
						}).then(res1 => {
							this.$api.doRequest('get', '/commonUser/getHis', {
								workflowId: res1.data.data[0].id,
								businessKey: this.id,
								// branch:that.list.jointVentureParties?that.list.jointVentureParties:'zt'
							}).then(response => {
								uni.hideLoading()
								for (let i = 0; i < response.data.data.length; i++) {
									this.$set(response.data.data[i], 'status', 'question')
									// console.log(response.data.data[i].workflowHistoricTasks,i)
									if (response.data.data[i].commonStaffs) {
										response.data.data[i].showflow = false
										response.data.data[i].operatorTitle = response.data.data[i]
											.desc.substring(0, 2)
										response.data.data[i].operatorName = response.data.data[i]
											.desc
										response.data.data[i].staffscontent = '共' + response.data
											.data[i].commonStaffs.length + '人，当前审核' + response.data
											.data[i].workflowHistoricTasks.length + '人'
										if (response.data.data[i].workflowHistoricTasks && response
											.data.data[i].workflowHistoricTasks.length > 0) {
											if (response.data.data[i].workflowHistoricTasks
												.length != response.data.data[i].commonStaffs
												.length) {
												// response.data.data[i].status='question'
												this.$set(response.data.data[i], 'status',
													'question')
											} else {
												this.$set(response.data.data[i], 'status',
													'success')
												// response.data.data[i].status='success'
											}
											response.data.data[i].workflowlen = response.data.data[
												i].workflowHistoricTasks.length
											var workflowdata = response.data.data[i]
												.workflowHistoricTasks
											var staffsdata = response.data.data[i].commonStaffs
											for (let q = 0; q < staffsdata.length; q++) {
												staffsdata[q].status = false
												staffsdata[q].staffTitle = staffsdata[q].staffName
												for (let k = 0; k < workflowdata.length; k++) {
													if (staffsdata[q].staffId == workflowdata[k]
														.operatorId) {
														staffsdata[q].status = true
													}
												}
											}
										}
										response.data.data[i].commonStaffs1 = response.data.data[i]
											.commonStaffs
									} else {
										if (response.data.data[i].workflowHistoricTasks && response
											.data.data[i].workflowHistoricTasks.length > 0) {
											var len = response.data.data[i].workflowHistoricTasks
												.length - 1
											if (response.data.data[i].workflowHistoricTasks[len]
												.approved) {
												this.$set(response.data.data[i], 'status',
													'success')
											} else {
												this.$set(response.data.data[i], 'status', 'error')
											}
											response.data.data[i].operatorTitle = response.data
												.data[i].workflowHistoricTasks[len].operatorName
												.substring(response.data.data[i]
													.workflowHistoricTasks[0].operatorName.length -
													2)
											response.data.data[i].operatorName = response.data
												.data[i].workflowHistoricTasks[len].operatorName
											var time = new Date(response.data.data[i]
													.workflowHistoricTasks[len].claimTime)
												.getTime()
											response.data.data[i].updateDate = this.$u.timeFormat(
												time, 'mm.dd hh:MM')
											response.data.data[i].auditMind = response.data.data[i]
												.workflowHistoricTasks[len].auditMind
										} else {
											this.$set(response.data.data[i], 'status', 'question')
											// response.data.data[i].status='question'
											if (response.data.data[i].desc == '总经理助理审核') {
												response.data.data[i].operatorTitle = '总助'
											} else if (response.data.data[i].desc == '杜大光审核') {
												response.data.data[i].operatorTitle = '大光'
											} else {
												response.data.data[i].operatorTitle = response.data
													.data[i].desc.substring(0, 2)
											}

											response.data.data[i].operatorName = response.data
												.data[i].desc
											var time1 = new Date(response.data.data[i].updateDate)
												.getTime()
											response.data.data[i].updateDate = this.$u.timeFormat(
												time1, 'mm.dd hh:MM')
											response.data.data[i].auditMind = ''
										}
									}

								}
								// console.log(response.data.data)
								this.auditList = response.data.data
								var time2 = new Date(this.list.updateDate).getTime()
								var time3 = this.$u.timeFormat(time2, 'mm.dd hh:MM')
								this.auditList.unshift({
									operatorTitle: this.list.creater.substring(0, 2),
									operatorName: this.list.creater,
									updateDate: time3,
									auditMind: '',
									desc: '发起申请',
									showflow: false,
									commonStaffs1: null,
									commonStaffs: null,
									workflowHistoricTasks: [],
									status: 'success'
								})
							})
						})
					}
				})
			},
			confirm(item) {
				this.list.contractNo = item[0].value
			},
			fanHui() {
				uni.navigateBack()
			}
		}
	}
</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;
			}
		}
	}

	.content3 {
		background: white;
		margin: 20rpx 0;
		border-radius: 20rpx;
		padding: 20rpx;

		.row {
			display: flex;

			.left {
				display: flex;
				align-items: center;

				.item1 {
					position: relative;

					.item-content {
						background: #617AE0;
						width: 44px;
						height: 44px;
						border-radius: 22px;
						line-height: 44px;
						text-align: center;
						font-size: 15px;
						color: #fff;
					}

					.status {
						position: absolute;
						border-radius: 50%;
						padding: 0px 2px;
						right: -3px;
						bottom: -3px;
						background: #fff;
					}

					.status.success {
						border: 1px solid rgb(60, 156, 255);
					}

					.status.error {
						border: 1px solid rgb(245, 108, 108);
					}

					.status.question {
						border: 1px solid #f9ae3d;
					}
				}

			}

			.right {
				width: 80%;
				// color: #B0B1B5;
				margin-top: 10px;

				.right-content {
					background: #F2F3F7;
					margin-left: 10px;
					margin-top: 10px;
					padding: 10px;
					border-radius: 5px;
					color: #B0B1B5;
				}

				.right-item {
					display: flex;
					justify-content: space-between;

					.time {
						color: #999;
					}

					.item2 {
						margin-left: 20rpx;
						margin-top: -7px;

						.name {
							font-size: 28rpx;
							font-weight: 800;
							margin-bottom: 4px;
						}

						.status.success {
							color: #6CC48C;
						}

						.status.error {
							color: rgb(245, 108, 108);
						}

						.status.question {
							color: #f9ae3d;
						}
					}
				}
			}
		}

		.row2 {
			display: flex;

			.item-content {
				background: #22C572;
				width: 30px;
				height: 30px;
				border-radius: 50%;
				line-height: 30px;
				text-align: center;
				font-size: 12px;
				color: #fff;
				padding: 0 2px;
				margin: 0 auto;
			}

			.status {
				position: absolute;
				top: 0;
				right: 0;
			}
		}

		.row-line {
			width: 1px;
			height: 30px;
			background: #F2F2F2;
			margin: 10rpx 50rpx;

		}

		.audit {
			margin-top: 20rpx;
		}
	}

	.form_view {
		margin: 20rpx 0;
		border-radius: 20rpx;
		background: #F9F9FA;
		padding: 30rpx 20rpx;

		.table_css td {
			text-align: center;
			border: 1rpx solid #DBD9CE;
			padding: 14rpx 0;
		}

		.table_css {
			border: 1rpx solid #DBD9CE;
		}
	}
</style>
