191 lines
10 KiB
JavaScript
191 lines
10 KiB
JavaScript
/**
|
||
* need.js - 需求转盘逻辑(列表+筛选+分页 / 新增编辑 / 推送按钮)
|
||
*/
|
||
$(function () {
|
||
renderShell('需求转盘', '业务模块 / 需求转盘');
|
||
renderPage();
|
||
initPage('need', function (user) {
|
||
if (!checkPagePermission('need')) return;
|
||
loadList(1);
|
||
});
|
||
|
||
var currentPage = 1;
|
||
|
||
/** 渲染页面内容(工具栏+表格+分页) */
|
||
function renderPage() {
|
||
$('#page-content').html(
|
||
'<div class="card">' +
|
||
' <div class="toolbar">' +
|
||
' <input type="text" data-filter="keyword" placeholder="描述/联系人/公司名关键词">' +
|
||
' <input type="text" data-filter="company_name" placeholder="公司名称">' +
|
||
' <input type="text" data-filter="industry" placeholder="行业(精确)">' +
|
||
' <input type="text" data-filter="need_category" placeholder="需求大类">' +
|
||
' <input type="date" data-filter="start_date" title="开始日期">' +
|
||
' <input type="date" data-filter="end_date" title="结束日期">' +
|
||
' <button class="btn btn-primary" id="btn-search">搜索</button>' +
|
||
' <button class="btn" id="btn-reset">重置</button>' +
|
||
' <span class="spacer"></span>' +
|
||
' <button class="btn btn-success" id="btn-add">+ 新增</button>' +
|
||
' <button class="btn btn-warning" id="btn-push-batch">批量推送</button>' +
|
||
' </div>' +
|
||
' <div class="table-wrap"><table class="grid">' +
|
||
' <thead><tr><th><input type="checkbox" id="check-all"></th><th>ID</th><th>公司</th><th>行业</th><th>联系人</th><th>需求大类</th><th>意向品类</th><th>描述</th><th>状态</th><th>录入时间</th><th>操作</th></tr></thead>' +
|
||
' <tbody id="need-tbody"></tbody>' +
|
||
' </table></div>' +
|
||
' <div class="pagination" id="pagination"></div>' +
|
||
'</div>'
|
||
);
|
||
$('#check-all').on('change', function () { $('.row-check').prop('checked', this.checked); });
|
||
}
|
||
|
||
function loadList(page) {
|
||
currentPage = page;
|
||
var params = buildFilterParam();
|
||
params.page = page;
|
||
params.limit = PAGE_SIZE;
|
||
|
||
httpGet('need/list.php', params).then(function (data) {
|
||
var rows = data.list || [];
|
||
var html = '';
|
||
rows.forEach(function (r) {
|
||
html += '<tr>' +
|
||
'<td><input type="checkbox" class="row-check" value="' + r.id + '"></td>' +
|
||
'<td>' + r.id + '</td>' +
|
||
'<td title="' + escHtml(r.display_name || '') + '">' + escHtml(r.display_name || '-') + '</td>' +
|
||
'<td>' + escHtml(r.industry || '-') + '</td>' +
|
||
'<td>' + escHtml(r.contact_person || '-') + '</td>' +
|
||
'<td>' + escHtml(r.need_category || '-') + '</td>' +
|
||
'<td>' + escHtml(r.target_product_category || '-') + '</td>' +
|
||
'<td title="' + escHtml(r.description || '') + '">' + escHtml((r.description || '-').substring(0, 30)) + '</td>' +
|
||
'<td>' + (r.is_valid ? '<span class="tag tag-green">有效</span>' : '<span class="tag tag-gray">已作废</span>') + '</td>' +
|
||
'<td>' + fmtDate(r.created_at) + '</td>' +
|
||
'<td class="ops">' +
|
||
' <a onclick="viewNeed(' + r.id + ')">详情</a>' +
|
||
' <a onclick="editNeed(' + r.id + ')">编辑</a>' +
|
||
' <a onclick="pushNeed(' + r.id + ')">推送</a>' +
|
||
(r.is_valid ? ' <a class="danger" onclick="delNeed(' + r.id + ')">作废</a>' : '') +
|
||
'</td></tr>';
|
||
});
|
||
if (!rows.length) {
|
||
html = '<tr><td colspan="11" class="empty-tip" style="padding:40px 0;">暂无数据</td></tr>';
|
||
}
|
||
$('#need-tbody').html(html);
|
||
renderPagination($('#pagination'), data, loadList);
|
||
});
|
||
}
|
||
|
||
$('#btn-search').on('click', function () { loadList(1); });
|
||
$('#btn-reset').on('click', function () {
|
||
$('.toolbar [data-filter]').val('');
|
||
loadList(1);
|
||
});
|
||
|
||
$('#btn-add').on('click', function () { openForm(null); });
|
||
window.editNeed = function (id) {
|
||
httpGet('need/detail.php', { id: id }).then(function (d) {
|
||
openForm(d.need);
|
||
});
|
||
};
|
||
|
||
function openForm(need) {
|
||
var isEdit = !!need;
|
||
var n = need || {};
|
||
var content =
|
||
'<form id="need-form" style="padding:18px 22px 4px;">' +
|
||
'<div class="form-grid">' +
|
||
' <div class="form-item full"><label>所属公司ID<span class="req">*</span></label><input type="number" name="company_id" value="' + escHtml(n.company_id) + '" ' + (isEdit ? 'disabled' : '') + ' placeholder="公司ID(如 1)"></div>' +
|
||
' <div class="form-item"><label>需求联系人</label><input type="text" name="contact_person" value="' + escHtml(n.contact_person) + '"></div>' +
|
||
' <div class="form-item"><label>需求大类</label><input type="text" name="need_category" value="' + escHtml(n.need_category) + '" placeholder="设备采购/原材料/咨询服务等"></div>' +
|
||
' <div class="form-item"><label>意向产品品类</label><input type="text" name="target_product_category" value="' + escHtml(n.target_product_category) + '"></div>' +
|
||
' <div class="form-item"><label>业务场景/应用工序</label><input type="text" name="application_scenario" value="' + escHtml(n.application_scenario) + '" placeholder="如:码垛、焊接"></div>' +
|
||
' <div class="form-item full"><label>详细需求描述</label><textarea name="description" style="min-height:100px;">' + escHtml(n.description) + '</textarea></div>' +
|
||
'</div>' +
|
||
'<div class="dialog-footer"><button type="button" class="btn" id="form-cancel">取消</button>' +
|
||
'<button type="submit" class="btn btn-primary">保存</button></div>' +
|
||
'</form>';
|
||
|
||
var idx = Dialog.open({
|
||
title: isEdit ? '编辑需求' : '新增需求',
|
||
area: ['680px', 'auto'],
|
||
content: content,
|
||
btn: false
|
||
});
|
||
|
||
$('#form-cancel').on('click', function () { Dialog.close(idx); });
|
||
|
||
$('#need-form').on('submit', function (e) {
|
||
e.preventDefault();
|
||
var data = {};
|
||
$(this).find('input, textarea').each(function () {
|
||
var name = $(this).attr('name');
|
||
if (!name) return;
|
||
if ($(this).attr('type') === 'number') {
|
||
data[name] = $(this).val() === '' ? '' : parseInt($(this).val(), 10);
|
||
} else {
|
||
data[name] = $(this).val();
|
||
}
|
||
});
|
||
if (!isEdit && !data.company_id) { Dialog.error('所属公司ID为必填项'); return; }
|
||
if (isEdit) data.id = n.id;
|
||
|
||
httpPost(isEdit ? 'need/update.php' : 'need/add.php', data).then(function () {
|
||
Dialog.success('保存成功', function () {
|
||
Dialog.close(idx);
|
||
loadList(currentPage);
|
||
});
|
||
});
|
||
});
|
||
}
|
||
|
||
window.delNeed = function (id) {
|
||
Dialog.confirm('确定作废该需求吗?', function () {
|
||
httpPost('need/delete.php', { id: id }).then(function () {
|
||
Dialog.success('操作成功', function () { loadList(currentPage); });
|
||
});
|
||
});
|
||
};
|
||
|
||
window.pushNeed = function (id) {
|
||
Dialog.confirm('确定推送该需求吗?(当前为占位实现)', function () {
|
||
httpPost('need/push.php', { id: id }).then(function (d) {
|
||
Dialog.alert(d.msg || '推送成功');
|
||
});
|
||
});
|
||
};
|
||
|
||
$('#btn-push-batch').on('click', function () {
|
||
var ids = [];
|
||
$('.row-check:checked').each(function () { ids.push($(this).val()); });
|
||
if (!ids.length) { Dialog.error('请先勾选记录'); return; }
|
||
Dialog.confirm('确定推送选中的 ' + ids.length + ' 条需求吗?(占位实现)', function () {
|
||
httpPost('need/push.php', { ids: ids.join(',') }).then(function (d) {
|
||
Dialog.alert(d.msg || '推送成功');
|
||
});
|
||
});
|
||
});
|
||
|
||
window.viewNeed = function (id) {
|
||
httpGet('need/detail.php', { id: id }).then(function (d) {
|
||
var n = d.need;
|
||
var html =
|
||
'<div style="padding:18px 22px;">' +
|
||
' <h3 style="margin-bottom:14px;">需求 #' + n.id + '(' + escHtml(n.display_name || '-') + ')</h3>' +
|
||
' <div style="display:grid;grid-template-columns:1fr 1fr;gap:8px 24px;font-size:13px;">' +
|
||
' <div><b>行业:</b>' + escHtml(n.industry || '-') + '</div>' +
|
||
' <div><b>国家:</b>' + escHtml(n.country || '-') + '</div>' +
|
||
' <div><b>联系人:</b>' + escHtml(n.contact_person || '-') + '</div>' +
|
||
' <div><b>需求大类:</b>' + escHtml(n.need_category || '-') + '</div>' +
|
||
' <div><b>意向品类:</b>' + escHtml(n.target_product_category || '-') + '</div>' +
|
||
' <div><b>应用场景:</b>' + escHtml(n.application_scenario || '-') + '</div>' +
|
||
' <div><b>状态:</b>' + (n.is_valid ? '有效' : '已作废') + '</div>' +
|
||
' <div><b>录入时间:</b>' + fmtDate(n.created_at) + '</div>' +
|
||
' </div>' +
|
||
' <h4 style="margin:16px 0 8px;">详细描述</h4>' +
|
||
' <div style="font-size:13px;color:#5a6472;white-space:pre-wrap;">' + escHtml(n.description || '-') + '</div>' +
|
||
' <div style="margin-top:16px;text-align:right;"><a href="' + escHtml(n.website || '#') + '" target="_blank" class="btn btn-sm" style="' + (n.website ? '' : 'display:none;') + '">访问官网</a></div>' +
|
||
'</div>';
|
||
Dialog.open({ title: '需求详情', area: ['680px', 'auto'], content: html, btn: ['关闭'] });
|
||
});
|
||
}
|
||
});
|