<template>
	<view style="position: relative;" class="modify_popup">
		<uni-icons @click="$emit('closeFn')" style="position: absolute;right: 5rpx;top: 5rpx;" color="#bbbbbb"  type="clear" size="30"></uni-icons>
		<view style="position: relative;">
				<!-- <text class="hui fonsize">{{newSeleData.id}}</text> -->
			<view class="modify_popup_header">
				<view style="width: 52rpx; height: 55rpx;">
					<uni-icons color="#2866ff" custom-prefix="iconfont" type="iconjiayou" size="30"></uni-icons>
				</view>
				<view class="flexGrow">
					<view>{{newSeleData.siteName}}</view>
					<view class="samallfonsize hui">{{newSeleData.siteId}}</view>
				</view>
			</view>
			<view class="border" style="display: flex;flex-direction: column;gap:16rpx;margin-top: 20rpx;">
				<view class="flex acenter">
					<text class="lable_minwidth hui">油号</text>
					<text style="color: #EC4645;font-size: 32rpx;"
						class="flexGrow">{{newSeleData.oilProductCode}}</text>
				</view>
				<view class="flex acenter ">
					<text class="lable_minwidth hui">发改委价格</text>
					<view class="flexGrow flex acenter">
						<view
							style="width: 168rpx;background-color: #F1F1F1;height: 60rpx;display: flex;align-items: center;">
							<input @input="inputFn('marketPrice')" :style="{color:disabled?'#bbbbbb':''}" :disabled="disabled"
								v-model="newSeleData.marketPrice" style="text-align: center;" type="digit" value=""
								placeholder="6.88" />
						</view>
						<uni-icons :color=" Number(newSeleData.marketPrice) >= Number(newSeleData.oldMarketPrice)? '#ff5555':'#2CE308' " custom-prefix="iconfont" :type="Number(newSeleData.marketPrice)>=Number(newSeleData.oldMarketPrice)?'icona-shangzhang1':'icona-xiadie2' " size="15"></uni-icons>
						<text
							style="margin-left: 10rpx; text-decoration: line-through">{{newSeleData.oldMarketPrice}}</text>
					</view>
				</view>
				<view class="flex acenter">
					<text class="lable_minwidth hui">油站价格</text>
					<view class="flexGrow flex acenter">
						<view
							style="width: 168rpx;background-color: #F1F1F1;height: 60rpx;display: flex;align-items: center;">
							<input @input="inputFn('sitePrice')" :style="{color:disabled?'#bbbbbb':''}" :disabled="disabled"
								v-model="newSeleData.sitePrice" style="text-align: center;" type="digit" value=""
								placeholder="6.88" />
						</view>
						<uni-icons :color=" Number(newSeleData.sitePrice) >= Number(newSeleData.oldSitePrice)? '#ff5555':'#2CE308' " custom-prefix="iconfont" :type="Number(newSeleData.sitePrice)>=Number(newSeleData.oldSitePrice)?'icona-shangzhang1':'icona-xiadie2' " size="15"></uni-icons>
						<text
							style="margin-left: 10rpx; text-decoration: line-through">{{newSeleData.oldSitePrice}}</text>
					</view>
				</view>
			</view>
			<view class="flex acenter  border ">
				<text class="lable_minwidth hui">调价类型</text>
				<view class="flexGrow flex acenter">
					<!-- <text
					    :style="{color:disabled?'#bbbbbb':''}"
						@click="disabled? '': newSeleData.effectiveMode == 0? newSeleData.effectiveMode=1:newSeleData.effectiveMode=0"
						style="width: 168rpx;height: 60rpx;display: flex;align-items: center">{{Number(newSeleData.effectiveMode)==0?'立即':'预约'}}</text> -->
						<text :style="{color:disabled?'#bbbbbb':''}" style="width: 168rpx;height: 60rpx;display: flex;align-items: center">{{Number(newSeleData.effectiveMode)==0?'立即':'预约'}}</text>
				</view>
			</view>
			<view  v-if="newSeleData.effectiveMode==1" class="flex acenter  border ">
				<text class="lable_minwidth hui">请选择时间</text>
				<view class="flexGrow flex acenter">
					<text
						style="margin-left: 10rpx;">{{newSeleData.subEntryTime?newSeleData.subEntryTime:'请选择时间'}}</text>
				</view>
			</view>
			<view style="border-bottom: 0px;" class="flex acenter border">
				<text class="lable_minwidth hui">审核状态</text>
				<view :style="{color:'#EBC153'}" class="flexGrow flex acenter">{{newSeleData.applyStatus|applyStatus}}
				</view>
			</view>
		</view>
		<view v-if="seleData.applyStatus==0" style="margin-top: 27rpx;" class="flex jb">
			<view @click="lefnFn" :style="{background: butten.leftButten.bg,color:butten.leftButten.color}"
				class="footer_zbutten">{{butten.leftButten.text}}</view>
			<view @click="rightFn" :style="{background: butten.rightButten.bg,color:butten.rightButten.color}"
				class="footer_butten">{{butten.rightButten.text}}</view>
		</view>
		<u-picker @confirm='dateConfirm' v-model="show" :params="params" mode="time"></u-picker>
	</view>
</template>

<script>
	import tool from '@/utils/tool.js'
	export default {
		props: {
			seleData: {
				type: Object,
				default: () => {
					return null
				}
			}
		},
		data() {
			return {
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: false
				},
				newSeleData: null,
				show: false,
				disabled: true,
				butten: {
					leftButten: {
						bg: '',
						color: '',
						text: '撤回'
					},
					rightButten: {
						bg: '',
						color: '',
						text: '修改价格'
					}
				}
			}
		},
		created() {
			this.initFn()
		},
		filters: {
			applyStatus(e) {
				/*
			        -3:执行失败
			        -2:已撤回
			        -1:审核失败
			        0:待审核
			        1:审核通过
			        2:等待执行
			        3:执行成功
				 */
				switch (Number(e)) {
					case 1:
						return '审核通过'
					case 2:
						return '等待执行'
					case 3:
						return '执行成功'
					case 0:
						return '等待审核'
					case -1:
						return '审核失败'
					case -2:
						return '已撤回'
					case -3:
						return '执行失败'
					case -4:
						return '已撤销'
				}
			}
		},
		methods: {
			inputFn(e) {
				console.log(this.newSeleData[e])
				if (this.newSeleData[e].indexOf('.') != -1) {
					if (this.newSeleData[e].split('.')[1].length > 2) {
						uni.showToast({
							title: '最多保留小数点后两位',
							icon: 'none'
						})
						this.$nextTick(function() {
							this.newSeleData[e] = Number(this.newSeleData[e]).toFixed(2)
						})
					}
				}
			},
			lefnFn() {
				if (this.butten.leftButten.text == '恢复') {
					this.disabled = true
					this.butten.rightButten.text = '修改价格'
					this.butten.leftButten.text = '撤回'
					this.newSeleData = JSON.parse(JSON.stringify(this.seleData))
				} else {
					uni.showToast({
						title: '撤回了',
						icon: 'success'
					})
					this.$emit('reject',{id:this.newSeleData.id})
				}
			},
			rightFn() {
				if (this.butten.rightButten.text == '修改价格') {
					this.disabled = false
					this.butten.rightButten.text = '重新提交'
					this.butten.leftButten.text = '恢复'
				} else {
					this.newSeleData.updateSource = 'OMS-MINIAPP'
					this.$emit('postFn',this.newSeleData)
					uni.showToast({
						title: '提交了',
						icon: 'success'
					})
				}
			},
			initFn() {
				this.newSeleData = JSON.parse(JSON.stringify(this.seleData))
			},
			dateConfirm(e) {
				this.newSeleData.subEntryTime = `${e.year}-${e.day}-${e.month} ${e.hour}:${e.minute}`
				console.log(e)
			},
		}
	}
</script>

<style scoped>
	.footer_zbutten {
		width: 227rpx;
		background-color: #EC4645;
		border-radius: 15rpx;
		padding: 22rpx 0;
		text-align: center;
		color: white;
	}

	.footer_butten {
		width: 227rpx;
		background-color: #2866FF;
		border-radius: 15rpx;
		padding: 22rpx 0;
		text-align: center;
		color: white;
	}

	.jb {
		justify-content: space-between;
	}

	.border {
		border-bottom: 1rpx solid #F0F0F0;
		padding: 10rpx 0;
	}

	.lable_minwidth {
		width: 30%;
	}

	.flex {
		display: flex;
	}

	.acenter {
		align-items: center;
	}

	.hui {
		color: #999999;
	}

	.fonsize {
		font-size: 27rpx;
	}

	.flexGrow {
		flex-grow: 1;
	}

	.samallfonsize {
		font-size: 24rpx;
	}

	.modify_popup_header {
		display: flex;
		border-bottom: 1rpx solid #F0F0F0;
		padding-bottom: 20rpx;
		margin-top: 39rpx;
		align-items: center;
		gap: 25rpx
	}

	.modify_popup {
		padding: 26rpx 46rpx;
		font-size: 28rpx;
	}
</style>