-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage2.html
More file actions
327 lines (281 loc) · 12.7 KB
/
page2.html
File metadata and controls
327 lines (281 loc) · 12.7 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, initial-scale=1, maximum-scale=1">
<title>Market-simulator 市场模拟器</title>
<style>
body {
background-color: #f0f7ff;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 左侧导航栏样式 */
.sidenav {
height: 100%;
width: 200px;
position: fixed;
top: 0;
left: 0;
background-color: #333;
padding-top: 20px;
}
/* 导航栏中的链接 */
.sidenav a {
padding: 15px 20px;
text-decoration: none;
font-size: 18px;
color: white;
display: block;
}
.sidenav a:hover {
background-color: #575757;
}
/* 主体内容 */
.container {
margin-left: 220px; /* 给导航栏留出空间 */
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
text-align: center;
max-width: 90%;
width: 100%;
margin-top: 40px;
}
h1 {
font-size: 2em;
margin-bottom: 10px;
color: #333;
}
h2 {
font-size: 1.8em;
font-weight: bold;
margin-bottom: 20px;
color: #333;
}
p {
font-size: 1em;
margin-bottom: 20px;
color: #555;
}
label {
font-size: 1em;
margin-bottom: 5px;
display: block;
text-align: left;
color: #333;
}
select {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 1.1em;
box-sizing: border-box;
}
table {
border-collapse: collapse;
width: 100%;
margin-top: 20px;
}
th, td {
border: 1px solid #000;
padding: 10px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.summary {
margin-top: 10px;
margin-bottom: 20px;
font-size: 1.2em;
padding: 20px;
background-color: white;
border-radius: 10px;
}
button {
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
font-size: 1.2em;
cursor: pointer;
margin-top: 20px;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<!-- 左侧导航栏 -->
<div class="sidenav">
<a href="index.html">主页</a>
<a href="#calculator">商品利润对比</a> <!-- 页面内跳转示例 -->
<a href="page2.html">资源计算器</a>
<a href="#about">关于</a> <!-- 页面内跳转示例 -->
</div>
<!-- 主体内容 -->
<div class="container" id="calculator">
<h1>Market-simulator <strong>市场模拟器</strong></h1>
<hr>
<p class="description">This page is developed for calculating how many resources should prepare to product, including cost and profit margin information.</p>
<p class="description">这个页面是为了计算应该准备生产多少资源、成本及利润率而开发的。</p>
<!-- 一级选项 -->
<label for="primarySelect">请选择机器:</label>
<select id="primarySelect" onchange="updateSecondaryOptions()">
<option value="">--请选择--</option>
<option value="brewing machinery">酿酒机</option>
<option value="meat slicer">切肉器</option>
<option value="oven">烤箱</option>
</select>
<!-- 二级选项 -->
<label for="secondarySelect">请选择商品:</label>
<select id="secondarySelect">
<option value="">--请选择--</option>
</select>
<!-- 显示结果 -->
<div id="resultArea"></div>
<button onclick="calculateResults()">计算</button>
</div>
<script>
// 一级选项对应的二级选项
const options = {
"brewing machinery": ["啤酒", "威士忌", "葡萄酒", "香槟"],
"meat slicer": ["菲力牛排", "香肠", "发酵香肠", "汉堡肉", "条状牛排", "肋眼牛排", "肋排"],
"oven": ["面包", "曲奇饼干", "姜饼", "派", "椒盐卷饼", "草莓巧克力"]
};
// 集中定义所有原材料的购买成本和生产成本
const materialsInfo = {
"麦芽": { purchaseCost: 2, productionCost: 1 },
"酵母": { purchaseCost: 1.5, productionCost: 0.5 },
"水": { purchaseCost: 0.1, productionCost: 0.05 },
"谷物": { purchaseCost: 3, productionCost: 1 },
"牛肉": { purchaseCost: 10, productionCost: 5 },
"调料": { purchaseCost: 1, productionCost: 0.2 },
"面粉": { purchaseCost: 2, productionCost: 0.5 },
"黄油": { purchaseCost: 3, productionCost: 1 },
"糖": { purchaseCost: 1.2, productionCost: 0.4 }
};
// 商品的销售价格、进货价以及生产数量
const productPrices = {
"啤酒": { salesPrice: 30, wholesalePrice: 22, productionQuantity: 4 },
"威士忌": { salesPrice: 50, wholesalePrice: 35, productionQuantity: 3 },
"菲力牛排": { salesPrice: 80, wholesalePrice: 60, productionQuantity: 2 },
"面包": { salesPrice: 15, wholesalePrice: 10, productionQuantity: 10 },
"曲奇饼干": { salesPrice: 25, wholesalePrice: 18, productionQuantity: 8 }
};
// 商品对应的原材料及其数量
const materialsData = {
"啤酒": [
{ material: "麦芽", quantity: 5 },
{ material: "酵母", quantity: 1 },
{ material: "水", quantity: 10 }
],
"威士忌": [
{ material: "谷物", quantity: 7 },
{ material: "酵母", quantity: 2 },
{ material: "水", quantity: 8 }
],
"菲力牛排": [
{ material: "牛肉", quantity: 1 },
{ material: "调料", quantity: 0.1 }
],
"面包": [
{ material: "面粉", quantity: 3 },
{ material: "酵母", quantity: 1 },
{ material: "水", quantity: 2 }
],
"曲奇饼干": [
{ material: "面粉", quantity: 2 },
{ material: "黄油", quantity: 1 },
{ material: "糖", quantity: 0.5 }
]
};
// 更新二级选项
function updateSecondaryOptions() {
var primarySelect = document.getElementById("primarySelect");
var secondarySelect = document.getElementById("secondarySelect");
var selectedValue = primarySelect.value;
// 清空二级选项
secondarySelect.innerHTML = '<option value="">--请选择--</option>';
// 如果有对应的二级选项数据,则更新二级下拉框
if (selectedValue && options[selectedValue]) {
var subOptions = options[selectedValue];
subOptions.forEach(function(option) {
var newOption = document.createElement("option");
newOption.value = option;
newOption.text = option;
secondarySelect.appendChild(newOption);
});
}
}
// 显示选定商品的原材料、数量、成本、利润率信息
function calculateResults() {
var selectedProduct = document.getElementById('secondarySelect').value;
var resultArea = document.getElementById('resultArea');
// 清空之前的结果
resultArea.innerHTML = "";
// 检查是否有该商品的原材料数据和销售价格
if (selectedProduct && materialsData[selectedProduct] && productPrices[selectedProduct]) {
var salesPrice = productPrices[selectedProduct].salesPrice;
var wholesalePrice = productPrices[selectedProduct].wholesalePrice;
var productionQuantity = productPrices[selectedProduct].productionQuantity;
// 生产每个商品所需的总成本
let totalProductionCost = 0;
let totalPurchaseCost = 0; // 用于进货模式计算
// 遍历原材料数据,计算生产成本和购买成本
materialsData[selectedProduct].forEach(function(item) {
var material = item.material;
var quantity = item.quantity;
var productionCost = materialsInfo[material].productionCost * quantity;
var purchaseCost = materialsInfo[material].purchaseCost * quantity;
totalProductionCost += productionCost;
totalPurchaseCost += purchaseCost;
});
// 由于每次生产生成指定数量的商品,因此生产成本除以生产数量
let costPerProductProduction = totalProductionCost / productionQuantity;
let costPerProductPurchase = totalPurchaseCost; // 进货模式每次仅进货一个商品
// 计算利润率
var productionProfitMargin = ((salesPrice - costPerProductProduction) / salesPrice * 100).toFixed(2);
var purchaseProfitMargin = ((salesPrice - costPerProductPurchase) / salesPrice * 100).toFixed(2);
var wholesaleProfitMargin = ((salesPrice - wholesalePrice) / salesPrice * 100).toFixed(2);
// 创建表格来显示原材料、数量、生产成本和进货成本
var tableHTML = "<h2>商品:" + selectedProduct + " 所需原材料及成本</h2>";
tableHTML += "<table><tr><th>原材料</th><th>数量</th><th>生产成本</th><th>进货成本</th></tr>";
// 遍历原材料并插入表格
materialsData[selectedProduct].forEach(function(item) {
var material = item.material;
var quantity = item.quantity;
var productionCost = materialsInfo[material].productionCost * quantity;
var purchaseCost = materialsInfo[material].purchaseCost * quantity;
tableHTML += "<tr><td>" + material + "</td><td>" + quantity + "</td><td>¥" + productionCost.toFixed(2) + "</td><td>¥" + purchaseCost.toFixed(2) + "</td></tr>";
});
tableHTML += "<tr><th colspan='2'>总计</th><th>¥" + totalProductionCost.toFixed(2) + "</th><th>¥" + totalPurchaseCost.toFixed(2) + "</th></tr>";
tableHTML += "</table>";
// 显示销售价格和利润率信息,分为生产模式和进货模式
var summaryHTML = "<div class='summary summary-1'><strong>销售价格:</strong>¥" + salesPrice.toFixed(2) + "<br>";
summaryHTML += "<strong>直接进货价:</strong>¥" + wholesalePrice.toFixed(2) + "</div><hr>";
summaryHTML += "<div class='summary summary-2'><h3>生产模式</h3>";
summaryHTML += "<strong>基于生产模式的成本(每个商品):</strong>¥" + costPerProductProduction.toFixed(2) + "<br>";
summaryHTML += "<strong>基于生产模式的利润率:</strong>" + productionProfitMargin + "%</div><hr>";
summaryHTML += "<div class='summary summary-3'><h3>进货模式</h3>";
summaryHTML += "<strong>基于进货模式的原材料成本(每个商品):</strong>¥" + costPerProductPurchase.toFixed(2) + "<br>";
summaryHTML += "<strong>基于原材料进货的利润率:</strong>" + purchaseProfitMargin + "%<br>";
summaryHTML += "<strong>基于直接进货的利润率:</strong>" + wholesaleProfitMargin + "%</div>";
// 将表格和总结部分插入到页面中
resultArea.innerHTML = tableHTML + summaryHTML;
} else {
resultArea.innerHTML = "<p>没有找到该商品的原材料数据或销售价格。</p>";
}
}
</script>
</body>
</html>