793 lines
42 KiB
Plaintext
Executable File
793 lines
42 KiB
Plaintext
Executable File
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>生产计划排程维护</title>
|
||
<!-- 公共侧边栏组件 -->
|
||
<link rel="stylesheet" href="../common/nav.css">
|
||
<style>
|
||
*{margin:0;padding:0;box-sizing:border-box}
|
||
body{font-family:'Microsoft YaHei','PingFang SC',sans-serif;background:#f0f2f5;min-height:100vh}
|
||
.main-content{max-width:1500px;margin:0 auto;padding:16px 20px}
|
||
.panel{background:#fff;border-radius:8px;box-shadow:0 1px 4px rgba(0,0,0,.08);padding:16px;margin-bottom:14px}
|
||
.panel h3{font-size:15px;color:#333;font-weight:600;margin-bottom:12px}
|
||
.toolbar{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin-bottom:12px}
|
||
.toolbar input,.toolbar select{height:32px;padding:0 10px;border:2px solid #e0e0e0;border-radius:5px;font-size:13px;outline:none}
|
||
.toolbar input:focus,.toolbar select:focus{border-color:#1a73e8}
|
||
.btn{height:32px;padding:0 16px;border:none;border-radius:5px;font-size:12px;font-weight:600;cursor:pointer;transition:all .2s;color:#fff}
|
||
.btn-primary{background:linear-gradient(135deg,#1a73e8,#1557b0)}
|
||
.btn-primary:hover{opacity:.92}
|
||
.btn-green{background:#22c55e}
|
||
.btn-green:hover{opacity:.92}
|
||
.btn-red{background:#ef4444}
|
||
.btn-red:hover{opacity:.92}
|
||
.btn-blue{background:#3b82f6}
|
||
.btn-blue:hover{opacity:.92}
|
||
.btn-outline{background:#fff;color:#666;border:2px solid #e0e0e0}
|
||
.btn-outline:hover{border-color:#1a73e8;color:#1a73e8}
|
||
table{width:100%;border-collapse:collapse;font-size:13px}
|
||
thead th{background:#f8f9fa;color:#555;font-weight:600;padding:9px 12px;text-align:left;border:1px solid #999;border-bottom:2px solid #999;white-space:nowrap}
|
||
tbody td{padding:9px 12px;border:1px solid #ddd;color:#333}
|
||
tbody tr:hover{background:#f0f6ff}
|
||
/* 宽松:列表区留白 + 左右可滑动 */
|
||
.table-wrap{overflow-x:auto;overflow-y:auto;max-height:680px;border:1px solid #e2e8f0;border-radius:8px;background:#fff}
|
||
.table-wrap table{min-width:1480px}
|
||
.table-wrap thead th{position:sticky;top:0;z-index:2;background:#f8f9fa}
|
||
/* 固定列:序号 / 选中 / 操作 */
|
||
.col-num,.col-check,.col-op{position:sticky;left:0;z-index:3;background:#fff;box-shadow:1px 0 0 #e2e8f0}
|
||
.col-num{width:50px;text-align:center}
|
||
.col-check{width:44px;text-align:center}
|
||
.col-op{width:130px;text-align:center}
|
||
.col-num,.col-check input{cursor:pointer}
|
||
/* 行 hover 时固定列同步变色,避免横向滚动透出底色 */
|
||
.table-wrap tbody tr:hover .col-num,
|
||
.table-wrap tbody tr:hover .col-check,
|
||
.table-wrap tbody tr:hover .col-op{background:#f0f6ff}
|
||
.table-wrap tbody tr{cursor:pointer}
|
||
/* 批量操作栏 */
|
||
.batch-bar{display:flex;align-items:center;gap:10px;padding:10px 16px;background:#fef2f2;border:1px solid #fecaca;border-radius:8px;margin-top:10px;font-size:13px}
|
||
.badge{display:inline-block;padding:2px 10px;border-radius:12px;font-size:12px;font-weight:500}
|
||
.badge-success{background:#dcfce7;color:#166534}
|
||
.badge-warning{background:#fef3c7;color:#92400e}
|
||
.badge-info{background:#dbeafe;color:#1e40af}
|
||
.badge-muted{background:#f1f5f9;color:#64748b}
|
||
.toast{position:fixed;top:14px;left:50%;transform:translateX(-50%);padding:10px 22px;border-radius:8px;font-size:13px;z-index:1001;box-shadow:0 4px 20px rgba(0,0,0,.15);display:none;min-width:240px;text-align:center}
|
||
.toast.error{background:#fdeaea;color:#b71c1c;display:block}
|
||
.toast.success{background:#e6f9ed;color:#1a7a3a;display:block}
|
||
|
||
/* ===== 排程弹窗(铺满、宽屏、多列)===== */
|
||
.modal-overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.4);z-index:999;justify-content:center;align-items:center;padding:24px}
|
||
body.with-sidebar:not(.sidebar-collapsed) .modal-overlay{padding-left:240px}
|
||
body.with-sidebar.sidebar-collapsed .modal-overlay{padding-left:60px}
|
||
.modal-overlay.show{display:flex}
|
||
.modal{background:#fff;border-radius:10px;width:1200px;max-width:96vw;height:88vh;display:flex;flex-direction:column;box-shadow:0 20px 60px rgba(0,0,0,.2);overflow:hidden}
|
||
.modal-header{padding:18px 24px;border-bottom:1px solid #e2e8f0;background:linear-gradient(135deg,#f8fafc,#f1f5f9);display:flex;align-items:center;justify-content:space-between;flex-shrink:0}
|
||
.modal-header h3{font-size:17px;color:#0f172a;font-weight:600;letter-spacing:.5px}
|
||
.modal-close{background:transparent;border:none;font-size:20px;color:#94a3b8;cursor:pointer;padding:4px 8px;line-height:1}
|
||
.modal-close:hover{color:#ef4444}
|
||
.modal-body{padding:20px 24px;flex:1;overflow-y:auto}
|
||
.modal-footer{padding:14px 24px;border-top:1px solid #e2e8f0;background:#f8fafc;display:flex;justify-content:flex-end;gap:8px;flex-shrink:0}
|
||
.form-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:16px}
|
||
.form-group{display:flex;flex-direction:column}
|
||
.form-group.full{grid-column:1/-1}
|
||
.form-group label{font-size:12px;color:#475569;font-weight:600;margin-bottom:6px}
|
||
.form-group label .req{color:#ef4444;margin-left:2px}
|
||
.form-group input,.form-group select{height:36px;padding:0 12px;border:2px solid #e2e8f0;border-radius:6px;font-size:13px;outline:none;background:#fff;transition:all .15s}
|
||
.form-group input:focus,.form-group select:focus{border-color:#3b82f6;box-shadow:0 0 0 3px rgba(59,130,246,.1)}
|
||
.form-group input.readonly{background:#f1f5f9;color:#64748b;cursor:not-allowed}
|
||
.form-group input[readonly]{background:#f1f5f9;color:#64748b}
|
||
.input-with-picker{position:relative}
|
||
.input-with-picker input{padding-right:34px;cursor:pointer}
|
||
.input-with-picker .picker-btn{position:absolute;right:6px;top:50%;transform:translateY(-50%);width:24px;height:24px;border:none;background:transparent;color:#94a3b8;cursor:pointer;font-size:14px;display:flex;align-items:center;justify-content:center;border-radius:4px}
|
||
.input-with-picker .picker-btn:hover{background:#f1f5f9;color:#1a73e8}
|
||
.section-divider{margin:24px 0 16px;padding:8px 12px;background:linear-gradient(90deg,#eff6ff,transparent);border-left:3px solid #3b82f6;color:#1e40af;font-size:13px;font-weight:600;border-radius:0 4px 4px 0}
|
||
|
||
/* 每日生产计划表 */
|
||
.daily-table{width:100%;border-collapse:collapse;font-size:12px;background:#fff;border-radius:6px;overflow:hidden}
|
||
.daily-table th{background:#f1f5f9;padding:8px 6px;border-bottom:1px solid #e2e8f0;font-weight:600;color:#64748b;white-space:nowrap}
|
||
.daily-table td{padding:6px;border-bottom:1px solid #f1f5f9;text-align:center}
|
||
.daily-table .weekend{background:#fafbfc;color:#cbd5e1}
|
||
.daily-table .weekend input{background:#fafbfc;color:#cbd5e1}
|
||
.daily-table input{width:90%;text-align:right;border:1px solid #e2e8f0;border-radius:4px;padding:5px 8px;font-size:12px;outline:none}
|
||
.daily-table input:focus{border-color:#3b82f6;box-shadow:0 0 0 2px rgba(59,130,246,.1)}
|
||
.daily-table tr:hover{background:#f8fafc}
|
||
.daily-scroll{overflow-x:auto;max-height:340px;border:1px solid #e2e8f0;border-radius:6px}
|
||
|
||
/* ===== 物料查询弹窗(仿金蝶) ===== */
|
||
#materialPicker{z-index:1100}
|
||
.picker-modal{width:1100px;max-width:95vw;height:80vh}
|
||
.picker-toolbar{padding:10px 16px;background:#f8fafc;border-bottom:1px solid #e2e8f0;display:flex;gap:10px;align-items:center;flex-shrink:0}
|
||
.picker-toolbar select,.picker-toolbar input{height:30px;padding:0 10px;border:1px solid #d1d5db;border-radius:4px;font-size:12px;outline:none;min-width:130px}
|
||
.picker-toolbar input{min-width:180px}
|
||
.picker-toolbar label{font-size:12px;color:#475569;margin-right:4px}
|
||
.picker-toolbar .cond-row{display:flex;gap:6px;align-items:center;margin-right:12px}
|
||
.picker-toolbar .remove-cond{color:#ef4444;background:transparent;border:none;cursor:pointer;font-size:14px;padding:0 4px;line-height:1}
|
||
.picker-toolbar .actions{margin-left:auto;display:flex;gap:8px}
|
||
.picker-toolbar .btn{height:30px;padding:0 14px;font-size:12px;border-radius:4px}
|
||
.picker-table-wrap{flex:1;overflow:auto}
|
||
.picker-table{width:100%;border-collapse:collapse;font-size:13px}
|
||
.picker-table thead th{position:sticky;top:0;z-index:1;background:#f1f5f9;color:#475569;font-weight:600;padding:9px 10px;text-align:left;border-bottom:2px solid #cbd5e1;white-space:nowrap}
|
||
.picker-table tbody td{padding:7px 10px;border-bottom:1px solid #f1f5f9;color:#334155}
|
||
.picker-table tbody tr:hover{background:#eff6ff;cursor:pointer}
|
||
.picker-table tbody tr.selected{background:#dbeafe}
|
||
.picker-table .col-check{width:36px;text-align:center}
|
||
.picker-table .filter-input{width:100%;padding:3px 6px;border:1px solid #e2e8f0;border-radius:3px;font-size:11px;margin-top:3px;outline:none}
|
||
.picker-table .filter-input:focus{border-color:#3b82f6}
|
||
.picker-pagination{padding:8px 16px;background:#f8fafc;border-top:1px solid #e2e8f0;display:flex;justify-content:space-between;align-items:center;font-size:12px;color:#64748b;flex-shrink:0}
|
||
.picker-pagination .pages{display:flex;gap:4px}
|
||
.picker-pagination .pages button{min-width:26px;height:26px;border:1px solid #d1d5db;background:#fff;border-radius:3px;cursor:pointer;font-size:12px;color:#475569}
|
||
.picker-pagination .pages button.active{background:#3b82f6;color:#fff;border-color:#3b82f6}
|
||
.picker-pagination .pages button:hover:not(.active){border-color:#3b82f6;color:#3b82f6}
|
||
/* 列表分页 */
|
||
.pagination{display:flex;justify-content:space-between;align-items:center;padding:10px 4px;border-top:1px solid #f0f0f0;font-size:12px;color:#666}
|
||
.pagination .btns{display:flex;gap:2px;flex-wrap:wrap}
|
||
.pagination .btns button,.pagination .size-btn{min-width:30px;height:26px;border:1px solid #e0e0e0;border-radius:4px;background:#fff;color:#555;cursor:pointer;font-size:12px;padding:0 8px}
|
||
.pagination .btns button:hover,.pagination .size-btn:hover{border-color:#1a73e8;color:#1a73e8}
|
||
.pagination .btns button.active,.pagination .size-btn.active{background:#1a73e8;color:#fff;border-color:#1a73e8}
|
||
.pagination .size-group{display:inline-flex;gap:2px;margin-left:8px}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div id="sidebar"></div>
|
||
|
||
<div class="main-content">
|
||
<div class="panel">
|
||
<h3>生产计划排程 - 维护</h3>
|
||
<div class="toolbar">
|
||
<select id="selProduct" style="min-width:120px"><option value="">产品编码:全部</option></select>
|
||
<select id="selVersion" style="min-width:100px"><option value="">BOM版本:全部</option></select>
|
||
<select id="selProductType" style="min-width:120px"><option value="">产品类型:全部</option></select>
|
||
<select id="selStatus" style="min-width:100px">
|
||
<option value="">状态:全部</option>
|
||
<option value="待开始">待开始</option>
|
||
<option value="进行中">进行中</option>
|
||
<option value="已完成">已完成</option>
|
||
<option value="已暂停">已暂停</option>
|
||
</select>
|
||
<input type="text" id="txtKeyword" placeholder="搜索 产品编码 / 产品名称" style="width:200px">
|
||
<button class="btn btn-primary" onclick="searchList()">查询</button>
|
||
<button class="btn btn-outline" onclick="resetSearch()">重置</button>
|
||
<div style="flex:1"></div>
|
||
<button class="btn btn-outline" onclick="downloadTemplate()">📄 下载导入模板</button>
|
||
<button class="btn btn-green" onclick="triggerImport()">📥 导入Excel</button>
|
||
<button class="btn btn-primary" onclick="openAddModal()">+ 新建排程任务</button>
|
||
</div>
|
||
<div class="table-wrap">
|
||
<div class="batch-bar" id="batchBar" style="display:none">
|
||
<span>已选中 <b id="selCount">0</b> 项</span>
|
||
<button class="btn btn-red" onclick="delSelected()">🗑 删除选中</button>
|
||
<button class="btn btn-outline" onclick="clearSelection()">取消选择</button>
|
||
</div>
|
||
<table>
|
||
<thead>
|
||
<tr>
|
||
<th class="col-num">序号</th>
|
||
<th class="col-check"><input type="checkbox" id="chkAll" onchange="toggleCheckAllRows(this.checked)"></th>
|
||
<th class="col-op">操作</th>
|
||
<th>产品编码</th><th>BOM版本</th><th>产品名称</th><th>产品类型</th>
|
||
<th>工厂</th><th>区域</th><th>国家</th>
|
||
<th>计划开始日</th><th>计划完成日</th><th>总产量</th><th>状态</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="tbodyList"></tbody>
|
||
</table>
|
||
</div>
|
||
<div class="pagination" id="pagination" style="display:none">
|
||
<div><span>共 <em id="totalCnt">0</em> 条</span><span class="size-group" id="sizeBtns"></span></div>
|
||
<div class="btns" id="pageBtns"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 排程编辑弹窗 -->
|
||
<div class="modal-overlay" id="editModal">
|
||
<div class="modal">
|
||
<div class="modal-header">
|
||
<h3 id="modalTitle">新建排程任务</h3>
|
||
<button class="modal-close" onclick="closeModal('editModal')">×</button>
|
||
</div>
|
||
<div class="modal-body">
|
||
<div class="form-grid">
|
||
<div class="form-group">
|
||
<label>产品编码 <span class="req">*</span></label>
|
||
<div class="input-with-picker">
|
||
<input type="text" id="fProductCode" placeholder="点击右侧图标选择产品" readonly>
|
||
<button type="button" class="picker-btn" onclick="openMaterialPicker()" title="选择产品">🔍</button>
|
||
</div>
|
||
</div>
|
||
<div class="form-group">
|
||
<label>BOM版本 <span class="req">*</span></label>
|
||
<input type="text" id="fBOMVersion" placeholder="选产品后自动带出,无BOM版本可手动输入">
|
||
</div>
|
||
<div class="form-group">
|
||
<label>产品名称</label>
|
||
<input type="text" id="fProductName" class="readonly" readonly>
|
||
</div>
|
||
<div class="form-group">
|
||
<label>产品类型</label>
|
||
<input type="text" id="fProductType" placeholder="如:标准机 / 定制机 / 样机(人为维护)">
|
||
</div>
|
||
<div class="form-group">
|
||
<label>工厂</label>
|
||
<input type="text" id="fFactory" placeholder="工厂">
|
||
</div>
|
||
<div class="form-group">
|
||
<label>区域</label>
|
||
<input type="text" id="fRegion" placeholder="区域">
|
||
</div>
|
||
<div class="form-group">
|
||
<label>国家</label>
|
||
<input type="text" id="fCountry" placeholder="国家">
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label>计划开始日 <span class="req">*</span></label>
|
||
<input type="date" id="fPlanStart" onchange="genDaily()">
|
||
</div>
|
||
<div class="form-group">
|
||
<label>计划完成日 <span class="req">*</span></label>
|
||
<input type="date" id="fPlanEnd" onchange="genDaily()">
|
||
</div>
|
||
<div class="form-group">
|
||
<label>状态 <span class="req">*</span></label>
|
||
<select id="fStatus">
|
||
<option value="待开始">待开始</option>
|
||
<option value="进行中" selected>进行中</option>
|
||
<option value="已完成">已完成</option>
|
||
<option value="已暂停">已暂停</option>
|
||
</select>
|
||
</div>
|
||
<div class="form-group">
|
||
<label>备注</label>
|
||
<input type="text" id="fRemark" placeholder="排程调整原因...">
|
||
</div>
|
||
</div>
|
||
<div class="section-divider">每日生产计划(计划人员只维护成品每日产量,周末自动标记无产量)</div>
|
||
<div class="daily-scroll">
|
||
<table class="daily-table" id="dailyTable">
|
||
<thead id="dailyHeader"><tr><th>日期</th><th>星期</th><th>日产量</th></tr></thead>
|
||
<tbody id="dailyBody"></tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
<div class="modal-footer">
|
||
<button class="btn btn-outline" onclick="closeModal('editModal')">取消</button>
|
||
<button class="btn btn-primary" onclick="saveSchedule()">保存</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 物料查询弹窗(仿金蝶数据查询) -->
|
||
<div class="modal-overlay" id="materialPicker">
|
||
<div class="modal picker-modal">
|
||
<div class="modal-header">
|
||
<h3>📋 物料查询(数据查询)</h3>
|
||
<button class="modal-close" onclick="closeModal('materialPicker')">×</button>
|
||
</div>
|
||
<div class="picker-toolbar">
|
||
<div class="cond-row">
|
||
<label>物料代码</label>
|
||
<select id="pkCodeOp" style="width:90px">
|
||
<option>包含</option><option>不包含</option><option>等于</option><option>不等于</option><option>开始于</option><option>结束于</option><option>为空</option><option>不为空</option>
|
||
</select>
|
||
<input type="text" id="pkCodeVal" placeholder="输入物料代码" style="min-width:160px">
|
||
</div>
|
||
<div class="cond-row">
|
||
<label>物料名称</label>
|
||
<select id="pkNameOp" style="width:90px">
|
||
<option>包含</option><option>不包含</option><option>等于</option><option>不等于</option><option>开始于</option><option>结束于</option><option>为空</option><option>不为空</option>
|
||
</select>
|
||
<input type="text" id="pkNameVal" placeholder="输入物料名称" style="min-width:160px">
|
||
</div>
|
||
<div class="actions">
|
||
<button class="btn btn-primary" onclick="doSearch()">🔍 搜索</button>
|
||
<button class="btn btn-outline" onclick="resetSearchPK()">重置</button>
|
||
<button class="btn btn-green" onclick="addSelectedMaterial()">添加</button>
|
||
</div>
|
||
</div>
|
||
<div class="picker-table-wrap">
|
||
<table class="picker-table">
|
||
<thead>
|
||
<tr>
|
||
<th class="col-check"><input type="checkbox" id="pkCheckAll" onchange="toggleCheckAll(this.checked)"></th>
|
||
<th>物料代码 <input class="filter-input" id="pkFilterCode" oninput="doSearch()"></th>
|
||
<th>物料名称 <input class="filter-input" id="pkFilterName" oninput="doSearch()"></th>
|
||
<th>规格型号 <input class="filter-input" id="pkFilterSpec" oninput="doSearch()"></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody id="pkBody"></tbody>
|
||
</table>
|
||
</div>
|
||
<div class="picker-pagination">
|
||
<span>共 <span id="pkTotal">0</span> 条 每页 <span id="pkPageSize">2000</span> 条</span>
|
||
<div class="pages" id="pkPages"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="toast" id="toast"></div>
|
||
<script>
|
||
var curId=0;
|
||
var options=null;
|
||
var dailyData=[];
|
||
var pkPage=1, pkPageSize=2000;
|
||
var pkTotal=0;
|
||
var selectedMaterial=null; // {code, name, spec, bomVersion}
|
||
var curPage=1, pageSize=20, totalCnt=0;
|
||
var pageSizeOptions=[20,50,100,200];
|
||
|
||
function toast(msg,tp){var el=document.getElementById('toast');el.textContent=msg;el.className='toast '+tp;clearTimeout(el._timer);el._timer=setTimeout(function(){el.className='toast'},3000)}
|
||
function api(url,method,data,cb){
|
||
var opts={method:method||'GET',headers:{'Content-Type':'application/json'}};
|
||
if(data)opts.body=JSON.stringify(data);
|
||
fetch(url,opts).then(function(r){return r.json()}).then(function(res){
|
||
if(res&&res.success===false){toast(res.message||'操作失败','error');return}
|
||
cb&&cb(res);
|
||
}).catch(function(e){toast('请求失败:'+e.message,'error')});
|
||
}
|
||
function getApiUrl(){return '../../api/deliver/'}
|
||
|
||
function loadOptions(cb){
|
||
api(getApiUrl()+'GetOptions','GET',null,function(res){
|
||
options=res.data||{};
|
||
var h='<option value="">产品编码:全部</option>';
|
||
(options.products||[]).forEach(function(p){h+='<option value="'+p+'">'+p+'</option>'});
|
||
document.getElementById('selProduct').innerHTML=h;
|
||
var h2='<option value="">BOM版本:全部</option>';
|
||
(options.versions||[]).forEach(function(v){h2+='<option value="'+v+'">'+v+'</option>'});
|
||
document.getElementById('selVersion').innerHTML=h2;
|
||
var h3='<option value="">产品类型:全部</option>';
|
||
(options.productTypes||[]).forEach(function(t){h3+='<option value="'+t+'">'+t+'</option>'});
|
||
document.getElementById('selProductType').innerHTML=h3;
|
||
cb&&cb();
|
||
});
|
||
}
|
||
|
||
function searchList(){curPage=1;loadList()}
|
||
|
||
function loadList(){
|
||
var p=document.getElementById('selProduct').value;
|
||
var v=document.getElementById('selVersion').value;
|
||
var t=document.getElementById('selProductType').value;
|
||
var s=document.getElementById('selStatus').value;
|
||
var kw=document.getElementById('txtKeyword').value.trim();
|
||
var url=getApiUrl()+'GetScheduleList?productCode='+encodeURIComponent(p)+'&bomVersion='+encodeURIComponent(v)+'&productType='+encodeURIComponent(t)+'&status='+encodeURIComponent(s)+'&keyword='+encodeURIComponent(kw)+'&page='+curPage+'&pageSize='+pageSize;
|
||
api(url,'GET',null,function(res){
|
||
var rows=res.data||[];
|
||
totalCnt=res.total||0;
|
||
var html='';
|
||
if(rows.length===0)html='<tr><td colspan="14" style="text-align:center;padding:36px;color:#bbb">暂无数据</td></tr>';
|
||
rows.forEach(function(r,idx){
|
||
var stClass=r.Status=='进行中'?'badge-success':(r.Status=='待开始'?'badge-warning':(r.Status=='已完成'?'badge-info':'badge-muted'));
|
||
var rowNo=(curPage-1)*pageSize+idx+1;
|
||
html+='<tr data-id="'+r.Id+'" onclick="openEdit('+r.Id+')">'+
|
||
'<td class="col-num">'+rowNo+'</td>'+
|
||
'<td class="col-check" onclick="event.stopPropagation()"><input type="checkbox" class="rowChk" onchange="updateSelCount()"></td>'+
|
||
'<td class="col-op" style="white-space:nowrap" onclick="event.stopPropagation()">'+
|
||
'<button class="btn btn-blue" style="height:26px;padding:0 10px;font-size:11px" onclick="recalc('+r.Id+')">重算需求</button>'+
|
||
'</td>'+
|
||
'<td>'+r.ProductCode+'</td>'+
|
||
'<td><span class="badge badge-info">'+r.BOMVersion+'</span></td>'+
|
||
'<td>'+r.ProductName+'</td>'+
|
||
'<td>'+(r.ProductType||'')+'</td>'+
|
||
'<td>'+(r.Factory||'')+'</td>'+
|
||
'<td>'+(r.Region||'')+'</td>'+
|
||
'<td>'+(r.Country||'')+'</td>'+
|
||
'<td>'+r.PlanStartDate+'</td>'+
|
||
'<td>'+r.PlanEndDate+'</td>'+
|
||
'<td>'+r.TotalOutput+'</td>'+
|
||
'<td><span class="badge '+stClass+'">'+r.Status+'</span></td>'+
|
||
'</tr>';
|
||
});
|
||
document.getElementById('tbodyList').innerHTML=html;
|
||
renderPagination();
|
||
});
|
||
}
|
||
|
||
function resetSearch(){
|
||
document.getElementById('selProduct').value='';
|
||
document.getElementById('selVersion').value='';
|
||
document.getElementById('selProductType').value='';
|
||
document.getElementById('selStatus').value='';
|
||
document.getElementById('txtKeyword').value='';
|
||
curPage=1;
|
||
loadList();
|
||
}
|
||
|
||
// ===== 列表分页 =====
|
||
function renderPagination(){
|
||
var tp=Math.ceil(totalCnt/pageSize)||1;
|
||
var pc=document.getElementById('pagination');
|
||
if(totalCnt<=pageSize){pc.style.display='none';return}
|
||
pc.style.display='flex';
|
||
document.getElementById('totalCnt').textContent=totalCnt;
|
||
document.getElementById('sizeBtns').innerHTML=pageSizeOptions.map(function(s){return '<button class="size-btn'+(s===pageSize?' active':'')+'" onclick="setPageSize('+s+')">'+s+'条</button>'}).join('');
|
||
var pb=document.getElementById('pageBtns');
|
||
if(tp<=1){pb.innerHTML='';return}
|
||
var h='<button '+(curPage<=1?'disabled':'')+' onclick="goPage(1)">首页</button><button '+(curPage<=1?'disabled':'')+' onclick="goPage('+(curPage-1)+')">‹</button>';
|
||
for(var i=Math.max(1,curPage-2);i<=Math.min(tp,curPage+2);i++)h+='<button class="'+(i===curPage?'active':'')+'" onclick="goPage('+i+')">'+i+'</button>';
|
||
h+='<button '+(curPage>=tp?'disabled':'')+' onclick="goPage('+(curPage+1)+')">›</button><button '+(curPage>=tp?'disabled':'')+' onclick="goPage('+tp+')">末页</button>';
|
||
pb.innerHTML=h;
|
||
}
|
||
function goPage(p){
|
||
if(p<1||p>Math.ceil(totalCnt/pageSize))return;
|
||
curPage=p;
|
||
loadList();
|
||
}
|
||
function setPageSize(s){
|
||
pageSize=s;curPage=1;loadList();
|
||
}
|
||
|
||
function openAddModal(){
|
||
curId=0;
|
||
document.getElementById('modalTitle').textContent='新建排程任务';
|
||
document.getElementById('fProductCode').value='';
|
||
document.getElementById('fBOMVersion').value='';
|
||
document.getElementById('fProductName').value='';
|
||
document.getElementById('fProductType').value='';
|
||
document.getElementById('fFactory').value='';
|
||
document.getElementById('fRegion').value='';
|
||
document.getElementById('fCountry').value='';
|
||
document.getElementById('fPlanStart').value='';
|
||
document.getElementById('fPlanEnd').value='';
|
||
document.getElementById('fStatus').value='进行中';
|
||
document.getElementById('fRemark').value='';
|
||
selectedMaterial=null;
|
||
dailyData=[];
|
||
renderDaily();
|
||
document.getElementById('editModal').classList.add('show');
|
||
}
|
||
|
||
// 打开物料查询弹窗
|
||
function openMaterialPicker(){
|
||
pkPage=1;
|
||
document.getElementById('materialPicker').classList.add('show');
|
||
doSearch();
|
||
}
|
||
|
||
// 重置查询条件
|
||
function resetSearchPK(){
|
||
document.getElementById('pkCodeOp').value='包含';
|
||
document.getElementById('pkCodeVal').value='';
|
||
document.getElementById('pkNameOp').value='包含';
|
||
document.getElementById('pkNameVal').value='';
|
||
document.getElementById('pkFilterCode').value='';
|
||
document.getElementById('pkFilterName').value='';
|
||
document.getElementById('pkFilterSpec').value='';
|
||
document.getElementById('pkCheckAll').checked=false;
|
||
pkPage=1;
|
||
doSearch();
|
||
}
|
||
|
||
// 搜索物料
|
||
function doSearch(){
|
||
var codeOp=encodeURIComponent(document.getElementById('pkCodeOp').value);
|
||
var codeVal=document.getElementById('pkCodeVal').value.trim();
|
||
var nameOp=encodeURIComponent(document.getElementById('pkNameOp').value);
|
||
var nameVal=document.getElementById('pkNameVal').value.trim();
|
||
// 列表内过滤(叠加在服务器条件之上)
|
||
var fc=document.getElementById('pkFilterCode').value.trim().toLowerCase();
|
||
var fn=document.getElementById('pkFilterName').value.trim().toLowerCase();
|
||
var fs=document.getElementById('pkFilterSpec').value.trim().toLowerCase();
|
||
var url=getApiUrl()+'GetKingdeeMaterials?codeOp='+codeOp+'&codeVal='+encodeURIComponent(codeVal)+'&nameOp='+nameOp+'&nameVal='+encodeURIComponent(nameVal)+'&page='+pkPage+'&pageSize='+pkPageSize;
|
||
api(url,'GET',null,function(res){
|
||
var rows=res.data||[];
|
||
var html='';
|
||
rows.forEach(function(m){
|
||
if(fc && (m.code||'').toLowerCase().indexOf(fc)<0)return;
|
||
if(fn && (m.name||'').toLowerCase().indexOf(fn)<0)return;
|
||
if(fs && (m.spec||'').toLowerCase().indexOf(fs)<0)return;
|
||
html+='<tr onclick="selectMaterialRow(this)" data-code="'+m.code+'" data-name="'+m.name+'" data-spec="'+(m.spec||'')+'" data-bom="'+m.bomVersion+'">'+
|
||
'<td class="col-check"><input type="checkbox" class="pkChk"></td>'+
|
||
'<td>'+m.code+'</td>'+
|
||
'<td>'+m.name+'</td>'+
|
||
'<td>'+(m.spec||'')+'</td>'+
|
||
'</tr>';
|
||
});
|
||
if(!html)html='<tr><td colspan="4" style="text-align:center;padding:30px;color:#bbb">暂无数据</td></tr>';
|
||
document.getElementById('pkBody').innerHTML=html;
|
||
pkTotal=res.total||0;
|
||
document.getElementById('pkTotal').textContent=pkTotal;
|
||
document.getElementById('pkPageSize').textContent=res.pageSize||pkPageSize;
|
||
renderPkPages(pkTotal,res.page||pkPage,res.pageSize||pkPageSize);
|
||
});
|
||
}
|
||
|
||
function renderPkPages(total,page,pageSize){
|
||
var pages=Math.ceil(total/pageSize);
|
||
var h='<button onclick="pkGoto('+(page-1)+')" '+(page<=1?'disabled':'')+'>‹</button>';
|
||
for(var i=1;i<=Math.min(pages,10);i++){
|
||
h+='<button class="'+(i==page?'active':'')+'" onclick="pkGoto('+i+')">'+i+'</button>';
|
||
}
|
||
if(pages>10)h+='<span style="padding:0 4px;">...</span><button class="'+(pages==page?'active':'')+'" onclick="pkGoto('+pages+')">'+pages+'</button>';
|
||
h+='<button onclick="pkGoto('+(page+1)+')" '+(page>=pages?'disabled':'')+'>›</button>';
|
||
document.getElementById('pkPages').innerHTML=h;
|
||
}
|
||
|
||
function pkGoto(p){
|
||
if(p<1)return;
|
||
var pages=Math.ceil(pkTotal/pkPageSize);
|
||
if(p>pages)return;
|
||
pkPage=p;
|
||
doSearch();
|
||
}
|
||
|
||
function toggleCheckAll(checked){
|
||
var cks=document.querySelectorAll('.pkChk');
|
||
for(var i=0;i<cks.length;i++)cks[i].checked=checked;
|
||
}
|
||
|
||
function selectMaterialRow(tr){
|
||
var cks=document.querySelectorAll('.pkChk');
|
||
cks.forEach(function(c){c.checked=false;});
|
||
cks.forEach(function(c){if(c.parentElement.parentElement===tr)c.checked=true;});
|
||
var chk=tr.querySelector('.pkChk');
|
||
if(chk)chk.checked=true;
|
||
document.querySelectorAll('.picker-table tbody tr').forEach(function(r){r.classList.remove('selected');});
|
||
tr.classList.add('selected');
|
||
// 双击行直接添加(提升体验)
|
||
// 单击选中,多选/添加走按钮
|
||
}
|
||
|
||
function addSelectedMaterial(){
|
||
var chks=document.querySelectorAll('.pkChk:checked');
|
||
if(chks.length===0){toast('请先勾选一条物料','error');return}
|
||
if(chks.length>1){toast('每次只能选择一个产品','error');return}
|
||
var tr=chks[0].parentElement.parentElement;
|
||
selectedMaterial={
|
||
code:tr.getAttribute('data-code'),
|
||
name:tr.getAttribute('data-name'),
|
||
spec:tr.getAttribute('data-spec'),
|
||
bomVersion:tr.getAttribute('data-bom')||''
|
||
};
|
||
// 回填到排程表单
|
||
document.getElementById('fProductCode').value=selectedMaterial.code;
|
||
document.getElementById('fBOMVersion').value=selectedMaterial.bomVersion;
|
||
document.getElementById('fProductName').value=selectedMaterial.name;
|
||
closeModal('materialPicker');
|
||
toast('已选择产品:'+selectedMaterial.code+(selectedMaterial.bomVersion?('(BOM版本:'+selectedMaterial.bomVersion+')'):''),'success');
|
||
}
|
||
|
||
function openEdit(id){
|
||
api(getApiUrl()+'GetScheduleDetail?id='+id,'GET',null,function(res){
|
||
if(!res.success||!res.data){toast('未找到记录','error');return}
|
||
var d=res.data;
|
||
curId=d.Id;
|
||
document.getElementById('modalTitle').textContent='编辑排程任务 - '+d.ProductCode;
|
||
document.getElementById('fProductCode').value=d.ProductCode||'';
|
||
document.getElementById('fBOMVersion').value=d.BOMVersion||'';
|
||
document.getElementById('fProductName').value=d.ProductName||'';
|
||
document.getElementById('fProductType').value=d.ProductType||'';
|
||
document.getElementById('fFactory').value=d.Factory||'';
|
||
document.getElementById('fRegion').value=d.Region||'';
|
||
document.getElementById('fCountry').value=d.Country||'';
|
||
document.getElementById('fPlanStart').value=d.PlanStartDate||'';
|
||
document.getElementById('fPlanEnd').value=d.PlanEndDate||'';
|
||
document.getElementById('fStatus').value=d.Status||'待开始';
|
||
document.getElementById('fRemark').value=d.Remark||'';
|
||
selectedMaterial={code:d.ProductCode,name:d.ProductName,bomVersion:d.BOMVersion};
|
||
dailyData=(d.daily||[]).map(function(x){return {date:x.PlanDate,output:x.DailyOutput||'0'}});
|
||
renderDaily();
|
||
document.getElementById('editModal').classList.add('show');
|
||
});
|
||
}
|
||
|
||
function genDaily(){
|
||
var start=document.getElementById('fPlanStart').value;
|
||
var end=document.getElementById('fPlanEnd').value;
|
||
if(!start||!end)return;
|
||
if(end<start){toast('计划完成日不能早于开始日','error');return}
|
||
var dates=[];
|
||
var cur=new Date(start);
|
||
var last=new Date(end);
|
||
while(cur<=last){
|
||
dates.push({date:formatDate(cur),output:''});
|
||
cur.setDate(cur.getDate()+1);
|
||
}
|
||
dailyData=dates;
|
||
renderDaily();
|
||
}
|
||
|
||
function formatDate(d){
|
||
var y=d.getFullYear(),m=('0'+(d.getMonth()+1)).slice(-2),dd=('0'+d.getDate()).slice(-2);
|
||
return y+'-'+m+'-'+dd;
|
||
}
|
||
|
||
function renderDaily(){
|
||
var header='<tr><th>日期</th><th>星期</th><th>日产量</th></tr>';
|
||
var body='';
|
||
dailyData.forEach(function(item,i){
|
||
var d=new Date(item.date);
|
||
var week=['日','一','二','三','四','五','六'][d.getDay()];
|
||
var isWeekend=(d.getDay()==0||d.getDay()==6);
|
||
var cls=isWeekend?'weekend':'';
|
||
body+='<tr class="'+cls+'">'+
|
||
'<td>'+item.date+'</td>'+
|
||
'<td>周'+week+'</td>'+
|
||
'<td><input type="number" data-idx="'+i+'" value="'+item.output+'" oninput="updateOutput(this)"></td>'+
|
||
'</tr>';
|
||
});
|
||
document.getElementById('dailyHeader').innerHTML=header;
|
||
document.getElementById('dailyBody').innerHTML=body;
|
||
}
|
||
|
||
function updateOutput(el){
|
||
var idx=el.getAttribute('data-idx');
|
||
dailyData[idx].output=el.value;
|
||
}
|
||
|
||
function saveSchedule(){
|
||
var data={
|
||
Id:curId,
|
||
ProductCode:document.getElementById('fProductCode').value.trim(),
|
||
BOMVersion:document.getElementById('fBOMVersion').value.trim(),
|
||
ProductName:document.getElementById('fProductName').value.trim(),
|
||
ProductType:document.getElementById('fProductType').value.trim(),
|
||
Factory:document.getElementById('fFactory').value.trim(),
|
||
Region:document.getElementById('fRegion').value.trim(),
|
||
Country:document.getElementById('fCountry').value.trim(),
|
||
PlanStartDate:document.getElementById('fPlanStart').value,
|
||
PlanEndDate:document.getElementById('fPlanEnd').value,
|
||
Status:document.getElementById('fStatus').value,
|
||
Remark:document.getElementById('fRemark').value,
|
||
CreateUser:(function(){try{var u=JSON.parse(sessionStorage.getItem('gx_user'));return u.userId||''}catch(e){return ''}})()
|
||
};
|
||
if(!data.ProductCode){toast('请先选择产品编码','error');return}
|
||
if(!data.BOMVersion){toast('所选产品没有BOM版本,请在物料查询中选择已建立BOM的物料','error');return}
|
||
if(!data.PlanStartDate||!data.PlanEndDate){toast('请选择计划开始日和完成日','error');return}
|
||
// 保存前从DOM同步最新输入值,确保oninput/onchange都能捕获
|
||
var inputs=document.querySelectorAll('#dailyBody input[type="number"]');
|
||
inputs.forEach(function(el){updateOutput(el)});
|
||
data.daily=dailyData.filter(function(x){return x.output&&parseFloat(x.output)>0}).map(function(x){return {PlanDate:x.date,DailyOutput:x.output}});
|
||
// 关闭按钮防止重复提交
|
||
var saveBtn=document.querySelector('.modal-footer .btn-primary');
|
||
if(saveBtn)saveBtn.disabled=true;
|
||
try{
|
||
api(getApiUrl()+'SaveSchedule','POST',data,function(res){
|
||
if(saveBtn)saveBtn.disabled=false;
|
||
if(res.success){toast('排程保存成功,已自动登记到BOM主数据','success');closeModal('editModal');loadList()}
|
||
});
|
||
}catch(e){if(saveBtn)saveBtn.disabled=false;}
|
||
}
|
||
|
||
// 下载导入模板
|
||
function downloadTemplate(){
|
||
var a=document.createElement('a');
|
||
a.href=getApiUrl()+'DownloadScheduleTemplate';
|
||
a.download='生产排程导入模板.xls';
|
||
a.style.display='none';
|
||
document.body.appendChild(a);
|
||
a.click();
|
||
setTimeout(function(){document.body.removeChild(a)},100);
|
||
}
|
||
|
||
function recalc(id){
|
||
if(!confirm('确认重新计算该排程的物料需求?'))return;
|
||
api(getApiUrl()+'RecalcSchedule','POST',{ScheduleId:id},function(res){
|
||
if(res.success){showRecalcProgress(id)}
|
||
else if(res.message&&res.message.indexOf('正在重算')>=0){showRecalcProgress(id)}
|
||
});
|
||
}
|
||
|
||
// 显示重算进度条并轮询后端进度
|
||
function showRecalcProgress(id){
|
||
var modal=document.getElementById('recalcModal');
|
||
if(!modal){
|
||
modal=document.createElement('div');
|
||
modal.id='recalcModal';
|
||
modal.style.cssText='position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.45);z-index:99999;display:none;align-items:center;justify-content:center;';
|
||
modal.innerHTML=
|
||
'<div style="background:#fff;border-radius:10px;padding:26px 32px;width:440px;box-shadow:0 8px 30px rgba(0,0,0,0.25);">'+
|
||
'<h4 style="margin:0 0 18px;font-size:16px;color:#303133;">物料需求重算中</h4>'+
|
||
'<div style="height:10px;background:#ebeef5;border-radius:5px;overflow:hidden;">'+
|
||
'<div id="recalcBar" style="height:100%;width:0%;background:linear-gradient(90deg,#409eff,#79bbff);border-radius:5px;transition:width 0.5s;"></div></div>'+
|
||
'<div style="margin-top:12px;font-size:13px;color:#606266;display:flex;justify-content:space-between;">'+
|
||
'<span id="recalcStage">准备中...</span><span id="recalcPercent" style="font-weight:bold;color:#409eff;">0%</span></div>'+
|
||
'<div id="recalcMsg" style="margin-top:10px;font-size:12px;color:#909399;"></div>'+
|
||
'</div>';
|
||
document.body.appendChild(modal);
|
||
}
|
||
modal.style.display='flex';
|
||
document.getElementById('recalcBar').style.width='0%';
|
||
document.getElementById('recalcPercent').textContent='0%';
|
||
document.getElementById('recalcStage').textContent='准备中...';
|
||
document.getElementById('recalcMsg').textContent='';
|
||
|
||
var timer=setInterval(function(){
|
||
fetch(getApiUrl()+'GetRecalcProgress?scheduleId='+id,{method:'GET'})
|
||
.then(function(r){return r.json()})
|
||
.then(function(res){
|
||
if(!res||res.success===false){clearInterval(timer);hideRecalcModal();toast((res&&res.message)||'获取进度失败','error');return;}
|
||
document.getElementById('recalcBar').style.width=res.percent+'%';
|
||
document.getElementById('recalcPercent').textContent=res.percent+'%';
|
||
document.getElementById('recalcStage').textContent=res.stage||'';
|
||
document.getElementById('recalcMsg').textContent=res.message||'';
|
||
if(res.status==='success'){
|
||
clearInterval(timer);
|
||
setTimeout(function(){hideRecalcModal();toast(res.message||'重算完成','success');loadList();},600);
|
||
}else if(res.status==='error'){
|
||
clearInterval(timer);
|
||
setTimeout(function(){hideRecalcModal();toast(res.message||'重算失败','error');},600);
|
||
}
|
||
})
|
||
.catch(function(e){clearInterval(timer);hideRecalcModal();toast('获取进度失败:'+e.message,'error');});
|
||
},1000);
|
||
}
|
||
|
||
function hideRecalcModal(){
|
||
var modal=document.getElementById('recalcModal');
|
||
if(modal)modal.style.display='none';
|
||
}
|
||
|
||
function delSchedule(id){
|
||
if(!confirm('确认删除该排程?相关需求明细将一并删除'))return;
|
||
api(getApiUrl()+'DeleteSchedule','POST',{Id:id},function(res){
|
||
if(res.success){toast('删除成功','success');loadList()}
|
||
});
|
||
}
|
||
|
||
// ===== 列表多选 / 批量删除 =====
|
||
function getCheckedIds(){
|
||
var ids=[];
|
||
document.querySelectorAll('#tbodyList .rowChk:checked').forEach(function(c){
|
||
var tr=c.closest('tr');
|
||
if(tr&&tr.dataset.id)ids.push(Number(tr.dataset.id));
|
||
});
|
||
return ids;
|
||
}
|
||
function toggleCheckAllRows(checked){
|
||
document.querySelectorAll('#tbodyList .rowChk').forEach(function(c){c.checked=checked;});
|
||
updateSelCount();
|
||
}
|
||
function updateSelCount(){
|
||
var ids=getCheckedIds();
|
||
var bar=document.getElementById('batchBar');
|
||
if(ids.length>0){
|
||
bar.style.display='flex';
|
||
document.getElementById('selCount').textContent=ids.length;
|
||
}else{
|
||
bar.style.display='none';
|
||
}
|
||
}
|
||
function clearSelection(){
|
||
document.querySelectorAll('#tbodyList .rowChk').forEach(function(c){c.checked=false;});
|
||
updateSelCount();
|
||
}
|
||
function delSelected(){
|
||
var ids=getCheckedIds();
|
||
if(ids.length===0){toast('请选择要删除的行','error');return}
|
||
if(!confirm('确认批量删除选中的 '+ids.length+' 条排程?'))return;
|
||
api(getApiUrl()+'DeleteSchedule','POST',{Ids:ids},function(res){
|
||
if(res.success){toast('批量删除完成','success');loadList()}
|
||
});
|
||
}
|
||
|
||
function triggerImport(){
|
||
var input=document.createElement('input');
|
||
input.type='file';
|
||
input.accept='.xls,.xlsx';
|
||
input.onchange=function(){
|
||
var file=input.files[0];
|
||
if(!file)return;
|
||
var reader=new FileReader();
|
||
reader.onload=function(){
|
||
var base64=reader.result.split(',')[1];
|
||
api(getApiUrl()+'ImportScheduleExcel','POST',{FileName:file.name,FileContent:base64},function(res){
|
||
if(res.success){toast(res.message,'success');loadList()}
|
||
});
|
||
};
|
||
reader.readAsDataURL(file);
|
||
};
|
||
input.click();
|
||
}
|
||
|
||
function closeModal(id){document.getElementById(id).classList.remove('show')}
|
||
|
||
loadOptions(function(){loadList()});
|
||
</script>
|
||
<!-- 公共侧边栏组件(菜单维护点:View/common/nav.js) -->
|
||
<script src="../common/nav.js"></script>
|
||
</body>
|
||
</html>
|