<template>
	<view>
		<view class="width90 mart15 font15 fcor666">选择油品</view>
		<view v-if="oilpriceList == ''" class="mart40 fotct font14 fcor666">
			<image mode="widthFix" style="width: 70vw;" src="../../../static/img/noorder.png"></image>
		</view>
		<view class="activeRefuel" v-for="(item,index) in oilpriceList" :key="index" @click="jumpupdatePrice(item)">
			{{item.oilNoName}}
			<image src="../../../static/img/6.png" mode="widthFix" class="imgcha iconw"
				@click.stop="delOilPrice(item.oilNo)" v-if="positionType == 1"></image>
		</view>
		<view class="btn mart50" @click="jumpaddoil()" v-if="positionType == 1">新 增 油 品</view>
	</view>
</template>

<script>
	import {
		getOilPriceListByStore,
		delOilPrice
	} from '../../../Utils/Api.js'
	let app = getApp();
	export default {
		data() {
			return {
				oilpriceList: [],
				typeid: '', //跳转类型
				userinfo: '', //用户信息
				positionType: app.globalData.positionType // 角色权限
			}
		},
		onLoad(Option) {
			this.typeid = Option.id;
		},
		onShow() {
			this.userinfo = app.globalData.userInfo;
			if (app.globalData.userInfo) {
				this.getOilPriceListByStore();
			} else {
				uni.showToast({
					title: '登录信息过期,请重新授权',
					icon: 'none',
					duration: 2000,
					success() {
						setTimeout(() => {
							uni.navigateTo({
								url: '../../login/login/login'
							})
						}, 1500);
					}
				})
			}
		},
		methods: {
			//查询油品
			getOilPriceListByStore() {
				uni.showLoading({
					title: '加载中'
				})
				let datas = {
					storeId: this.userinfo.merchantStore.id
				}
				getOilPriceListByStore(datas).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000') {
						this.oilpriceList = res.return_data;
					} else {
						this.oilpriceList = [];
					}
				});
			},
			//跳转添加油品
			jumpaddoil() {
				uni.navigateTo({
					url: '../addOils/addOils'
				})
			},
			//跳转
			jumpupdatePrice(item) {
				if (this.typeid == 1) {
					uni.navigateTo({
						url: '../updateOilgun/updateOilgun?oilno=' + item.id
					})
				}
				if (this.typeid == 2) {
					uni.navigateTo({
						url: '../updateOilprice/updateOilprice?oilno=' + item.oilNo
					})
				}
			},
			//删除油品
			delOilPrice(item) {
				let that = this;
				uni.showModal({
					title: '删除油品',
					content: '是否删除当前油品',
					success: function(res) {
						if (res.confirm) {
							uni.showLoading({
								title: '操作中'
							})
							let datas = {
								"storeId": that.userinfo.merchantStore.id,
								"oilNo": item
							}
							delOilPrice(datas).then(res => {
								uni.hideLoading();
								if (res.return_code == '000000') {
									uni.showToast({
										title: '删除成功',
										icon: 'none',
										duration: 1000,
										success() {
											setTimeout(() => {
												that.getOilPriceListByStore();
											}, 1000);
										}
									})
								}
							});
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.refuel {
		padding: 6px 10px;
		border-radius: 5px;
		background-color: #f6f6f6;
		color: #666666;
		margin-right: 10px;
		margin-left: 15px;
		margin-top: 20px;
		display: inline-block;
		font-size: 16px;
		width: 20%;
		text-align: center;
	}

	.activeRefuel {
		padding: 6px 10px;
		border-radius: 5px;
		border: 1px solid #089bf5;
		color: #089bf5;
		margin-right: 10px;
		margin-left: 15px;
		margin-top: 20px;
		display: inline-block;
		font-size: 16px;
		width: 20%;
		text-align: center;
	}

	.btn {
		bottom: 0px;
		position: absolute;
		color: #FFFFFF;
		background-color: #0083f5;
		width: 90%;
		margin-left: 5%;
		margin-top: 80rpx;
		margin-bottom: 50rpx;
		height: 90rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 45rpx;
		font-size: 40rpx;
	}

	.imgcha {
		position: absolute;
		margin-top: -15px;
		margin-left: 25px;
	}
</style>
