<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.priceStatus == '已驳回'"
							style="height: 40rpx;"></image><!-- 驳回 -->
						<image src="../../../static/img/tongguo.png" mode="" v-if="list.priceStatus == '已通过'"
							style="height: 40rpx;"></image><!-- 通过 -->
						<image src="../../../static/img/daishenhe.png" mode="" v-if="list.priceStatus == '审核中'"
							style="height: 40rpx;"></image><!-- 待审核 -->
					</view>
					<view class="infoText">{{list.priceStatus}}</view>
				</view>
				<view class="infoData">{{list.updateDate}}</view>
			</view>
		</view>
		<view class="transaction">
			<u-form :model="list" ref="list" class="uForm">
				<u-form-item label="运费类型" prop="contractNo" label-width="140">
					{{list.tranType}}运费
				</u-form-item>
				<u-form-item label="合同编号" prop="contractNo" label-width="140">
					<u-input v-model="list.contractNo" input-align="right" placeholder="" disabled />
				</u-form-item>
				<u-form-item label="任务编号" prop="processNo" label-width="140">
					<u-input v-model="list.processNo" input-align="right" placeholder="" disabled />
				</u-form-item>
				<u-form-item label="货名" prop="goodsName" label-width="140">
					<u-input v-model="list.goodsName" input-align="right" placeholder="" disabled />
				</u-form-item>
				<u-form-item label="发货地址" prop="sendDetailedAddress" label-width="140">
					<!-- <u-input v-model="list.sendDetailedAddress" input-align="right" placeholder="发货地址" disabled /> -->
					<view class="text_info">
						{{list.sendPrivate}}{{list.sendCity}}{{list.sendArea}}{{list.sendDetailedAddress}}
					</view>

				</u-form-item>
				<u-form-item label="收货地址" prop="receiveDetailedAddress" label-width="140">
					<!-- <u-input v-model="list.receiveDetailedAddress" input-align="right" placeholder="收货地址" disabled /> -->
					<view class="text_info">
						{{list.receivePrivate}}{{list.receiveCity}}{{list.receiveArea}}{{list.receiveDetailedAddress}}
					</view>

				</u-form-item>
				<u-form-item label="运费（元）" prop="tranPrice" label-width="250">
					<u-input v-if='list.billingMethod==1&&list.tranType=="汽运"' v-model="list.tranPriceIng"
						input-align="right" placeholder="请输入运费单价" />
					<u-input v-else-if='list.billingMethod!=1&&list.tranType=="汽运"' v-model="list.tranPriceIngCar"
						input-align="right" placeholder="请输入运费单价" />
					<u-input v-else v-model="list.tranPriceIng" input-align="right" placeholder="请输入运费单价" />
				</u-form-item>
				<u-form-item label="货值" prop="tranPrice" label-width="250">
					<u-input v-model="list.goodsValueIng" input-align="right" placeholder="请输入货值" />
				</u-form-item>
			</u-form>
		</view>
		<flow :auditList="auditList" @status='getStatus'></flow>
		<u-modal v-model="show" :title-style="{fontSize: '18px',fontWeight:'500'}"
			:content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='提示'
			:showCancelButton='true' :content="content" @confirm="passSubmit" @cancel="show = false"></u-modal>
		<u-button type="success" class="submit" @click="show = true" v-if="list.priceStatus == '审核中'||isSHowBtn">通过
		</u-button>
	</view>
</template>

<script>
	import flow from '@/components/flow.vue';
	import helper from '@/common/helper.js';
	import {
		mapState
	} from 'vuex';
	export default {
		components: {
			flow
		},
		data() {
			return {
				isSHowBtn: true,
				everyCheck: '',
				list: {
					priceStatus: "",
				},
				id: "",
				show: false,
				rejectInfo: "", //审核意见
				title: "提示",
				auditList: [],
				content: '是否通过该设置?'
			}
		},
		onBackPress(e) {
			if (this.everyCheck) {
				uni.navigateTo({
					url: "/pages/task/my_task"
				})
				return true;
			}
		},
		onLoad(options) {
			this.id = options.id
			this.everyCheck = uni.getStorageSync("everyTask")
			this.isSHowBtn = options.isShowbtn
			this.getList()
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		methods: {
			getStatus(val) {
				if (val == 200) this.getList()
			},
			getList() {
				var that = this
				this.$api.doRequest('get', '/tranProcessInfo/getTranProcess', {
					id: this.id
				}).then(res => {
					this.list = res.data.data
					// 查流程
					this.$api.doRequest('get', '/workflow/query/workflowDefinitions', {
						businessCode: 'YUNJIA-TRAN-APPROVE',
						tmpCompId: uni.getStorageSync('pcUserInfo').compId
					}).then(res1 => {
						this.$api.doRequest('get', '/commonUser/getHis', {
							workflowId: res1.data.data[0].id,
							businessKey: this.id,
							// branch:'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)
							for (let i = 0; i < response.data.data.length; i++) {
								if (response.data.data[i].status == "error") {
									this.auditCheck = "error"
									break;
								} else if (response.data.data[i].status == "question") {
									this.auditCheck = "question"
									break;
								} else {
									this.auditCheck = "success"
								}
							}
							this.auditList = response.data.data
							var time2 = new Date(this.list.createDate).getTime()
							var time3 = this.$u.timeFormat(time2, 'mm.dd hh:MM')
							this.auditList.unshift({
								operatorTitle: this.list.requester.substring(0, 2),
								operatorName: this.list.requester,
								updateDate: time3,
								auditMind: '',
								desc: '发起申请',
								showflow: false,
								commonStaffs1: null,
								commonStaffs: null,
								workflowHistoricTasks: [],
								status: 'success'
							})
						})
					})
				})
			},
			passSubmit() {
				var that = this
				if (!this.list.tranPriceIng && this.list.billingMethod == 1 && this.list.tranType == "汽运" || !this.list
					.tranPriceIngCar && this.list
					.billingMethod == 2 && this.list.tranType == "汽运" || !this.list.tranPriceIng && this.list.tranType !=
					"汽运") {
					this.$api.msg('运费单价不能为空')
					return
				}
				uni.showLoading({
					title: "审核中"
				})
				var tranProcessInfo = {}
				var url = ''
				tranProcessInfo.id = that.list.id
				tranProcessInfo.flag = "2"
				tranProcessInfo.billingMethod = that.list.billingMethod
				tranProcessInfo.goodsValueIng = that.list.goodsValueIng
				tranProcessInfo.reviewer = that.userInfo.userName
				tranProcessInfo.tranTypeKey = that.list.tranTypeKey
				if (that.list.billingMethod == 1 && that.list.tranType == "汽运" || that.list.tranType != "汽运") {
					tranProcessInfo.tranPriceIng = that.list.tranPriceIng
					url = '/tranProcessInfo/api/setUpTranPrice'
				} else {
					tranProcessInfo.tranPriceIngCar = that.list.tranPriceIngCar
					url = '/tranProcessInfo/api/setUpTranPriceCar'
				}
				that.$api.doRequest('post', url, tranProcessInfo)
					.then(res => {
						if (res.data.code == 200) {
							that.$api.doRequest('post', '/newWorkflow/api/handle', {
								taskId: that.list.taskId,
								approved: true,
								auditMind: '',
								needReapply: true,
							}).then(res => {
								that.$api.msg('通过成功')
								that.show = false
								setTimeout(function() {
									if (that.everyCheck) {
										helper.setAudit(that.list)
									} else {
										uni.navigateBack()
									}
									uni.hideLoading()
								}, 1000);
							})
						}
					})

			}
		}
	}
</script>

<style scoped lang="scss">
	.transaction {
		background-color: #FFFFFF;
		margin: 10rpx;
		padding-bottom: 10rpx;
		border-radius: 20rpx;
	}

	.uForm {
		padding: 0 40rpx;
	}

	.u-form-item {
		padding: 0;
	}

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

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

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

	.rejectInfoCss {
		border: 1px solid #ccc;
		border-radius: 10rpx;
		background-color: #F9F9FA;
		// height: 100px;
		overflow-y: auto;
		margin: 30rpx;
	}

	.rejectText {
		text-align: center;
	}

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

	.text_info {
		display: flex;
		width: 100%;
		justify-content: flex-end;
	}

	.u-form {
		margin-bottom: 20rpx;
		background: #fff;
		border-radius: 10px;
		padding: 30rpx 10px;

		.u-form-item {
			line-height: 30px;
			padding: 0px 0;
			font-size: 26rpx;
			color: #878C9C;
		}
	}

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

		.row {
			display: flex;

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

			}

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

	.warp {
		padding-bottom: 30rpx;
	}
</style>
