/*默认滚动条样式*/
::-webkit-scrollbar {
width: 12px;
height: 12px;
background-color: #F5F5F5;
}
::-webkit-scrollbar-track {
background-color: #fff;
}
::-webkit-scrollbar-thumb {
-webkit-border-radius: 6px;
border-radius: 6px;
min-height: 30px;
border-radius: 6px;
border: 2px solid #fff;
margin: 5px;
background-color: #e0e0e0;
}
::-webkit-scrollbar-thumb:hover {
background: #cfcfcf;
}
#main {
display: flex;
}
.left {
padding: 10px;
box-sizing: padding-box;
border-right: 1px #F2F6FC solid;
}
.right {
padding: 10px;
width: 100%;
}
@media screen and (max-width: 600px) {
#main {
flex-wrap: wrap;
}
.left {
border: none;
}
}
.input-text .el-input__inner {
width: 210px;
}
.short-select .el-input__inner {
width: 150px;
}
.el-input-number--small {
width: 40px;
}
.el-tabs__item {
padding: 0 15px;
}
.el-form-item__content {
display: flex;
}
.swith .el-form-item__content {
display: block;
}
div.text {
padding: 0 6px;
}
.el-input-number.is-without-controls .el-input__inner {
padding-left: 7px;
padding-right: 7px;
}
#main.hidden {
display: none;
}
.el-dialog__body {
padding: 10px 20px 20px 20px;
font-size: 14px;
line-height: 1.6;
}
.el-dialog__body p, .el-dialog__body h3 {
margin: 10px 0;
}
.bold {
font-weight: 600;
}
.el-notification.right {
right: 16px;
width: 91%;
}
.el-checkbox__label {
padding-left: 5px;
}
说明
v-for="(r, i) in data"
:key="i"
:label="r.name + '(' + (repices_x[index] ? Math.ceil(r.value * 105 / 100) : r.value) + ')'"
:value="r.name + ',' + r.value">
已修
计算
重置
确 定
$(function() {
var app = new Vue({
el: '#main',
data: {
dialogWidth: '90%',
dialogVisible: false,
min: '-5',
height: window.innerHeight - 60,
max: '5',
step: '1',
num: 3,
tolerance: true,
repices: [],
repices_c: [1, 1, 1, 1, 1, 1],
repices_x: [false, false, false, false, false, false],
result: '0',
tableData: [],
r1: '菜谱1',
r2: '菜谱2',
r3: '菜谱3',
r4: '菜谱4',
r5: '菜谱5',
r6: '菜谱6',
r1_f: [],
r2_f: [],
r3_f: [],
r4_f: [],
r5_f: [],
r6_f: [],
data: []
},
mounted() {
this.initData();
if (window.location.origin === 'https://yuwenxifan.github.io') {
this.$message({
showClose: true,
message: '新增国内镜像,地址https://yuwenxifan.gitee.io/foodgod/'
});
}
$(document).ready(() => {
$(main).removeClass('hidden');
});
if (window.innerWidth > 1000) {
this.dialogWidth = '950px';
}
const h = this.$createElement;
if (window.innerWidth < 600) {
console.log('lalala');
this.$notify({
title: '提示',
type: 'warning',
dangerouslyUseHTMLString: true,
message: '_(:з」∠)_手机浏览器好像不太兼容,不建议手机使用
---by菜鸡小鱼',
duration: 0
});
}
},
methods: {
initData() {
const that = this;
$.ajax({
url: 'https://bcjh.xyz/api/get_recipe',
}).success(rst => {
const data = rst;
that.data = data.map(item => {
return {
id: item.id,
name: item.name,
value: item.price
};
});
}).fail(err => {
console.log(err);
that.$message.error('调用数据出错,使用备用本地数据,可能不全');
that.standbyInitData();
});
},
standbyInitData() {
const that = this;
$.ajax({
url: 'data/data.min.json?v=1',
}).success(rst => {
const data = rst.recipes;
that.data = data.map(item => {
return {
id: item.recipeId,
name: item.name,
value: item.price
};
});
}).fail(err => {
that.$message.error('调用本地数据也出错了是什么鬼');
});
},
filterHandler(value, row, column) {
const property = column['property'];
return row[property] == value;
},
/**
* @param {array} multiples 倍数
* @param {array} cnts 份数
* @param {array} values 单价
* @param {int} tolerance 容差
**/
check(multiples, cnts, values, tolerance) {
if (Math.ceil(this.step) == this.step || tolerance == 0) {
return true;
} else {
let count = multiples.map((multiple, index) => {
let result = multiple * values[index];
if (Math.ceil(result) != result) {
return cnts[index];
} else {
return -1;
}
});
count = count.filter(cnt => {
return cnt != -1;
});
let possible = count.length == 1 ? count : this.listAll(count);
possible.unshift(0);
return possible.indexOf(tolerance) > -1;
}
},
listAll(arr, num) {
for (var a2 = []; a2.push([]) < arr.length;) {
var l = Math.pow(2, arr.length) - 1;
}
for (let i = 1; i <= l; i++) {
let s2 = i.toString(2).split("").reverse();
let t = [];
let m = -1;
for (var k = 0; k < s2.length; k++) {
if (s2[k] == "1") {
t.push(arr[k]);
m++;
}
}
a2[m].push(t);
}
let a3 = [];
for (let item of a2) {
a3 = a3.concat(item);
}
a3 = a3.map(i => {
if (typeof i == 'object') {
let r = 0;
for (let j of i) {
r = r + j;
}
return r;
} else {
return i;
}
});
a3 = Array.from(new Set(a3));
return a3;
},
toTry () {
let count = 0;
this.tableData = [];
for (let i of this.repices) {
if (i != '') {
count++;
}
}
if (count < this.num || this.min == '' || this.max == '' || this.step == '' || this.result == '') {
this.$message.warning('请填写配置!');
} else if (isNaN(parseInt(this.min)) || isNaN(parseInt(this.max)) || isNaN(parseFloat(this.step)) || isNaN(parseInt(this.result))) {
this.$message.warning('最大值/最小值/步长/奖励分请填写数字');
} else if (parseFloat(this.step) <= 0) {
this.$message.warning('步长必须大于0');
} else {
let repices = this.repices.map((item, index) => {
const ratio = this.repices_x[index] ? 105 : 100;
return {
name: item.split(',')[0],
value: Math.ceil(parseInt(item.split(',')[1]) * ratio / 100)
}
});
if (this.num == 3) {
this.three(
repices[0].value,
repices[0].name,
repices[1].value,
repices[1].name,
repices[2].value,
repices[2].name,
this.result
);
} else if (this.num == 4) {
this.four(
repices[0].value,
repices[0].name,
repices[1].value,
repices[1].name,
repices[2].value,
repices[2].name,
repices[3].value,
repices[3].name,
this.result
);
} else if (this.num == 5) {
this.five(
repices[0].value,
repices[0].name,
repices[1].value,
repices[1].name,
repices[2].value,
repices[2].name,
repices[3].value,
repices[3].name,
repices[4].value,
repices[4].name,
this.result
);
} else if (this.num == 6) {
this.six(
repices[0].value,
repices[0].name,
repices[1].value,
repices[1].name,
repices[2].value,
repices[2].name,
repices[3].value,
repices[3].name,
repices[4].value,
repices[4].name,
repices[5].value,
repices[5].name,
this.result
);
}
}
this.r1_f = this.setFilter(this.tableData, 'v1');
this.r2_f = this.setFilter(this.tableData, 'v2');
this.r3_f = this.setFilter(this.tableData, 'v3');
this.r4_f = this.setFilter(this.tableData, 'v4');
this.r5_f = this.setFilter(this.tableData, 'v5');
this.r6_f = this.setFilter(this.tableData, 'v6');
},
reset() {
this.repices = [];
this.repices_x = [false, false, false, false, false, false];
this.repices_c = [1, 1, 1, 1, 1, 1];
this.result = '0';
},
setFilter(data, key) {
if (data.length > 0 && (data[0][key] || data[0][key] == 0)) {
let arr = data.map(item => {
return item[key]
});
arr = arr.filter((item, index) => {
return index == arr.indexOf(item);
});
arr.sort();
arr = arr.map(item => {
return { text: item, value: item };
});
return arr;
} else {
return [];
}
},
three(a, a_n, b, b_n, c, c_n, result) {
let count = 0;
let tolerance = 0;
let min = parseFloat(this.min);
let max = parseFloat(this.max);
let step = parseFloat(this.step);
let c_1 = this.repices_c[0] || 1;
let c_2 = this.repices_c[1] || 1;
let c_3 = this.repices_c[2] || 1;
for (let i = 0; i < 3; i++) {
tolerance += (this.repices_c[i] || 1);
}
tolerance = this.tolerance && step != Math.ceil(step) ? tolerance : 0;
for (let i = min; i <= max; i += step) {
for (let j = min; j <= max; j += step) {
for (let k = min; k <= max; k += step) {
let x = Math.ceil(i * a) * c_1 + Math.ceil(j * b) * c_2 + Math.ceil(k * c) * c_3;
if (x >= result && (x - result) <= tolerance) {
let check = this.check(
[i, j, k],
[c_1, c_2, c_3],
[a, b, c],
x - result
);
if (check) {
count ++;
this.r1 = a_n;
this.r2 = b_n;
this.r3 = c_n;
this.tableData.push({ v1: i, v2: j, v3: k, score: x, error: x - result});
}
}
}
}
}
this.$message.success({
showClose: true,
message: `尝试完毕,共有${count}种结果`
});
},
four(a, a_n, b, b_n, c, c_n, d, d_n, result) {
let count = 0;
let tolerance = 0;
let min = parseFloat(this.min);
let max = parseFloat(this.max);
let step = parseFloat(this.step);
let c_1 = this.repices_c[0] ? this.repices_c[0] : 1;
let c_2 = this.repices_c[1] ? this.repices_c[1] : 1;
let c_3 = this.repices_c[2] ? this.repices_c[2] : 1;
let c_4 = this.repices_c[3] ? this.repices_c[3] : 1;
for (let i = 0; i < 4; i++) {
tolerance += (this.repices_c[i] || 1);
}
tolerance = this.tolerance && step != Math.ceil(step) ? tolerance : 0;
for (let i = min; i <= max; i += step) {
for (let j = min; j <= max; j += step) {
for (let k = min; k <= max; k += step) {
for (let o = min; o <= max; o += step) {
let x = Math.ceil(i * a) * c_1 + Math.ceil(j * b) * c_2 + Math.ceil(k * c) * c_3 + Math.ceil(o * d) * c_4;
if (x >= result && (x - result) <= tolerance) {
let check = this.check(
[i, j, k, o],
[c_1, c_2, c_3, c_4],
[a, b, c, d],
x - result
);
if (check) {
count ++;
this.r1 = a_n;
this.r2 = b_n;
this.r3 = c_n;
this.r4 = d_n;
this.tableData.push({ v1: i, v2: j, v3: k , v4: o, score: x, error: x - result});
}
}
}
}
}
}
this.$message.success({
showClose: true,
message: `尝试完毕,共有${count}种结果`
})
},
five(a, a_n, b, b_n, c, c_n, d, d_n, e, e_n, result) {
let count = 0;
let tolerance = 0;
let min = parseFloat(this.min);
let max = parseFloat(this.max);
let step = parseFloat(this.step);
let c_1 = this.repices_c[0] ? this.repices_c[0] : 1;
let c_2 = this.repices_c[1] ? this.repices_c[1] : 1;
let c_3 = this.repices_c[2] ? this.repices_c[2] : 1;
let c_4 = this.repices_c[3] ? this.repices_c[3] : 1;
let c_5 = this.repices_c[4] ? this.repices_c[4] : 1;
for (let i = 0; i < 5; i++) {
tolerance += (this.repices_c[0] || 1);
}
tolerance = this.tolerance && step != Math.ceil(step) ? tolerance : 0;
for (let i = min; i <= max; i += step) {
for (let j = min; j <= max; j += step) {
for (let k = min; k <= max; k += step) {
for (let o = min; o <= max; o += step) {
for (let p = min; p <= max; p += step) {
let x = Math.ceil(i * a) * c_1 + Math.ceil(j * b) * c_2 + Math.ceil(k * c) * c_3 + Math.ceil(o * d) * c_4 + Math.ceil(p * e) * c_5;
if (x >= result && (x - result) <= tolerance) {
let check = this.check(
[i, j, k, o, p],
[c_1, c_2, c_3, c_4, c_5],
[a, b, c, d, e],
x - result
);
if (check) {
count ++;
this.r1 = a_n;
this.r2 = b_n;
this.r3 = c_n;
this.r4 = d_n;
this.r5 = e_n;
this.tableData.push({ v1: i, v2: j, v3: k , v4: o, v5: p, score: x, error: x - result});
}
}
}
}
}
}
}
this.$message.success({
showClose: true,
message: `尝试完毕,共有${count}种结果`
})
},
six(a, a_n, b, b_n, c, c_n, d, d_n, e, e_n, f, f_n, result) {
let count = 0;
let tolerance = 0;
let min = parseFloat(this.min);
let max = parseFloat(this.max);
let step = parseFloat(this.step);
let c_1 = this.repices_c[0] ? this.repices_c[0] : 1;
let c_2 = this.repices_c[1] ? this.repices_c[1] : 1;
let c_3 = this.repices_c[2] ? this.repices_c[2] : 1;
let c_4 = this.repices_c[3] ? this.repices_c[3] : 1;
let c_5 = this.repices_c[4] ? this.repices_c[4] : 1;
let c_6 = this.repices_c[5] ? this.repices_c[5] : 1;
for (let i = 0; i < 6; i++) {
tolerance += (this.repices_c[0] || 1);
}
tolerance = this.tolerance && step != Math.ceil(step) ? tolerance : 0;
for (let i = min; i <= max; i += step) {
for (let j = min; j <= max; j += step) {
for (let k = min; k <= max; k += step) {
for (let o = min; o <= max; o += step) {
for (let p = min; p <= max; p += step) {
for (let q = min; q <= max; q += step) {
let x = Math.ceil(i * a) * c_1 + Math.ceil(j * b) * c_2 + Math.ceil(k * c) * c_3 + Math.ceil(o * d) * c_4 + Math.ceil(p * e) * c_5 + Math.ceil(q * f) * c_6;
if (x >= result && (x - result) <= tolerance) {
let check = this.check(
[i, j, k, o, p, q],
[c_1, c_2, c_3, c_4, c_5, c_6],
[a, b, c, d, e, f],
x - result
);
if (check) {
count ++;
this.r1 = a_n;
this.r2 = b_n;
this.r3 = c_n;
this.r4 = d_n;
this.r5 = e_n;
this.r6 = f_n;
this.tableData.push({ v1: i, v2: j, v3: k , v4: o, v5: p, v6: q, score: x, error: x - result});
}
}
}
}
}
}
}
}
this.$message.success({
showClose: true,
message: `尝试完毕,共有${count}种结果`
})
}
},
watch: {
num() {
this.tableData = [];
this.r1 = '菜谱1';
this.r2 = '菜谱2';
this.r3 = '菜谱3';
this.r4 = '菜谱4';
this.r5 = '菜谱5';
this.r6 = '菜谱6';
this.r1_f = [];
this.r2_f = [];
this.r3_f = [];
this.r4_f = [];
this.r5_f = [];
this.r6_f = [];
}
}
});
});
一键复制
编辑
Web IDE
原始数据
按行查看
历史