吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 656|回复: 11
收起左侧

[其他转载] ai写的单文件计算发货回桶数量

[复制链接]
losrss 发表于 2025-5-12 09:41
本帖最后由 苏紫方璇 于 2025-5-12 10:28 编辑

工作需要要计算发货+桶+盖子,回桶也是这样,自己算太麻烦了用ai搞了个单文件还可以。

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>桶盖管理系统(增强版)</title>
    <!-- 引入xlsx库 -->
    <script src="https://cdn.sheetjs.com/xlsx-0.20.0/package/dist/xlsx.full.min.js"></script>
    <style>
        :root {
            --primary-color: #3498db;
            --danger-color: #e74c3c;
            --success-color: #2ecc71;
        }

       <!--以下是改进后的网页应用方案,新增日期范围选择、动态记录管理和支持负数的库存计算功能:-->

        :root {
            --primary-color: #3498db;
            --danger-color: #e74c3c;
        }

        body {
            font-family: '微软雅黑', Arial, sans-serif;
            max-width: 800px;
            margin: 20px auto;
            padding: 20px;
            background-color: #f8f9fa;
        }

        .container {
            background: white;
            padding: 25px;
            border-radius: 10px;
            box-shadow: 0 2px 15px rgba(0,0,0,0.1);
        }

        .record-form {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            gap: 10px;
            margin-bottom: 20px;
        }

        input, select {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }

        button {
            background: var(--primary-color);
            color: white;
            padding: 10px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: opacity 0.3s;
        }

        button:hover {
            opacity: 0.9;
        }

        .records-table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }

        .records-table th,
        .records-table td {
            padding: 12px;
            border: 1px solid #eee;
            text-align: center;
        }

        .summary {
            background: #f8f9fa;
            padding: 15px;
            border-radius: 6px;
            margin-top: 20px;
        }

        .negative {
            color: var(--danger-color);
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>时序桶盖管理系统</h1>

        <!-- 操作记录表单 -->
        <div class="record-form">
            <input type="date" id="operationDate" required>
            <select id="operationType">
                <option value="ship">发货</option>
                <option value="return">回货</option>
            </select>
            <input type="number" id="drumQty" placeholder="桶数量" step="1" required>
            <input type="number" id="lidQty" placeholder="盖数量" step="1" required>
            <button onclick="addRecord()">添加记录</button>
        </div>

        <!-- 记录表格 -->
        <table class="records-table">
            <thead>
                <tr>
                    <th>日期</th>
                    <th>类型</th>
                    <th>桶数量</th>
                    <th>盖数量</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody id="recordsBody"></tbody>
        </table>

        <!-- 统计面板 -->
        <div class="summary">
            <h3>实时库存统计</h3>
            <p>当前总桶数: <span id="totalDrums" class="negative">0</span></p >
            <p>当前总盖数: <span id="totalLids" class="negative">0</span></p >
            <button onclick="calculatePeriod()">生成时段报告</button>
            <div id="periodReport"></div>
        </div>
    </div>

    <script>
        let records = [];

        function addRecord() {
            const newRecord = {
                date: document.getElementById('operationDate').value,
                type: document.getElementById('operationType').value,
                drums: parseInt(document.getElementById('drumQty').value),
                lids: parseInt(document.getElementById('lidQty').value)
            };

            records.push(newRecord);
            renderTable();
            updateTotals();
        }

        function renderTable() {
            const tbody = document.getElementById('recordsBody');
            tbody.innerHTML = records.map((record, index) => `
                <tr>
                    <td>${record.date}</td>
                    <td>${record.type === 'ship' ? '🚚 发货' : '📦 回货'}</td>
                    <td class="${record.drums < 0 ? 'negative' : ''}">${record.drums}</td>
                    <td class="${record.lids < 0 ? 'negative' : ''}">${record.lids}</td>
                    <td>
                        <button onclick="deleteRecord(${index})" style="background:var(--danger-color)">删除</button>
                    </td>
                </tr>
            `).join('');
        }

        function deleteRecord(index) {
            records.splice(index, 1);
            renderTable();
            updateTotals();
        }

        function updateTotals() {
            const totalDrums = records.reduce((sum, record) => sum + record.drums, 0);
            const totalLids = records.reduce((sum, record) => sum + record.lids, 0);

            document.getElementById('totalDrums').textContent = totalDrums;
            document.getElementById('totalLids').textContent = totalLids;

            document.getElementById('totalDrums').className = totalDrums < 0 ? 'negative' : '';
            document.getElementById('totalLids').className = totalLids < 0 ? 'negative' : '';
        }

        function calculatePeriod() {
            const startDate = prompt("请输入起始日期 (YYYY-MM-DD)");
            const endDate = prompt("请输入结束日期 (YYYY-MM-DD)");

            const filtered = records.filter(record =>
                record.date >= startDate && record.date <= endDate
            );

            const periodDrums = filtered.reduce((sum, record) => sum + record.drums, 0);
            const periodLids = filtered.reduce((sum, record) => sum + record.lids, 0);

            document.getElementById('periodReport').innerHTML = `
                <h4>时段报告 ${startDate}${endDate}</h4>
                <p>桶数量变动: <span class="${periodDrums < 0 ? 'negative' : ''}">${periodDrums}</span></p >
                <p>盖数量变动: <span class="${periodLids < 0 ? 'negative' : ''}">${periodLids}</span></p >
            `;
        }
    </script>

    <div class="container">
        <h1>桶盖管理系统(增强版)</h1>

        <!-- 在表单后添加导出按钮 -->
        <div class="record-form">
            <!-- 原有表单元素保持不变... -->
        </div>

        <button class="export-btn" onclick="exportToExcel()">📤 导出Excel</button>

        <!-- 其余HTML结构保持不变... -->
    </div>

    <script>
        // 在addRecord函数中修改数值处理逻辑
        function addRecord() {
            const type = document.getElementById('operationType').value;
            const drumQty = document.getElementById('drumQty');
            const lidQty = document.getElementById('lidQty');

            // 自动转换回货为负数
            const newRecord = {
                date: document.getElementById('operationDate').value,
                type: type,
                drums: type === 'return' ? -Math.abs(drumQty.value) : Math.abs(drumQty.value),
                lids: type === 'return' ? -Math.abs(lidQty.value) : Math.abs(lidQty.value)
            };

            records.push(newRecord);
            drumQty.value = '';
            lidQty.value = '';
            renderTable();
            updateTotals();
        }

        // 新增Excel导出功能
        function exportToExcel() {
            /* 创建工作表数据 */
            const wsData = [
                ["日期", "操作类型", "桶数量", "盖数量", "备注"],
                ...records.map(record => [
                    record.date,
                    record.type === 'ship' ? '发货' : '回货',
                    record.drums,
                    record.lids,
                    record.drums + record.lids === 0 ? '' : '数量不匹配'
                ])
            ];

            /* 创建工作表 */
            const ws = XLSX.utils.aoa_to_sheet(wsData);

            /* 设置列宽 */
            ws['!cols'] = [
                { wch: 12 }, // 日期列
                { wch: 10 }, // 类型列
                { wch: 8 },  // 桶数列
                { wch: 8 },  // 盖数列
                { wch: 15 } // 备注列
            ];

            /* 创建工作簿并添加工作表 */
            const wb = XLSX.utils.book_new();
            XLSX.utils.book_append_sheet(wb, ws, "操作记录");

            /* 生成文件并下载 */
            const date = new Date().toISOString().slice(0,10);
            XLSX.writeFile(wb, `桶盖管理记录_${date}.xlsx`);
        }

        // 其余JavaScript代码保持不变...
    </script>
</body>
</html>

index.zip

2.87 KB, 下载次数: 11, 下载积分: 吾爱币 -1 CB

附件

免费评分

参与人数 2吾爱币 +4 热心值 +2 收起 理由
苏紫方璇 + 3 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
快乐的小驹 + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

追风营销 发表于 2025-5-12 11:27
手机端不能自适应帮你改了一下
[Asm] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>桶盖管理系统(增强版)</title>
    <!-- 引入xlsx库 -->
    <script src="https://cdn.sheetjs.com/xlsx-0.20.0/package/dist/xlsx.full.min.js"></script>
    <style>
        :root {
            --primary-color: #3498db;
            --danger-color: #e74c3c;
            --success-color: #2ecc71;
            --neutral-color: #f8f9fa;
            --border-color: #ddd;
        }
 
        * {
            box-sizing: border-box;
        }
 
        body {
            font-family: '微软雅黑', Arial, sans-serif;
            margin: 0;
            padding: 1rem;
            background-color: var(--neutral-color);
            min-height: 100vh;
        }
 
        .container {
            background: white;
            padding: 1.5rem;
            border-radius: 0.75rem;
            box-shadow: 0 0.5rem 1.5rem rgba(0,0,0,0.05);
            max-width: 100%;
            margin: 0 auto;
        }
 
        .record-form {
            display: grid;
            grid-template-columns: 1fr;
            gap: 0.75rem;
            margin-bottom: 1.5rem;
        }
 
        [url=home.php?mod=space&uid=945662]@media[/url] (min-width: 640px) {
            .record-form {
                grid-template-columns: repeat(5, 1fr);
            }
        }
 
        input, select {
            padding: 0.5rem 0.75rem;
            border: 1px solid var(--border-color);
            border-radius: 0.25rem;
            font-size: 0.9rem;
            width: 100%;
        }
 
        button {
            background: var(--primary-color);
            color: white;
            padding: 0.5rem 0.75rem;
            border: none;
            border-radius: 0.25rem;
            cursor: pointer;
            transition: all 0.2s ease;
            font-size: 0.9rem;
            width: 100%;
        }
 
        @media (min-width: 640px) {
            button {
                width: auto;
            }
        }
 
        button:hover {
            opacity: 0.9;
            transform: translateY(-1px);
        }
 
        button:active {
            transform: translateY(0);
        }
 
        .records-table {
            width: 100%;
            border-collapse: collapse;
            margin: 1.5rem 0;
            overflow-x: auto;
            display: block;
        }
 
        @media (min-width: 640px) {
            .records-table {
                display: table;
            }
        }
 
        .records-table th,
        .records-table td {
            padding: 0.75rem;
            border: 1px solid #eee;
            text-align: center;
            white-space: nowrap;
        }
 
        .records-table th {
            background-color: var(--neutral-color);
            font-weight: 600;
        }
 
        .summary {
            background: var(--neutral-color);
            padding: 1rem;
            border-radius: 0.5rem;
            margin-top: 1.5rem;
        }
 
        .negative {
            color: var(--danger-color);
            font-weight: bold;
        }
 
        .export-btn {
            margin-top: 1rem;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>时序桶盖管理系统</h1>
 
        <!-- 操作记录表单 -->
        <div class="record-form">
            <input type="date" id="operationDate" required>
            <select id="operationType">
                <option value="ship">发货</option>
                <option value="return">回货</option>
            </select>
            <input type="number" id="drumQty" placeholder="桶数量" step="1" required>
            <input type="number" id="lidQty" placeholder="盖数量" step="1" required>
            <button onclick="addRecord()">添加记录</button>
        </div>
 
        <!-- 导出按钮 -->
        <button class="export-btn" onclick="exportToExcel()">&#128228; 导出Excel</button>
 
        <!-- 记录表格 -->
        <div class="overflow-x-auto">
            <table class="records-table">
                <thead>
                    <tr>
                        <th>日期</th>
                        <th>类型</th>
                        <th>桶数量</th>
                        <th>盖数量</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody id="recordsBody"></tbody>
            </table>
        </div>
 
        <!-- 统计面板 -->
        <div class="summary">
            <h3>实时库存统计</h3>
            <p>当前总桶数: <span id="totalDrums" class="negative">0</span></p>
            <p>当前总盖数: <span id="totalLids" class="negative">0</span></p>
            <button onclick="calculatePeriod()">生成时段报告</button>
            <div id="periodReport"></div>
        </div>
    </div>
 
    <script>
        let records = [];
 
        // 初始化日期为今天
        document.getElementById('operationDate').valueAsDate = new Date();
 
        function addRecord() {
            const type = document.getElementById('operationType').value;
            const drumQty = document.getElementById('drumQty');
            const lidQty = document.getElementById('lidQty');
 
            // 自动转换回货为负数
            const newRecord = {
                date: document.getElementById('operationDate').value,
                type: type,
                drums: type === 'return' ? -Math.abs(parseInt(drumQty.value) || 0) : Math.abs(parseInt(drumQty.value) || 0),
                lids: type === 'return' ? -Math.abs(parseInt(lidQty.value) || 0) : Math.abs(parseInt(lidQty.value) || 0)
            };
 
            records.push(newRecord);
            drumQty.value = '';
            lidQty.value = '';
            renderTable();
            updateTotals();
        }
 
        function renderTable() {
            const tbody = document.getElementById('recordsBody');
            tbody.innerHTML = records.map((record, index) => `
                <tr>
                    <td>${record.date}</td>
                    <td>${record.type === 'ship' ? '&#128666; 发货' : '&#128230; 回货'}</td>
                    <td class="${record.drums < 0 ? 'negative' : ''}">${record.drums}</td>
                    <td class="${record.lids < 0 ? 'negative' : ''}">${record.lids}</td>
                    <td>
                        <button onclick="deleteRecord(${index})" style="background:var(--danger-color)">删除</button>
                    </td>
                </tr>
            `).join('');
        }
 
        function deleteRecord(index) {
            if (confirm('确定要删除这条记录吗?')) {
                records.splice(index, 1);
                renderTable();
                updateTotals();
            }
        }
 
        function updateTotals() {
            const totalDrums = records.reduce((sum, record) => sum + record.drums, 0);
            const totalLids = records.reduce((sum, record) => sum + record.lids, 0);
 
            document.getElementById('totalDrums').textContent = totalDrums;
            document.getElementById('totalLids').textContent = totalLids;
 
            document.getElementById('totalDrums').className = totalDrums < 0 ? 'negative' : '';
            document.getElementById('totalLids').className = totalLids < 0 ? 'negative' : '';
        }
 
        function calculatePeriod() {
            let startDate = prompt("请输入起始日期 (YYYY-MM-DD)");
            let endDate = prompt("请输入结束日期 (YYYY-MM-DD)");
 
            // 检查日期格式
            const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
            if (!dateRegex.test(startDate) || !dateRegex.test(endDate)) {
                alert("日期格式不正确,请使用YYYY-MM-DD格式");
                return;
            }
 
            const filtered = records.filter(record =>
                record.date >= startDate && record.date <= endDate
            );
 
            const periodDrums = filtered.reduce((sum, record) => sum + record.drums, 0);
            const periodLids = filtered.reduce((sum, record) => sum + record.lids, 0);
 
            document.getElementById('periodReport').innerHTML = `
                <h4>时段报告 ${startDate} 至 ${endDate}</h4>
                <p>桶数量变动: <span class="${periodDrums < 0 ? 'negative' : ''}">${periodDrums}</span></p>
                <p>盖数量变动: <span class="${periodLids < 0 ? 'negative' : ''}">${periodLids}</span></p>
            `;
        }
 
        // 新增Excel导出功能
        function exportToExcel() {
            if (records.length === 0) {
                alert('没有记录可导出');
                return;
            }
             
            /* 创建工作表数据 */
            const wsData = [
                ["日期", "操作类型", "桶数量", "盖数量", "备注"],
                ...records.map(record => [
                    record.date,
                    record.type === 'ship' ? '发货' : '回货',
                    record.drums,
                    record.lids,
                    record.drums + record.lids === 0 ? '' : '数量不匹配'
                ])
            ];
 
            /* 创建工作表 */
            const ws = XLSX.utils.aoa_to_sheet(wsData);
 
            /* 设置列宽 */
            ws['!cols'] = [
                { wch: 12 }, // 日期列
                { wch: 10 }, // 类型列
                { wch: 8 },  // 桶数列
                { wch: 8 },  // 盖数列
                { wch: 15 }  // 备注列
            ];
 
            /* 创建工作簿并添加工作表 */
            const wb = XLSX.utils.book_new();
            XLSX.utils.book_append_sheet(wb, ws, "操作记录");
 
            /* 生成文件并下载 */
            const date = new Date().toISOString().slice(0,10);
            XLSX.writeFile(wb, `桶盖管理记录_${date}.xlsx`);
        }
    </script>
</body>
</html>

免费评分

参与人数 1热心值 +1 收起 理由
shadmmd + 1 热心回复!

查看全部评分

苏紫方璇 发表于 2025-5-12 10:29
losrss 发表于 2025-5-12 09:44
请问这个代码怎么全部显示出来啊为啥会一段一段的

帮您修改了,markdown格式代码要加相应的代码标记
 楼主| losrss 发表于 2025-5-12 09:44
请问这个代码怎么全部显示出来啊为啥会一段一段的

点评

帮您修改了,markdown格式代码要加相应的代码标记  详情 回复 发表于 2025-5-12 10:29
kulouxiaohai 发表于 2025-5-12 11:33
这是用什么语言写的?
rhci 发表于 2025-5-12 12:01
kulouxiaohai 发表于 2025-5-12 11:33
这是用什么语言写的?

如图所见,html
ringcoco 发表于 2025-5-12 15:24
用哪个AI写的?deepseek?为什么我用deepseek写代码,总是服务器繁忙。感觉基本上长的代码就提示服务器繁忙。
WePojie 发表于 2025-5-12 19:43
写的挺好
robert1234 发表于 2025-5-13 08:44
谢谢分享。
 楼主| losrss 发表于 2025-5-14 12:12
ringcoco 发表于 2025-5-12 15:24
用哪个AI写的?deepseek?为什么我用deepseek写代码,总是服务器繁忙。感觉基本上长的代码就提示服务器繁忙 ...

是的,长的代码不行要新开页面了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-23 20:55

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表