/** * need.js - 需求转盘逻辑(列表+筛选+分页 / 新增编辑 / 推送按钮) */ $(function () { renderShell('需求转盘', '业务模块 / 需求转盘'); renderPage(); initPage('need', function (user) { if (!checkPagePermission('need')) return; loadList(1); }); var currentPage = 1; /** 渲染页面内容(工具栏+表格+分页) */ function renderPage() { $('#page-content').html( '
' + '
' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '
' + '
' + ' ' + ' ' + '
ID公司行业联系人需求大类意向品类描述状态录入时间操作
' + ' ' + '
' ); $('#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 += '' + '' + '' + r.id + '' + '' + escHtml(r.display_name || '-') + '' + '' + escHtml(r.industry || '-') + '' + '' + escHtml(r.contact_person || '-') + '' + '' + escHtml(r.need_category || '-') + '' + '' + escHtml(r.target_product_category || '-') + '' + '' + escHtml((r.description || '-').substring(0, 30)) + '' + '' + (r.is_valid ? '有效' : '已作废') + '' + '' + fmtDate(r.created_at) + '' + '' + ' 详情' + ' 编辑' + ' 推送' + (r.is_valid ? ' 作废' : '') + ''; }); if (!rows.length) { html = '暂无数据'; } $('#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 = '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '' + '
'; 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 = '
' + '

需求 #' + n.id + '(' + escHtml(n.display_name || '-') + ')

' + '
' + '
行业:' + escHtml(n.industry || '-') + '
' + '
国家:' + escHtml(n.country || '-') + '
' + '
联系人:' + escHtml(n.contact_person || '-') + '
' + '
需求大类:' + escHtml(n.need_category || '-') + '
' + '
意向品类:' + escHtml(n.target_product_category || '-') + '
' + '
应用场景:' + escHtml(n.application_scenario || '-') + '
' + '
状态:' + (n.is_valid ? '有效' : '已作废') + '
' + '
录入时间:' + fmtDate(n.created_at) + '
' + '
' + '

详细描述

' + '
' + escHtml(n.description || '-') + '
' + '
访问官网
' + '
'; Dialog.open({ title: '需求详情', area: ['680px', 'auto'], content: html, btn: ['关闭'] }); }); } });