<template>
	<view>
		<view class="username paddtop10">
			<view class="namecont">油品选择</view>
			<picker mode="selector" style="width: 90%;" :range="oilList" range-key="codeName" @change="changeUserCard">
				<view class="date text1" style="padding: 0 25rpx;">{{typeName}}</view>
			</picker>
			<image class="flright" style="width: 15px;height: 15px;" src="../../../static/img/downj.png"></image>
		</view>

		<!-- <view class="username">
			<view class="namecont">国标价</view>
			<input placeholder="请输入国标价" v-model="nationalPrice" type="text"
				placeholder-style="color: #bfbfbf;font-size:14px;padding-top:2px;" />
		</view> -->
		<view class="username">
			<view class="namecont">油站价</view>
			<input placeholder="请输入油站价" v-model="serviceStationPrice" type="text"
				placeholder-style="color: #bfbfbf;font-size:14px;padding-top:2px;" />
		</view>
		<view class="username">
			<view class="namecont">优惠幅度</view>
			<input placeholder="请输入优惠幅度" v-model="concessionalRate" type="text"
				placeholder-style="color: #bfbfbf;font-size:14px;padding-top:2px;" />
		</view>
		<view class="btn mart50" @click="editGasOilPrice()">提 交</view>
	</view>
</template>

<script>
	import {
		getDictionaryByCodeType,
		editGasOilPrice,
		getOilPriceDetail
	} from '../../../Utils/Api.js';
	let app = getApp();
	export default {
		data() {
			return {
				oilList: [], //数据字典
				serviceStationPrice: '', // 油站价格
				concessionalRate: '', //优惠价
				typeName: '', // 名称
				typeId: '' //区分类型

			}
		},
		onLoad() {
			this.getDictionaryByCodeType();
		},
		methods: {
			//查询数据字典油品
			getDictionaryByCodeType() {
				let datas = {
					codeType: 'GAS_OIL_TYPE'
				}
				getDictionaryByCodeType(datas).then(res => {
					if (res.return_code == '000000') {
						this.oilList = res.return_data;
						this.typeId = res.return_data[0].codeValue;
						this.typeName = res.return_data[0].codeName;
					}
				})
			},
			//选择油品
			changeUserCard(e) {
				this.typeId = this.oilList[e.target.value].codeValue;
				this.typeName = this.oilList[e.target.value].codeName;
			},
			//新增油品
			editGasOilPrice() {
				if (this.serviceStationPrice.length == "") {
					uni.showToast({
						icon: 'none',
						duration: 2000,
						title: '请输入油站价格'
					});
					return;
				}
				if (this.concessionalRate.length == "") {
					uni.showToast({
						icon: 'none',
						duration: 2000,
						title: '请输入优惠幅度'
					});
					return;
				}
				uni.showLoading({
					title: '提交中'
				})
				let datas = {
					"storeId": app.globalData.userInfo.merchantStore.id,
					"oilNo": this.typeId,
					"priceGun": this.serviceStationPrice,
					"preferentialMargin": this.concessionalRate
				}
				editGasOilPrice(datas).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000') {
						uni.showToast({
							title: '添加成功',
							icon: 'none',
							duration: 2000,
							success() {
								setTimeout(() => {
									uni.navigateBack({})
								}, 1500);
							}
						})
					} else {
						uni.showToast({
							title: res.return_msg,
							duration: 2000,
							icon: 'none'
						})
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.username {
		width: calc(100% - 90upx);
		height: 100upx;
		display: flex;
		align-items: center;
		background-color: rgba($color: #ffffff, $alpha: 0.1);
		border-bottom: 1px solid #f6f6f6;
		padding: 8upx 45upx;

		input {
			width: 50%;
			height: 50upx;
			font-size: 16px;
			color: #333333;
			font-weight: blod;
		}

		.get-code {
			position: absolute;
			display: flex;
			align-items: center;
			justify-content: center;
			right: 7px;
			z-index: 3;
			border: 1px solid #bfbfbf;
			width: 25%;
			padding: 3px 5px;
			border-radius: 22px;

			&:after {
				content: " ";
				width: 1upx;
				height: 50upx;
				position: absolute;
				z-index: 3;
				margin-right: 100%;
				left: 0;
				top: 20upx;
			}
		}

		.namecont {
			color: #666666;
			width: 28%;
		}
	}

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