<template>
	<view class="priceAdjustment_body">
		<topBar height="343rpx" title="调价申请">
			<view slot="coment">
				<view class="header_seach">
					<view class="header_seach_seach">
						<view class="seach_input">
							<uni-easyinput :letfText='letfText' confirmType='search'
								@confirm='getData.currentPage=1;getList()'
								placeholder-style="color:#bbbbbb;font-weight: 100;" v-model="getData.params.siteName"
								placeholder="油站名称、油站ID" @iconClick="onClick">
							</uni-easyinput>
						</view>
						<button @tap='jump(2)' class="header_seach_butten">
							<uni-icons type="plusempty" size="20" color="#bbbbbb"></uni-icons>
							<view>新增</view>
						</button>
					</view>
					<view class="Navigation">
						<view @tap="seleFn(item);seleindex = index"
							:class="seleindex==index?'navigation_seleitem':'navigation_item'"
							v-for="(item,index) in navigation" :key="index">
							{{item.text}}
							<uni-icons :animation="animationData" class="icoon" v-if="index==0" type="refreshempty"
								style="margin-left: 10rpx;" size="15" color="#bbbbbb"></uni-icons>
						</view>
					</view>
				</view>
			</view>
		</topBar>
		<view class="listContainer" style='flex: 1;overflow: hidden;'>
			<scroll-view :refresher-triggered='isShow.refresherTriggered' @refresherrefresh='refresherrefresh' :refresher-enabled='true' @scrolltolower='scrolltolower' style="height: 100%;" scroll-y="true">
				<view v-for="(item,index) in list" @click="select(item)" class="list_item_car">
					<view style="">
						<view class=" list_item_car_title flex jb">
							<view class="flex">
								<view class="flex jcenter acenter" style="min-width: 93rpx;">
									<uni-icons color="#2866ff" custom-prefix="iconfont" type="iconjiayou" size="30">
									</uni-icons>
								</view>
								<view>
									<view style=" color: #333333;font-size: 28rpx;">{{item.siteName}}</view>
									<view style=" font-size: 22rpx;color: #999999;">{{item.siteId}}</view>
								</view>
							</view>
							<view :style="{background:Number(item.effectiveMode)==0?'':'#55aaff'}"
								class="itemtable flex jcenter acenter">{{Number(item.effectiveMode)==0?'立即':'预约'}}
							</view>
						</view>
						<view class=" list_item_car_title flex ">
							<view class="flex">
								<view class="flex jcenter acenter olitext " style="">{{item.oilProductCode}}</view>
								<view class="pricr_text">
									<view class="flex">
										发改委
										<view style="margin: 0 10rpx; min-width: 82rpx;" class="blackcolor">
											{{Number(item.marketPrice).toFixed(2)}}
										</view>
										<uni-icons
											:color=" Number(item.marketPrice) >= Number(item.oldMarketPrice)? '#ff5555':'#2CE308' "
											custom-prefix="iconfont"
											:type="Number(item.marketPrice)>=Number(item.oldMarketPrice)?'icona-shangzhang1':'icona-xiadie2' "
											size="15"></uni-icons>
										<text class="decor">{{ Number(item.oldMarketPrice).toFixed(2) }}</text>
									</view>
									<view class="flex">
										油站价
										<view style="margin: 0 10rpx;min-width: 82rpx;" class="blackcolor">
											{{ Number(item.sitePrice).toFixed(2) }}
										</view>
										<uni-icons
											:color="Number(item.sitePrice)>Number(item.oldSitePrice)?'#ff5555':'#2CE308' "
											custom-prefix="iconfont"
											:type="Number(item.sitePrice)>Number(item.oldSitePrice)?'icona-shangzhang1':'icona-xiadie2' "
											size="15"></uni-icons>
										<text class="decor">{{Number(item.oldSitePrice).toFixed(2)}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="list_item_car_footer flex acenter jb" style=" padding: 10rpx;">
						<view>创建时间:{{item.createTime}}</view>
						<view :style="{color:colorFn(item)}">{{item.applyStatus|applyStatus}}</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<popup :show="modifyShow" :butten='butten' v-model="isShow.modify">
			<view slot="coment">
				<modify @closeFn='isShow.modify=false' @reject='reject' @postFn='postFn' v-if="isShow.modify"
					:seleData='seleData' />
			</view>
		</popup>
	</view>
</template>

<script>
	import scroll from '@/components/scroll'
	import modify from '../../modify/modify.vue'
	import priceAdjustment from '@/api/priceAdjustment'
	import tool from '@/utils/tool.js'
	export default {
		components: {
			scroll,
			modify
		},
		data() {
			return {
				seleData: null,
				list: [],
				animationData: null,
				seleindex: '0',
				isShow: {
					modify: false,
					refresherTriggered:false
				},
				modifyShow: {
					img: false,
					footer: false
				},
				butten: {
					colse: '撤回',
					confirm: '修改价格',
					coloseBg: '#EC4645',
					coloseColor: '#FFFFFF',
					confirmBg: '',
					confirmColor: ''
				},
				getData: {
					pageSize: 15,
					currentPage: 1,
					params: {
						applyStatus: '', //申请状态审核状态
						siteName: '', //油站名称
						effectiveMode: '', //生效方式调价类型

					}
				},
				navigation: [{
						text: '全部',
						index: ''
					},
					{
						text: '待审核',
						index: '0'
					},
					{
						text: '待执行',
						index: '1'
					}
				],
			}
		},
		onShow() {
			this.getList()
		},
		onLoad() {

		},
		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: {
			refresherrefresh(e){
				this.isShow.refresherTriggered = true
				this.getList()
			},
			reject(e) {
				priceAdjustment.withdrawalOfPriceAdjustment(e).then(res => {
					if (res.code !== 20000) return
					uni.showToast({
						title: '撤回成功',
						icon: 'success'
					})
					setTimeout(() => {
						this.isShow.modify = false
						this.getList()
					}, 500)
				})
			},
			postFn(e) {
				priceAdjustment.update(e).then(res => {
					if (res.code !== 20000) return
					uni.showToast({
						title: '提交成功',
						icon: 'success'
					})
					setTimeout(() => {
						this.isShow.modify = false
						this.getList()
					}, 500)
				})
			},
			colorFn(item) {
				switch (Number(item.applyStatus)) {
					case 1:
						return '#17A00E'
					case 2:
						return '#17A00E'
					case 0:
						return '#EBC153'
					case -1:
						return '#EC4645'
					case -2:
						return '#EC4645'
				}
			},
			select(item) {
				// if (item.applyStatus !== 0) return
				this.isShow.modify = true
				tool.numberSetting(item, ['marketPrice', 'oldMarketPrice', 'oldSitePrice', 'sitePrice'], 2)
				this.seleData = item
			},
			//转圈圈逻辑 ！！！！ 操
			seleFn(e) {
				if (e.index == '') {
					if (this.getData.params.applyStatus !== '') {
						this.navigation[0].text = '全部'
						this.getData.params.effectiveMode = ''
						this.getData.params.applyStatus = ''
					} else {
						switch (e.text) {
							case '全部':
								this.navigation[0].text = '立即'
								this.getData.params.effectiveMode = 0
								break
							case '立即':
								this.navigation[0].text = '预约'
								this.getData.params.effectiveMode = 1
								break
							case '预约':
								this.navigation[0].text = '全部'
								this.getData.params.effectiveMode = ''
								break
						}
					}

					this.getData.params.applyStatus = ''
				} else {
					this.navigation[0].text = '全部'
					this.getData.params.effectiveMode = ''
					this.getData.params.applyStatus = e.index
				}
				this.getData.currentPage = 1
				this.rotateFn()
				this.getList()
			},
			getList() {
				let page = JSON.parse(JSON.stringify(this.getData))
				priceAdjustment.findByPage(page).then(res => {
					this.isShow.refresherTriggered = false
					if (res.code !== 20000) return
					if (res.data.list.length == 0) {
						uni.showToast({
							title: '没有数据了哦',
							icon: 'none'
						})
					}
					if (page.currentPage !== 1) {
						this.list = this.list.concat(res.data.list)
						return
					}
					this.list = res.data.list
					console.log(res)
				})
			},
			animationFns() {
				console.log('恢复动画')
				var animation = uni.createAnimation({
					duration: 0,
					timingFunction: 'ease',
				})
				animation.rotate(0).step()
				this.animationData = animation.export()
			},
			rotateFn() {
				var animation = uni.createAnimation({
					duration: 1000,
					timingFunction: 'ease',
				})
				animation.rotate(360).step()
				this.animationData = animation.export()
				setTimeout(() => {
					this.animationFns()
				}, 1000)
			},
			scrolltolower() {
				this.getData.currentPage += 1
				this.getList()
			},
			seachFn() {},
			onClick() {},
			jump() {
				uni.navigateTo({
					url: '../addPrice/addPrice'
				})
			},
		}
	}
</script>

<style>
	@import url("./index.css");
</style>
