<template>
	<view class="content">
		<view class="container">
			<headers :titles="titles"><u-icon name="arrow-left" color="#fff" size="22"></u-icon></headers>
			<view class="b-box">
				<view class="">金额</view>
				<view style="text-align: right;"><input type="text" v-model="oilOrder.orderAmount" placeholder="请输入金额" /></view>
			</view>
			<view class="b-box">
				<view class="">备注</view>
				<view style="text-align: right;"><input type="text" v-model="oilOrder.remark" placeholder="请输入备注" /></view>
			</view>
			
			<view class="title_">选择油枪</view>
			<view class="warp-box">
				<view class="w-box" :class="{ 'acv' : spearIndex == index }" v-for="(item,index) in spearList"
					:key="index" @click="getspearIndex(index,item)">
					{{item.gunName}}
				</view>
			</view>
			
			<view class="title_">选择支付方式</view>
			<view class="warp-box">
				<view class="w-box" :class="{ 'acv' : payIndex == index }" v-for="(item,index) in payList"
					v-if="item.dictValue != 'CASH' && item.dictValue != 'APPLET_CODE'"
					style="width: 100px;"
					:key="index" @click="getpayIndex(index,item)">
					{{item.dictLabel}}
				</view>
			</view>
			
		<view class="bottom-b"></view>
			<view class="p-bottom" @click="addOrder()">
				<view class="anniu">
					确定
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from "../../utils/request";
	import headers from '../../components/header/headers.vue'

	export default {
		data() {
			return {
				titles: "设置金额",
				spearList: [
					"1号枪", "2号枪", "3号枪"
				],
				spearIndex: 0,
				payList:[],
				payIndex:0,
				oilName: "",
				tankId: "",
				oilPrice: "",
				oilGunNum: "",
				oilOrder:{},
				orderNo:"",
				qrCode:"",
			}
		},
		onLoad(e) {
			uni.removeStorageSync("qrCode")
			this.orderNo = e.orderNo
		},
		onShow() {
			// this.actList = ["1", "1", "1", "1", "1", ]
			// this.status = "nomore" 底部刷新结束
			this.getOilGun()
			this.getPayList()
		},
		onPullDownRefresh() {
			console.log("刷新");
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			// this.show = true
			setTimeout(() => {
				console.log("加载执行");
			}, 2000)
		},
		components: {
			headers
		},
		methods: {
			// 添加订单，并获取主扫链接
			addOrder(){
				if (this.orderNo) this.oilOrder.orderNo = this.orderNo
				this.oilOrder.payAmount = this.oilOrder.orderAmount
				this.oilOrder.oils = this.oilName
				this.oilOrder.tankId = this.tankId
				this.oilOrder.oilPrice = this.oilPrice
				this.oilOrder.oilGunNum = this.oilGunNum
				request({
					url: 'business/oilOrder/addOrderScanPos',
					method: 'post',
					data:this.oilOrder
				}).then((res) => {
					this.orderNo = res.data.oilOrder.orderNo
					this.qrCode = res.data.scanCode.qr_code
					uni.setStorageSync("qrCode",this.qrCode)
					uni.navigateTo({
						url:"/pagesHome/PaymentCode/PaymentCode?orderNo="+this.orderNo
					})
				})
			},
			// 获取油枪信息
			getOilGun() {
				request({
					url: 'business/petrolStationManagement/oilGun/queryOilGunList',
					method: 'get',
				}).then((res) => {
					this.spearList = res.data
					if (this.spearList.length > 0) {
						this.oilGunNum = this.spearList[0].id
						
						this.oilName = this.spearList[0].oilName
						this.tankId = this.spearList[0].tankId
						this.oilPrice = this.spearList[0].oilPrice
					}
				})
			},
			getspearIndex(num, data) {
				this.spearIndex = num
				this.oilGunNum = data.id
				this.oils = data.oilName
				this.tankId = data.tankId
				this.oilPrice = data.oilPrice
			},
			// 获取支付信息
			getPayList(){
				request({
					url: '/system/dict/data/type/payment_type',
					method: 'get',
				}).then((res) => {
					this.payList = res.data
					this.oilOrder.payType = res.data[0].dictValue
				})
			},
			getpayIndex(num, data) {
				this.payIndex = num
				this.oilOrder.payType = data.dictValue
			},
			goback() {
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background: #f8f8f8;
		// background: linear-gradient(180deg, #B2D2FC 0%, #B2D2FC 14%, rgba(255, 255, 255, 0.84) 24%, rgba(255, 255, 255, 0.84) 100%);
		height: 100vh;
	}

	.container {
		width: 100%;
		background: #f8f8f8;
		box-sizing: border-box;
		padding-top: 88px;
	}

	.img-box {
		image {
			width: 100%;
			height: 100%;
		}
	}

	.b-box {
		width: 95%;
		margin: 15px auto;
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-weight: bold;
		font-size: 16px;
		color: #333333;
		background: #fff;
		box-sizing: border-box;
		padding: 10px;
	}
	
	.bottom-b {
		width: 100%;
		height: 68px;
	}
	
	.p-bottom {
		width: 100%;
		height: 68px;
		background: #fff;
		position: fixed;
		bottom: 0px;
		left: 0px;
	}
	
	.anniu {
		height: 40px;
		background: #0864E9;
		width: 80%;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		border-radius: 50px;
		margin: 5px auto;
	}

	.title_ {
		font-weight: bold;
		font-size: 16px;
		color: black;
		width: 95%;
		margin: 10px auto;
	}

	.warp-box {
		width: 95%;
		margin: 10px auto;
		display: flex;
		align-items: center;
		flex-wrap: wrap;
	}

	.w-box {
		width: 60px;
		height: 32px;
		background: #FFFFFF;
		border-radius: 6px 6px 6px 6px;
		display: flex;
		align-items: center;
		justify-content: center;
		font-weight: 500;
		font-size: 14px;
		color: #333333;
		margin-right: 10px;
	}

	.acv {
		background: #E8F5FF !important;
		color: #0864E9 !important;
	}
</style>