vue完成大乐透界面和算法

5 篇文章 0 订阅
4 篇文章 0 订阅

参考大乐透玩法分为手选和机选两种,手选可以选择多倍多期多注方式。

引用了uview框架进行开发需要提前引入使用,自行去uview官网下载资源包,引入代码如下

import Vue from 'vue'
import App from './App'
import uView from "uview-ui";
Vue.use(uView);

大乐透注数算法:

//大乐透注数算法
		factorial(num){
		    if(num <= 1) {
		         return 1;      
		    }else{
		          return num * this.factorial(num-1);   
		    }
		},
		
		combination(n,m){
			var divisor = this.factorial(n-m) * this.factorial(m);
			return this.factorial(n)/divisor;
		},
		count_zhu_superlottery(r,b){
			return this.combination(r,5) * this.combination(b,2);
		},

完整代码如下

<template>
	<div class="container">
		
		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">模式选择</view>
				<u-subsection :current="current" :list="['手选', '机选']" @change="modeChange"></u-subsection>
			</view>
		</view>
		<view class="lotto_all">
			<!-- 手选 -->
			<view class="lotto_manual" v-if="current==0">
				<view class="u-item-title">选择前区</view>
				<div>
					<ul class="lotto_front" >
						<li :id= "item" @click="lotto_front(item)" v-for="(item, index) in arrfront" :key="index">{{ item }}</li>
					</ul>
				</div>
				
				<view class="u-item-title">选择后区</view>
				<div>
					<ul class="back_front"  >
						<li :id= "item1" @click="lotto_back(item1)" v-for="(item1, index1) in arrback" :key="index1">{{ index1+1 }}</li>
					</ul>
				</div>
				<div id="s_lotto" class=select_area>
					您选了{{num}}注,共{{2*num}}.00元
				</div>
				<u-button type="success" @click="confirm_lotto" >确认选号</u-button>
				<u-popup v-model="show" mode="center" border-radius="14">
							<view>{{description}}</view>
							<view class="confrim-btn">
							<u-button @click="show = false;">知道了</u-button>
							</view>
				</u-popup>
				<view class="u-item-title">已选号码</view>
				<u-table>
						<u-tr>
							<u-th>类型</u-th>
							<u-th>红球</u-th>
							<u-th>篮球</u-th>
							<u-th>注数</u-th>
						</u-tr>
						<u-tr v-for="(item2,index2) in confirm_lottos" :key="index2">
							<u-td>{{item2.ltype}}</u-td>
							<u-td>{{item2.larrfront}}</u-td>
							<u-td>{{item2.larrback}}</u-td>
							<u-td>{{item2.nums}}</u-td>
						</u-tr>

					</u-table>
				
				
			</view>
			<!-- 机选 -->
			<view class="lotto_machine" v-if="current==1">
				<ul class="ssq_wrap" >
					
				</ul>
			</view>
		</view>
		<view>您选了{{nums}}注</view>
		<view class="beitou_area">
			倍投:<u-number-box v-model="multiple" :min="1" :max="150" @change="Multiple"></u-number-box>
		</view>
		<view >
			期数:<u-number-box v-model="periods" :min="1" :max="15" @change="valChange"></u-number-box>
		</view>
		<view  class="append">
			<u-checkbox-group >
						<u-checkbox name="append"  v-model="checked" @change="checkboxChange" >
							追加投注 <span>单注+1元,奖金最高可到1600万元</span>
						</u-checkbox >
					</u-checkbox-group>
		</view>
		<view>共 {{money}} 元 + 代买服务费:{{service_money}} 元 = {{moneys}} 元</view>
		<u-button type="success">提交订单</u-button>
	</div>
	
</template>

<script>
const NET = require('../../utils/request');
const API = require('../../config/api');
export default {
	components: {},
	data() {
		return {
			title: '',
			description: '',
			show:false,
			arr: [],
			control: true,
			current:0,//模式选择
			flag:true,//是否选中
			num:0,//注数
			nums:0,//总注数
			multiple:1,//倍数
			periods:1,//期数
			append:'',//追加
			checked:false,
			arrfront:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35],
			arrback:[101,102,103,104,105,106,107,108,109,110,111,112],
			arrfront_confirm:[],//选择的红球
			arrback_confirm:[],//选择的篮球
			confirm_lottos :[],//选中的号
			money:'',//下注钱
			service_money:'',//服务费
			moneys:'',//总价

		};
	},
	mounted() {
		var that = this;
		setTimeout(() => {
			that.arr = [];
			function arrFun() {
				const numArr = [];
				const time = setInterval(() => {
					// 生成红球
					const redNum = Math.floor(Math.random() * (1 - 34) + 34);
					// 蓝球
					const blueNum = Math.floor(Math.random() * (1 - 17) + 17);
					numArr.push(redNum);
					// 红球去重
					const n = arrRemoval(numArr);
					for (let i = 1; i < n.length; i++) {
						// 获取当前遍历数字。
						const currentNum = n[i];
						// 拿到上一个索引值进行比较
						let prevIndex = i - 1;
						// 对红球进行排序
						while (prevIndex >= 0 && n[prevIndex] > currentNum) {
							n[prevIndex + 1] = n[prevIndex];
							prevIndex--;
						}
						n[prevIndex + 1] = currentNum;
					}
					if (n.length === 6) {
						n.push(blueNum);
						that.arr.push(n);
						clearInterval(time);
						// return n
					}
				}, 10);
				function arrRemoval(array) {
					const set = [...new Set(array)];
					return set;
				}
			}
			const intervalFun = setInterval(() => {
				arrFun();
				// 机选多组, n+1
				if (that.arr.length === 4) {
					clearInterval(intervalFun);
				}
			}, 100);
		}, 2000);
	},
	methods: {
		//模式选择
		modeChange(index) {
			this.control = true;
			if(index == 0) {
				this.current=0
				this.control = true;
			} else {
				this.current=1
				this.control = false;
			}


		},
		//获取点击的值
		
		lotto_front(item){
			this.flag=this.arrfront_confirm.includes(item);
			if(this.flag==true){
				document.getElementById(item).className="is-boll";
				this.arrfront_confirm.splice(this.arrfront_confirm.indexOf(item),1);
				let m=this.arrfront_confirm.length;
				let n=this.arrback_confirm.length;
				if(m>4&&n>1){
					document.getElementById("s_lotto").className="select_areas";
					console.log("sa",this.num)
					this.num= this.count_zhu_superlottery(m,n)
					//alert("sa",this.num)
				}
				if(m<5||n<2){
					document.getElementById("s_lotto").className="select_area";
				}
				console.log(document.getElementById(item).innerHTML);
			}
			else{
				document.getElementById(item).className="red-boll-active";
				let frontval=parseInt(document.getElementById(item).innerHTML);
				this.arrfront_confirm.push(frontval);
				let m=this.arrfront_confirm.length;
				let n=this.arrback_confirm.length;
				if(m>4&&n>1){
					document.getElementById("s_lotto").className="select_areas";
					console.log("sa",this.num)
					this.num= this.count_zhu_superlottery(m,n)
					//alert("sa",this.num)
				}
				console.log(this.arrfront_confirm);
			}
			
		},
		lotto_back(item1){
			
			this.flag=this.arrback_confirm.includes(item1-100);
			if(this.flag==true){
				document.getElementById(item1).className="is-boll";
				this.arrback_confirm.splice(this.arrback_confirm.indexOf(item1-100),1);
				let m=this.arrfront_confirm.length;
				let n=this.arrback_confirm.length;
				if(m>4&&n>1){
					document.getElementById("s_lotto").className="select_areas";
					console.log("sa",this.num)
					this.num= this.count_zhu_superlottery(m,n)
					//alert("sa",this.num)
				}
				if(m<5||n<2){
					document.getElementById("s_lotto").className="select_area";
				}
				console.log(this.arrback_confirm);
			}
			else{
				document.getElementById(item1).className="blue-boll-active";
				let frontval=parseInt(document.getElementById(item1).innerHTML);
				this.arrback_confirm.push(frontval);
				let m=this.arrfront_confirm.length;
				let n=this.arrback_confirm.length;
				if(m>4&&n>1){
					document.getElementById("s_lotto").className="select_areas";
					console.log("sa",this.num)
					this.num= this.count_zhu_superlottery(m,n)
					//alert("sa",this.num)
				}
				
				console.log(this.arrback_confirm);
			}
			
		},
		confirm_lotto(){
			if(this.arrfront_confirm.length<5){
				this.show=true;
				this.description="请至少选择5个红球"
			}
			else if(this.arrback_confirm.length<2){
				this.show=true;
				this.description="请至少选择2个蓝球"
			}
			else if(this.arrfront_confirm.length>5 ||this.arrback_confirm.length>2){
				this.confirm_lottos.push({ltype: "复式",larrfront: this.arrfront_confirm.toString(),
				larrback: this.arrback_confirm.toString(),nums: this.num,})
				this.nums+=this.num;
				this.money=this.nums*this.periods*this.multiple*2;
				this.service_money=Math.round(this.money * 100*0.02) / 100;
				this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;
			}
			else{
				this.confirm_lottos.push({ltype: "单式",larrfront: this.arrfront_confirm.toString(),
				larrback: this.arrback_confirm.toString(),nums: this.num,})
				this.nums+=this.num;
				this.money=this.nums*this.periods*this.multiple*2;
				this.service_money=Math.round(this.money * 100*0.02) / 100;
				this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;
			}
		},
		
		factorial(num){
		    if(num <= 1) {
		         return 1;      
		    }else{
		          return num * this.factorial(num-1);   
		    }
		},
		
		combination(n,m){
			var divisor = this.factorial(n-m) * this.factorial(m);
			return this.factorial(n)/divisor;
		},
		count_zhu_superlottery(r,b){
			return this.combination(r,5) * this.combination(b,2);
		},
		//是否多倍
		Multiple(e) {
			this.multiple=e.value
			console.log('当前值为: ' + e.value)
			this.money=this.nums*this.periods*this.multiple*2;
			this.service_money=Math.round(this.money * 100*0.02) / 100;
			this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;
		},
		//是否多期
		valChange(e) {
			this.periods=e.value
			console.log('当前值为: ' + e.value)
			this.money=this.nums*this.periods*this.multiple*2
			this.service_money=Math.round(this.money * 100*0.02) / 100;
			this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;
		},
		//是否追加
		checkboxChange(e) {
					 //console.log(e);
					 if(e.value==true){
						 this.money=this.nums*this.periods*this.multiple*3
						 this.service_money=Math.round(this.money * 100*0.02) / 100;
						 this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;
					 }
					 else{
						 this.money=this.nums*this.periods*this.multiple*2
						 this.service_money=Math.round(this.money * 100*0.02) / 100;
						 this.moneys=Math.round(this.money * 100*0.02) / 100+this.money;
					 }
					
				},
	},
	
};
</script>

<style lang="scss" scoped>
page {
	background: #cccccc;
}
.container {
	margin: 0 auto;
}
.lotto_all{
	.lotto_manual{
		ul{
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			flex-direction: row;
			list-style: none;
		}
		ul li{
			width: 68rpx;
			height: 68rpx;
			border-radius: 68rpx;
			line-height: 68rpx;
			text-align: center;
			margin: 6rpx;
			background-color: #ffffff;
		}
		.is-boll{
			color: #000;
			background: white;
		}
		.red-boll-active{
			color: #fff;
			background: red;
		}
		.blue-boll-active{
			color: #fff;
			background: blue;
		}
	}
	.select_area{
		display: none;
	}
	.select_areas{
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		display: block;
	}
	
	.confirm_area{
		    border: #ccc 1px solid;
		    min-height: 120px;
		    padding: 6px;
		    background: #fff;
	}
	
	
}
.beitou_area{
		background: #ffffff;
		display: flex;
		flex-direction: row;
	}
.append{
		//height: 40rpx;
		padding:10rpx 10rpx ;
		background: #ffffff;
		span{
			font-size: 24rpx;
			color: red;
		}
	}

</style>

最终效果展示图如下,后续不断优化代码和界面样式

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

variation8

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值