define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
/* 列表:Controller.index 内顺序执行。审核:Controller.review 内顺序执行。无其它本文件自定义函数。 */
var Controller = {
currYm: '',
index: function () {
var $layout = $('#procuremen-layout');
var table = $('#table');
var issuedOnlyCols = ['purchase_order_id'];
var pendingOnlyCols = ['po_detail_count', 'po_amount_fill_cnt', 'po_delivery_fill_cnt'];
var pickedOnlyCols = ['picked_supplier_name'];
var allOnlyCols = ['ID'];
Controller.currYm = ($layout.data('defaultYm') || '').toString();
Controller.wffTab = 'all';
Table.api.init({
extend: {
index_url: 'procuremen/index' + location.search,
multi_url: 'procuremen/multi',
import_url: 'procuremen/import',
table: 'scydgy',
}
});
$('.procuremen-ym-item').removeClass('active');
$('.procuremen-ym-item[data-ym="' + Controller.currYm + '"]').addClass('active');
$('.procuremen-wff-tabs').find('li').removeClass('active');
$('.procuremen-wff-tabs').find('a[data-wff="' + Controller.wffTab + '"]').parent().addClass('active');
$(document).off('click.procuremenWff', '.procuremen-wff-tabs a').on('click.procuremenWff', '.procuremen-wff-tabs a', function (e) {
e.preventDefault();
var t = $(this).data('wff');
if (!t || t === Controller.wffTab) {
return;
}
Controller.wffTab = t;
$('.procuremen-wff-tabs').find('li').removeClass('active');
$('.procuremen-wff-tabs').find('a[data-wff="' + Controller.wffTab + '"]').parent().addClass('active');
/* 先清空:否则 show/hideColumn 会立刻用上一状态的 data 重绘一行/多行,直到 refresh 返回才消失 */
try {
table.bootstrapTable('removeAll');
} catch (ignore) {
}
var issuedNow = Controller.wffTab === 'pending' || Controller.wffTab === 'done' || Controller.wffTab === 'picked';
issuedOnlyCols.forEach(function (field) {
try {
table.bootstrapTable(issuedNow ? 'showColumn' : 'hideColumn', field);
} catch (ignore) {
}
});
pendingOnlyCols.forEach(function (field) {
try {
table.bootstrapTable(Controller.wffTab === 'pending' ? 'showColumn' : 'hideColumn', field);
} catch (ignore) {
}
});
pickedOnlyCols.forEach(function (field) {
try {
table.bootstrapTable(Controller.wffTab === 'picked' ? 'showColumn' : 'hideColumn', field);
} catch (ignore) {
}
});
allOnlyCols.forEach(function (field) {
try {
table.bootstrapTable(issuedNow ? 'hideColumn' : 'showColumn', field);
} catch (ignore) {
}
});
table.bootstrapTable('refresh', {pageNumber: 1});
});
$(document).off('click.procuremenYm', '.procuremen-ym-item').on('click.procuremenYm', '.procuremen-ym-item', function () {
var ym = $(this).data('ym');
if (!ym || ym === Controller.currYm) {
return;
}
Controller.currYm = ym;
$('.procuremen-ym-item').removeClass('active');
$(this).addClass('active');
try {
table.bootstrapTable('removeAll');
} catch (ignore) {
}
table.bootstrapTable('refresh', {pageNumber: 1});
});
$(document).off('click.procuremenExportMonth', '#btn-export-month-outward').on('click.procuremenExportMonth', '#btn-export-month-outward', function () {
var ymDefault = (Controller.currYm || '').toString();
if (!/^\d{4}-\d{2}$/.test(ymDefault)) {
ymDefault = ($layout.data('defaultYm') || '').toString();
}
if (!/^\d{4}-\d{2}$/.test(ymDefault)) {
ymDefault = '';
}
if (!ymDefault) {
var d = new Date();
ymDefault = d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2);
}
var escYm = String(ymDefault == null ? '' : ymDefault).replace(/&/g, '&').replace(/"/g, '"').replace(//g, '>');
var html = ''
+ '
'
+ '
'
+ '默认与左侧当前月份一致,可选择导出其它月份的下发明细。'
+ '
'
+ '
'
+ ''
+ '
'
+ '
';
Layer.open({
type: 1,
title: '月份下发明细导出',
area: ['440px', 'auto'],
shadeClose: true,
content: html,
btn: ['导出明细'],
yes: function (index, layero) {
var v = (layero.find('#export-outward-ym-input').val() || '').trim();
if (!/^\d{4}-\d{2}$/.test(v)) {
Toastr.warning('请选择有效月份');
return;
}
Layer.close(index);
var url = Fast.api.fixurl('procuremen/export_month_outward?ym=' + encodeURIComponent(v));
setTimeout(function () {
window.open(url, '_blank');
}, 100);
}
});
});
table.on('post-header.bs.table', function () {
var $host = $('#procuremen-toolbar-host');
var $bt = table.closest('.bootstrap-table');
if (!$host.length || !$bt.length) {
return;
}
var $ft = $bt.children('.fixed-table-toolbar').first();
if (!$ft.length) {
$ft = $host.find('.fixed-table-toolbar').first();
}
if (!$ft.length) {
return;
}
if ($ft.parent()[0] !== $host[0]) {
$host.children('.fixed-table-toolbar').remove();
$host.append($ft);
var $src = $bt.closest('.procuremen-table-area').find('#toolbar').first();
if ($src.length && !$src.children().length) {
$src.addClass('procuremen-toolbar-empty');
}
}
$ft.find('.procuremen-toolbar-search-wrap').removeClass('procuremen-toolbar-search-wrap');
var $search = $ft.find('.search').first();
if (!$search.length) {
return;
}
var $right = $search.closest('.columns, .pull-right').first();
if (!$right.length || ($ft[0] && !$.contains($ft[0], $right[0]))) {
return;
}
$ft.children().each(function () {
var $c = $(this);
if ($c.is('.bars, .bs-bars') || $c[0] === $right[0]) {
return;
}
var mergeToolbarExtras = $c.hasClass('columns')
|| $c.hasClass('pull-right')
|| ($c.hasClass('btn-group') && $c.find('.search').length === 0);
if (!mergeToolbarExtras || $c.find('.search').length) {
return;
}
if ($c.hasClass('btn-group') && !$c.hasClass('columns')) {
$c.appendTo($right);
} else {
$c.children().appendTo($right);
if (!$c.children().length) {
$c.remove();
}
}
});
$ft.find('.search').first().prependTo($right);
$right.addClass('procuremen-toolbar-search-wrap');
});
var indexInitWffTab = Controller.wffTab;
var indexShowall = indexInitWffTab === 'all';
var indexShowIssued = indexInitWffTab === 'pending' || indexInitWffTab === 'done' || indexInitWffTab === 'picked';
var indexShowPendingOnly = indexInitWffTab === 'pending';
var indexShowPickedOnly = indexInitWffTab === 'picked';
function procuremenEscAttr(s) {
return String(s == null ? '' : s)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
var indexTableColumns = [
// {field: 'ID', title: __('ID'), operate: 'LIKE', table: 'a', width: 100, align: 'center',
// visible: indexShowall,
// formatter: function (v) {
// return v != null && v !== '' && String(v) !== '0' ? String(v) : '';
// }
// },
// {field: 'purchase_order_id',title: 'ID',operate: false,table: 'a',width: 88,align: 'center',
// visible: indexShowIssued,
// formatter: function (v) {
// return v != null && v !== '' && String(v) !== '0' ? String(v) : '';
// }
// },
{field: 'CCYDH', title: __('订单号'), operate: 'LIKE', table: 'b', width: 100, align: 'center'},
{field: 'CYJMC', title: __('印件名称'), operate: 'LIKE', table: 'b', width: 270, align: 'left'},
{field: 'CGYMC', title: __('工序名称'), operate: 'LIKE', table: 'a', width: 100, align: 'center'},
{field: 'CDW', title: __('单位'), operate: 'LIKE', table: 'a', width: 50, align: 'center'},
{field: 'NGZL', title: __('工作量'), operate: false, table: 'a', width: 80, align: 'center'},
{field: 'This_quantity', title: '本次数量', operate: false, table: 'a', width: 96, align: 'center',
visible: true,
formatter: function (v, row, index) {
var tab = Controller.wffTab || 'all';
if (tab === 'all') {
var val = (v != null && v !== '') ? String(v) : '';
return '';
}
return (v == null || v === '') ? '' : String(v);
}
},
{field: 'ceilingPrice', title: '最高限价', operate: false, table: 'a', width: 96, align: 'center',
visible: true,
formatter: function (value, row, index) {
var tab = Controller.wffTab || 'all';
var v = value;
if (v == null || v === '') {
v = (row && row.ceilingPrice != null && row.ceilingPrice !== '') ? row.ceilingPrice
: (row && row.ceiling_price != null ? row.ceiling_price : '');
}
if (tab === 'all') {
var val = (v != null && v !== '') ? String(v) : '';
return '';
}
return (v == null || v === '') ? '' : String(v);
}
},
{field: 'po_detail_count',title: '已下发数量',operate: false,table: 'a',width: 96,align: 'center',
visible: indexShowPendingOnly,
formatter: function (v) {
return v != null && v !== '' ? String(v) : '0';
}
},
{field: 'po_amount_fill_cnt',title: '已上报金额',operate: false,table: 'a',width: 96,align: 'center',
visible: indexShowPendingOnly,
formatter: function (v) {
return v != null && v !== '' ? String(v) : '0';
}
},
{field: 'po_delivery_fill_cnt',title: '已上报货期',operate: false,table: 'a',width: 96,align: 'center',
visible: indexShowPendingOnly,
formatter: function (v) {
return v != null && v !== '' ? String(v) : '0';
}
},
{field: 'picked_supplier_name', title: '已选供应商', operate: false, table: 'a', width: 200, align: 'left',
visible: indexShowPickedOnly,
formatter: function (v) {
return v != null && v !== '' ? String(v) : '';
}
},
{field: 'CDF', title: __('订法'), operate: false, table: 'a', width: 100, align: 'center'},
{field: 'cGzzxMc', title: __('外厂单位'), operate: 'LIKE', table: 'a', width: 220, align: 'center'},
{field: 'MBZ', title: __('备注'), operate: 'LIKE', table: 'a', width: 150, align: 'center'},
{field: 'dStamp', title: __('操作日期'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, table: 'a', width: 165, align: 'center'},
{field: 'dputrecord', title: __('提交日期'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, table: 'b', width: 170, align: 'center'},
{field: 'cywyxm', title: __('业务员'), operate: 'LIKE', table: 'b', width: 80, align: 'center'},
{field: 'operate',title: '操作',width: 260,align: 'center',fixed: 'right',
table: table,
formatter: function (value, row, index) {
var tab = Controller.wffTab || 'all';
var pk = row && (row.ID != null ? row.ID : row.id);
if (!row || pk == null || pk === '' || String(pk) === '0') {
return '';
}
var area = ' data-area=\'["76%","100%"]\'';
var parts = [];
if (tab === 'all') {
//未发
parts.push(' 审核');
parts.push(' 完结');
} else if (tab === 'pending') {
//已下发
parts.push(' 采购确认');
parts.push(' 详情');
} else if (tab === 'picked') {
parts.push(' 详情');
} else {
//已完结
parts.push(' 详情');
}
return '' + parts.join(' ') + '
';
},
events: {}
}
];
var $wbh = $layout.find('.procuremen-main .widget-body');
var tableHeight = !$wbh.length ? 400 : Math.max(168, $(window).height() - $wbh.offset().top - 56);
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'ID',
sortName: 'a.ID',
width: 'auto',
height: tableHeight,
fixedColumns: true,
fixedRightNumber: 1,
clickToSelect: false,
dblClickToEdit: false,
commonSearch: false,
showToggle: false,
showExport: false,
smartDisplay: false,
queryParams: function (params) {
params.ym = Controller.currYm;
params.wff_tab = Controller.wffTab;
return params;
},
columns: [indexTableColumns]
});
Table.api.bindevent(table);
(function () {
var $wrap = table.closest('.bootstrap-table');
function procuremenSetFixedRightStaleLoading(hide) {
$wrap.find('.fixed-columns-right').toggleClass('procuremen-hide-fixed-right-loading', !!hide);
}
table.on('refresh.bs.table', function () {
if ($wrap.find('.fixed-table-loading').is(':visible')) {
procuremenSetFixedRightStaleLoading(true);
}
});
table.on('load-success.bs.table load-error.bs.table', function () {
procuremenSetFixedRightStaleLoading(false);
});
})();
var $bt = table.closest('.bootstrap-table');
var procuremenPoBlurTimer = null;
function procuremenNormPoCell(v) {
if (v == null || v === '') {
return '';
}
return String(v).trim();
}
if ($bt.length) {
$bt.off('blur.procuremenPoSave', '.procuremen-po-field').on('blur.procuremenPoSave', '.procuremen-po-field', function () {
if (Controller.wffTab !== 'all') {
return;
}
var $inp = $(this);
clearTimeout(procuremenPoBlurTimer);
procuremenPoBlurTimer = setTimeout(function () {
procuremenPoBlurTimer = null;
var rowIdx = parseInt($inp.data('rowIndex'), 10);
if (isNaN(rowIdx)) {
return;
}
var dataRows = table.bootstrapTable('getData');
if (!dataRows[rowIdx]) {
return;
}
var $qty = $bt.find('.procuremen-po-qty[data-row-index="' + rowIdx + '"]');
var $price = $bt.find('.procuremen-po-price[data-row-index="' + rowIdx + '"]');
var q = ($qty.length ? String($qty.val()) : '').trim();
var p = ($price.length ? String($price.val()) : '').trim();
var baseRow = dataRows[rowIdx];
var origQ = procuremenNormPoCell(baseRow.This_quantity);
var origP = procuremenNormPoCell(baseRow.ceilingPrice);
if (origP === '' && baseRow.ceiling_price != null && baseRow.ceiling_price !== '') {
origP = procuremenNormPoCell(baseRow.ceiling_price);
}
/* 与当前行数据一致则不调接口、不弹*/
if (q === origQ && p === origP) {
return;
}
var row = $.extend({}, baseRow);
row.This_quantity = q;
row.ceilingPrice = p;
Fast.api.ajax({
url: 'procuremen/completeDirectly',
type: 'POST',
data: {
row_json: JSON.stringify(row),
finish: '0',
__token__: $('input[name=\'__token__\']').val() || ''
}
}, function () {
try {
table.bootstrapTable('updateRow', {
index: rowIdx,
row: $.extend({}, baseRow, {This_quantity: q, ceilingPrice: p})
});
} catch (ignore) {
}
Toastr.success('操作成功');
return false;
});
}, 220);
});
}
if ($bt.length && $bt[0]) {
var tableRoot = $bt[0];
Controller._procuremenOpTableClick = function (e) {
var t = e.target;
if (!t || typeof t.closest !== 'function') {
return;
}
var finish = t.closest('a.procuremen-btn-finish');
if (finish && tableRoot.contains(finish) && !finish.classList.contains('disabled')) {
e.preventDefault();
if (typeof e.stopImmediatePropagation === 'function') {
e.stopImmediatePropagation();
}
e.stopPropagation();
var $f = $(finish);
var rowIdxF = parseInt($f.data('rowIndex'), 10);
var dataRowsF = table.bootstrapTable('getData');
var rowF = !isNaN(rowIdxF) && dataRowsF[rowIdxF] !== undefined ? dataRowsF[rowIdxF] : null;
if (!rowF) {
Toastr.error('无法取得行数据');
return;
}
var $qtyF = $bt.find('.procuremen-po-qty[data-row-index="' + rowIdxF + '"]');
var $priceF = $bt.find('.procuremen-po-price[data-row-index="' + rowIdxF + '"]');
if ($qtyF.length) {
rowF = $.extend({}, rowF, {This_quantity: String($qtyF.val()).trim()});
}
if ($priceF.length) {
rowF = $.extend({}, rowF, {ceilingPrice: String($priceF.val()).trim()});
}
Layer.confirm('确认后仅将本单标记为已完结。', function (idx) {
Layer.close(idx);
Fast.api.ajax({
url: 'procuremen/completeDirectly',
type: 'POST',
data: {
row_json: JSON.stringify(rowF),
finish: '1',
__token__: $('input[name=\'__token__\']').val() || ''
}
}, function () {
table.bootstrapTable('refresh');
Toastr.success('操作成功');
return false;
});
});
return;
}
var details = t.closest('a.procuremen-btn-details');
if (details && tableRoot.contains(details) && !details.classList.contains('disabled')) {
e.preventDefault();
if (typeof e.stopImmediatePropagation === 'function') {
e.stopImmediatePropagation();
}
e.stopPropagation();
var $d = $(details);
var rowIdxD = parseInt($d.data('rowIndex'), 10);
var dataRowsD = table.bootstrapTable('getData');
var rowD = !isNaN(rowIdxD) && dataRowsD[rowIdxD] !== undefined ? dataRowsD[rowIdxD] : null;
var detUrl;
if (rowD) {
detUrl = Fast.api.fixurl(Table.api.replaceurl('procuremen/details', rowD, table));
} else {
detUrl = Backend.api.replaceids(details, $d.attr('href'));
}
var tabForDet = Controller.wffTab ? Controller.wffTab : 'done';
if (String(detUrl).indexOf('wff_tab=') === -1) {
detUrl += (detUrl.indexOf('?') > -1 ? '&' : '?') + 'wff_tab=' + encodeURIComponent(tabForDet);
}
var $ad = $(details);
var optsd = $.extend({}, $ad.data() || {});
var titled = $ad.attr('title') || $ad.data('title') || '详情';
var buttond = Backend.api.gettablecolumnbutton(optsd);
var layerOptsd = $.extend({}, optsd);
if (buttond && typeof buttond.callback === 'function') {
layerOptsd.callback = buttond.callback;
}
if (buttond && buttond.layerArea && buttond.layerArea.length) {
layerOptsd.area = buttond.layerArea;
}
var winNd = $ad.data('window') || 'self';
var winD = window[winNd] || window;
if (!winD.Backend || !winD.Backend.api) {
Toastr.error('Backend 未就绪,请刷新页面');
return;
}
winD.Backend.api.open(detUrl, titled, layerOptsd);
return;
}
var outward = t.closest('a.procuremen-btn-outward');
if (outward && !outward.classList.contains('disabled')) {
e.preventDefault();
if (typeof e.stopImmediatePropagation === 'function') {
e.stopImmediatePropagation();
}
e.stopPropagation();
var $o = $(outward);
var oOpts = $.extend({}, $o.data() || {});
var rowIdx = parseInt(oOpts.rowIndex, 10);
var dataRows = table.bootstrapTable('getData');
var row = !isNaN(rowIdx) && dataRows[rowIdx] !== undefined ? dataRows[rowIdx] : null;
var tab = Controller.wffTab ? Controller.wffTab : 'all';
var base = 'procuremen/outward_detail?wff_tab=' + encodeURIComponent(tab);
var outUrl;
if (row) {
outUrl = Fast.api.fixurl(Table.api.replaceurl(base, row, table));
} else {
outUrl = Backend.api.replaceids(outward, $o.attr('href'));
if (String(outUrl).indexOf('wff_tab=') === -1) {
outUrl += (outUrl.indexOf('?') > -1 ? '&' : '?') + 'wff_tab=' + encodeURIComponent(tab);
}
}
var $a = $(outward);
var opts = $.extend({}, $a.data() || {});
var title = $a.attr('title') || $a.data('title') || $a.data('original-title');
var button = Backend.api.gettablecolumnbutton(opts);
var layerOpts = $.extend({}, opts);
if (button && typeof button.callback === 'function') {
layerOpts.callback = button.callback;
}
if (button && button.layerArea && button.layerArea.length) {
layerOpts.area = button.layerArea;
}
var winName = $a.data('window') || 'self';
var win = window[winName] || window;
if (!win.Backend || !win.Backend.api) {
Toastr.error('Backend 未就绪,请刷新页面');
return;
}
if (typeof layerOpts.confirm !== 'undefined') {
Layer.confirm(layerOpts.confirm, function (index) {
win.Backend.api.open(outUrl, title, layerOpts);
Layer.close(index);
});
} else {
win.Backend.api.open(outUrl, title, layerOpts);
}
return;
}
var review = t.closest('a.procuremen-btn-review');
if (!review || !tableRoot.contains(review) || review.classList.contains('disabled')) {
return;
}
e.preventDefault();
if (typeof e.stopImmediatePropagation === 'function') {
e.stopImmediatePropagation();
}
e.stopPropagation();
var $a2 = $(review);
var rowIdx2 = parseInt($a2.data('rowIndex'), 10);
var dataRows2 = table.bootstrapTable('getData');
var row2 = !isNaN(rowIdx2) && dataRows2[rowIdx2] !== undefined ? dataRows2[rowIdx2] : null;
var revUrl;
if (row2) {
revUrl = Fast.api.fixurl(Table.api.replaceurl('procuremen/review', row2, table));
} else {
revUrl = Backend.api.replaceids(review, $a2.attr('href'));
}
var opts2 = $.extend({}, $a2.data() || {});
var title2 = $a2.attr('title') || $a2.data('title') || $a2.data('original-title');
var button2 = Backend.api.gettablecolumnbutton(opts2);
var layerOpts2 = $.extend({}, opts2);
if (button2 && typeof button2.callback === 'function') {
layerOpts2.callback = button2.callback;
}
if (button2 && button2.layerArea && button2.layerArea.length) {
layerOpts2.area = button2.layerArea;
}
var winName2 = $a2.data('window') || 'self';
var win2 = window[winName2] || window;
if (!win2.Backend || !win2.Backend.api) {
Toastr.error('Backend 未就绪,请刷新页面');
return;
}
if (typeof layerOpts2.confirm !== 'undefined') {
Layer.confirm(layerOpts2.confirm, function (index) {
win2.Backend.api.open(revUrl, title2, layerOpts2);
Layer.close(index);
});
} else {
win2.Backend.api.open(revUrl, title2, layerOpts2);
}
};
tableRoot.addEventListener('click', Controller._procuremenOpTableClick, true);
}
$layout.find('.procuremen-main').off('click.procuremenTbRefresh').on('click.procuremenTbRefresh', '#procuremen-toolbar-host .btn-refresh', function (e) {
e.preventDefault();
table.bootstrapTable('refresh');
});
table.on('refresh.bs.table', function () {
$('#procuremen-toolbar-host .btn-refresh .fa').addClass('fa-spin');
setTimeout(function () {
var $host2 = $('#procuremen-toolbar-host');
var $bt2 = table.closest('.bootstrap-table');
if (!$host2.length || !$bt2.length) {
return;
}
var $ft2 = $bt2.children('.fixed-table-toolbar').first();
if (!$ft2.length) {
$ft2 = $host2.find('.fixed-table-toolbar').first();
}
if (!$ft2.length) {
return;
}
if ($ft2.parent()[0] !== $host2[0]) {
$host2.children('.fixed-table-toolbar').remove();
$host2.append($ft2);
var $src2 = $bt2.closest('.procuremen-table-area').find('#toolbar').first();
if ($src2.length && !$src2.children().length) {
$src2.addClass('procuremen-toolbar-empty');
}
}
$ft2.find('.procuremen-toolbar-search-wrap').removeClass('procuremen-toolbar-search-wrap');
var $search2 = $ft2.find('.search').first();
if (!$search2.length) {
return;
}
var $right2 = $search2.closest('.columns, .pull-right').first();
if (!$right2.length || ($ft2[0] && !$.contains($ft2[0], $right2[0]))) {
return;
}
$ft2.children().each(function () {
var $c2 = $(this);
if ($c2.is('.bars, .bs-bars') || $c2[0] === $right2[0]) {
return;
}
var merge2 = $c2.hasClass('columns')
|| $c2.hasClass('pull-right')
|| ($c2.hasClass('btn-group') && $c2.find('.search').length === 0);
if (!merge2 || $c2.find('.search').length) {
return;
}
if ($c2.hasClass('btn-group') && !$c2.hasClass('columns')) {
$c2.appendTo($right2);
} else {
$c2.children().appendTo($right2);
if (!$c2.children().length) {
$c2.remove();
}
}
});
$ft2.find('.search').first().prependTo($right2);
$right2.addClass('procuremen-toolbar-search-wrap');
}, 0);
});
table.on('post-body.bs.table', function () {
$('#procuremen-toolbar-host .btn-refresh .fa').removeClass('fa-spin');
});
$(window).off('resize.procuremenIndex').on('resize.procuremenIndex', function () {
try {
var $wbr = $layout.find('.procuremen-main .widget-body');
var h = !$wbr.length ? 400 : Math.max(168, $(window).height() - $wbr.offset().top - 56);
table.bootstrapTable('resetView', {height: h});
} catch (ignore) {
}
});
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
Controller.api.bindevent();
},
outward_detail: function () {
Controller.api.bindevent();
var $wrap = $('.outward-detail-wrap');
if (!$wrap.length || !$('#btn-pod-purchase-confirm').length) {
return;
}
var scydgyId = String($wrap.attr('data-scydgy-id') || '').trim();
if (!scydgyId) {
return;
}
var purchaseOrderId = String($wrap.attr('data-purchase-order-id') || '').trim();
$wrap.off('.procuremenPurchaseConfirm');
$wrap.on('change.procuremenPurchaseConfirm', '.pod-pick-cb', function () {
if (this.checked) {
$wrap.find('.pod-pick-cb').not(this).prop('checked', false);
}
});
$wrap.on('click.procuremenPurchaseConfirm', '#btn-pod-purchase-confirm', function () {
var FastRef = (typeof Fast !== 'undefined' && Fast.api) ? Fast
: (typeof parent !== 'undefined' && parent.Fast && parent.Fast.api ? parent.Fast : null);
if (!FastRef || !FastRef.api) {
if (typeof parent !== 'undefined' && parent.Toastr) {
parent.Toastr.error('页面未就绪,请刷新后重试');
}
return;
}
var $cbs = $wrap.find('.pod-pick-cb');
var all = $cbs.map(function () { return String($(this).val()); }).get();
var sel = $cbs.filter(':checked').val();
if (!sel) {
var L = (typeof parent !== 'undefined' && parent.Layer) ? parent.Layer : (typeof Layer !== 'undefined' ? Layer : null);
if (L && typeof L.msg === 'function') {
L.msg('请勾选一条明细');
} else if (typeof Toastr !== 'undefined') {
Toastr.warning('请勾选一条明细');
}
return;
}
var unsel = $.grep(all, function (id) { return String(id) !== String(sel); });
var selArr = [String(sel)];
var tk = $('input[name=\'__token__\']').val() || '';
function podRowCompany($tr) {
if (!$tr || !$tr.length) {
return '(无名称)';
}
var $tds = $tr.children('td');
if ($tds.length < 8) {
return '(无名称)';
}
var t = $.trim($tds.eq(6).text());
return t !== '' ? t : '(无名称)';
}
function escHtml(s) {
return String(s)
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/"/g, '"');
}
var $trOk = $cbs.filter(':checked').closest('tr');
var okName = podRowCompany($trOk);
var unNames = [];
$cbs.not(':checked').each(function () {
unNames.push(podRowCompany($(this).closest('tr')));
});
var nUn = unNames.length;
var unListText = nUn ? (nUn <= 4 ? unNames.join('、') : (unNames.slice(0, 3).join('、') + ' 等共' + nUn + '家')) : '—';
var confirmHtml = ''
+ ''
+ '
提交后将立即发送短信,且不可撤回或更改。请确认以下通知:
'
+ '
'
+ '- 已选中 1 条:采购确认结果视为「通过」,将向 ' + escHtml(okName) + ' 发送「已通过」短信;
'
+ '- 未选中 ' + nUn + ' 条:视为「未通过」,将向对应供应商发送「未通过」短信。
'
+ '
'
+ (nUn ? ('
未选中涉及:' + escHtml(unListText) + '
') : '')
+ '
是否确认提交?
'
+ '
';
var Lr = (typeof parent !== 'undefined' && parent.Layer) ? parent.Layer : (typeof Layer !== 'undefined' ? Layer : null);
if (!Lr || typeof Lr.confirm !== 'function') {
if (typeof Toastr !== 'undefined') {
Toastr.error('弹层组件未就绪,请刷新后重试');
}
return;
}
Lr.confirm(confirmHtml, {
icon: 3,
title: '采购确认 — 短信通知',
area: ['480px', 'auto'],
btn: ['确定提交', '取消']
}, function (idx) {
Lr.close(idx);
FastRef.api.ajax({
url: FastRef.api.fixurl('procuremen/purchaseConfirmPick'),
type: 'POST',
data: {
scydgy_id: scydgyId,
purchase_order_id: purchaseOrderId,
selected_id: sel,
selected_ids: JSON.stringify(selArr),
unselected_ids: JSON.stringify(unsel),
all_detail_ids: JSON.stringify(all),
__token__: tk
}
}, function () {
if (typeof parent !== 'undefined' && parent.Layer) {
var ix = parent.Layer.getFrameIndex(window.name);
if (typeof ix !== 'undefined') {
parent.Layer.close(ix);
}
}
var p$ = (typeof parent !== 'undefined' && parent.jQuery) ? parent.jQuery : (typeof parent !== 'undefined' ? parent.$ : null);
if (p$) {
var $doneTab = p$('.procuremen-wff-tabs a[data-wff="done"]');
if ($doneTab.length) {
$doneTab.trigger('click');
} else if (p$('#table').length) {
p$('#table').bootstrapTable('refresh');
}
}
});
});
});
},
details: function () {
Controller.api.bindevent();
},
review: function () {
var ids = window.Fast && Fast.api ? Fast.api.query('ids') : null;
if (ids === null || ids === '') {
Toastr.error('请刷新页面后重试');
return;
}
var $ptable = parent.$('#table');
if (!$ptable.length) {
Toastr.error('请刷新页面后重试');
return;
}
var pk = $ptable.bootstrapTable('getOptions').pk || 'ID';
var row = null;
$.each($ptable.bootstrapTable('getData'), function (i, r) {
if (String(r[pk]) === String(ids)) {
row = r;
return false;
}
});
if (!row) {
Toastr.error('请刷新页面后重试');
return;
}
$('#review-ccydh').text(row.CCYDH || '');
$('#review-cyjmc').text(row.CYJMC || '');
$('#review-CGYMC').text(row.CGYMC || '');
$('#review-CDW').text(row.CDW != null && row.CDW !== '' ? row.CDW : '');
$('#review-NGZL').text(row.NGZL != null && row.NGZL !== '' ? row.NGZL : '');
$('#review-CDF').text(row.CDF || '');
$('#review-cGzzxMc').text(row.cGzzxMc || '');
var qDisp = row.This_quantity != null && String(row.This_quantity).trim() !== '' ? String(row.This_quantity).trim()
: (row.this_quantity != null && String(row.this_quantity).trim() !== '' ? String(row.this_quantity).trim() : '');
var pDisp = row.ceilingPrice != null && String(row.ceilingPrice).trim() !== '' ? String(row.ceilingPrice).trim()
: (row.ceiling_price != null && String(row.ceiling_price).trim() !== '' ? String(row.ceiling_price).trim() : '');
$('#review-qty-display').text(qDisp !== '' ? qDisp : '—');
$('#review-price-display').text(pDisp !== '' ? pDisp : '—');
$('#c-row-json').val(JSON.stringify(row));
var reviewCompaniesAll = [];
var activeReviewCategory = null;
var reviewCompanySearchQ = '';
var reviewSelectedMap = {};
var reviewSearchTimer = null;
function syncReviewSelectedSummary() {
var entries = [];
$.each(reviewSelectedMap, function (k, c) {
if (!c) {
return;
}
var t = String(c.name || c.company_name || '').trim() || '(无名称)';
entries.push({ k: k, label: t });
});
entries.sort(function (a, b) {
return a.label.localeCompare(b.label, 'zh-CN');
});
var n = entries.length;
$('#review-selected-count').text(String(n));
$('#review-selected-tags').empty();
if (!n) {
$('#review-selected-empty').show();
return;
}
$('#review-selected-empty').hide();
$.each(entries, function (i, e) {
var $chip = $('').attr('title', e.label);
$chip.data('reviewSelKey', e.k);
$chip.append(
$('').text(e.label),
$('').text('\u00d7')
);
$('#review-selected-tags').append($chip);
});
}
syncReviewSelectedSummary();
$('#review-selected-tags').off('click.reviewChipRemove').on('click.reviewChipRemove', '.review-chip-remove', function (e) {
e.preventDefault();
e.stopPropagation();
var k = $(this).closest('.review-selected-chip').data('reviewSelKey');
if (k == null || k === '') {
return;
}
delete reviewSelectedMap[k];
$('#review-company-tbody .review-company-cb').each(function () {
var c = $(this).data('company');
var kk = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
if (kk === k) {
$(this).prop('checked', false);
}
});
var $cbsR = $('#review-company-tbody .review-company-cb');
var $masterR = $('#review-check-all');
if (!$cbsR.length) {
$masterR.prop('checked', false).prop('indeterminate', false);
} else {
var nR = $cbsR.filter(':checked').length;
$masterR.prop('checked', nR === $cbsR.length);
$masterR.prop('indeterminate', nR > 0 && nR < $cbsR.length);
}
syncReviewSelectedSummary();
});
$('#review-category-sidebar').off('click.reviewCat').on('click.reviewCat', '.review-cat-item', function () {
var $t = $(this);
if ($t.hasClass('review-cat-all')) {
activeReviewCategory = null;
} else {
activeReviewCategory = $t.data('reviewCat');
}
$('#review-category-list .review-cat-item').removeClass('active');
$t.addClass('active');
var q = reviewCompanySearchQ;
var searchActive = q.length > 0;
var list = [];
$.each(reviewCompaniesAll, function (i, c) {
if (!c || typeof c !== 'object') {
return;
}
if (!searchActive && activeReviewCategory !== null) {
var segOk = activeReviewCategory == null || activeReviewCategory === '';
if (!segOk) {
var rawCat = (c.company_type != null && String(c.company_type).trim() !== '')
? String(c.company_type).trim()
: String(c.category || '').trim();
var segs = [];
if (!rawCat) {
segs = ['未分类'];
} else {
var parts = rawCat.split('、');
var seen = {};
$.each(parts, function (idx, p) {
var tt = String(p).trim();
if (!tt || seen[tt]) {
return;
}
seen[tt] = true;
segs.push(tt);
});
if (!segs.length) {
segs = ['未分类'];
}
}
if ($.inArray(activeReviewCategory, segs) === -1) {
return;
}
}
}
if (q) {
var blob = [
c.name, c.company_name, c.username, c.email, c.phone,
c.company_type, c.category
].map(function (x) {
return x == null ? '' : String(x);
}).join(' ').toLowerCase();
if (blob.indexOf(q) === -1) {
return;
}
}
list.push(c);
});
var $tbody = $('#review-company-tbody').empty();
if (!list.length) {
$tbody.append($('
').append($(' | ').text('暂无符合条件的单位')));
var $cbs0 = $('#review-company-tbody .review-company-cb');
var $master0 = $('#review-check-all');
if (!$cbs0.length) {
$master0.prop('checked', false).prop('indeterminate', false);
} else {
var n0 = $cbs0.filter(':checked').length;
$master0.prop('checked', n0 === $cbs0.length);
$master0.prop('indeterminate', n0 > 0 && n0 < $cbs0.length);
}
syncReviewSelectedSummary();
return;
}
$.each(list, function (i, c) {
var $cb = $('');
$cb.data('company', c);
var k = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
if (k && reviewSelectedMap[k]) {
$cb.prop('checked', true);
}
var $tr = $('
');
$tr.append($(' | ').append($cb));
$tr.append($(' | ').text(c.name || c.company_name || ''));
$tr.append($(' | ').text(c.username || ''));
$tr.append($(' | ').text(c.email || ''));
$tr.append($(' | ').text(c.phone || ''));
$tr.append($(' | ').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
$tbody.append($tr);
});
var $cbs = $('#review-company-tbody .review-company-cb');
var $master = $('#review-check-all');
var n = $cbs.filter(':checked').length;
$master.prop('checked', n === $cbs.length);
$master.prop('indeterminate', n > 0 && n < $cbs.length);
syncReviewSelectedSummary();
});
$('#review-company-search').off('input.reviewSearch').on('input.reviewSearch', function () {
var v = ($(this).val() || '').trim().toLowerCase();
if (reviewSearchTimer) {
clearTimeout(reviewSearchTimer);
}
reviewSearchTimer = setTimeout(function () {
reviewSearchTimer = null;
reviewCompanySearchQ = v;
var q = reviewCompanySearchQ;
var searchActive = q.length > 0;
var list = [];
$.each(reviewCompaniesAll, function (i, c) {
if (!c || typeof c !== 'object') {
return;
}
if (!searchActive && activeReviewCategory !== null) {
var segOk2 = activeReviewCategory == null || activeReviewCategory === '';
if (!segOk2) {
var rawCat2 = (c.company_type != null && String(c.company_type).trim() !== '')
? String(c.company_type).trim()
: String(c.category || '').trim();
var segs2 = [];
if (!rawCat2) {
segs2 = ['未分类'];
} else {
var parts2 = rawCat2.split('、');
var seen2 = {};
$.each(parts2, function (idx, p) {
var tt2 = String(p).trim();
if (!tt2 || seen2[tt2]) {
return;
}
seen2[tt2] = true;
segs2.push(tt2);
});
if (!segs2.length) {
segs2 = ['未分类'];
}
}
if ($.inArray(activeReviewCategory, segs2) === -1) {
return;
}
}
}
if (q) {
var blob2 = [
c.name, c.company_name, c.username, c.email, c.phone,
c.company_type, c.category
].map(function (x) {
return x == null ? '' : String(x);
}).join(' ').toLowerCase();
if (blob2.indexOf(q) === -1) {
return;
}
}
list.push(c);
});
var $tbody2 = $('#review-company-tbody').empty();
if (!list.length) {
$tbody2.append($('
').append($(' | ').text('暂无符合条件的单位')));
} else {
$.each(list, function (i, c) {
var $cb = $('');
$cb.data('company', c);
var k2 = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
if (k2 && reviewSelectedMap[k2]) {
$cb.prop('checked', true);
}
var $tr = $('
');
$tr.append($(' | ').append($cb));
$tr.append($(' | ').text(c.name || c.company_name || ''));
$tr.append($(' | ').text(c.username || ''));
$tr.append($(' | ').text(c.email || ''));
$tr.append($(' | ').text(c.phone || ''));
$tr.append($(' | ').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
$tbody2.append($tr);
});
}
var $cbsS = $('#review-company-tbody .review-company-cb');
var $masterS = $('#review-check-all');
if (!$cbsS.length) {
$masterS.prop('checked', false).prop('indeterminate', false);
} else {
var nS = $cbsS.filter(':checked').length;
$masterS.prop('checked', nS === $cbsS.length);
$masterS.prop('indeterminate', nS > 0 && nS < $cbsS.length);
}
syncReviewSelectedSummary();
}, 160);
});
$('#review-company-tbody').off('change.reviewCb').on('change.reviewCb', '.review-company-cb', function () {
var c = $(this).data('company');
var k = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
var $cbsC = $('#review-company-tbody .review-company-cb');
var $masterC = $('#review-check-all');
if (!k) {
if (!$cbsC.length) {
$masterC.prop('checked', false).prop('indeterminate', false);
} else {
var nC = $cbsC.filter(':checked').length;
$masterC.prop('checked', nC === $cbsC.length);
$masterC.prop('indeterminate', nC > 0 && nC < $cbsC.length);
}
syncReviewSelectedSummary();
return;
}
if ($(this).prop('checked')) {
reviewSelectedMap[k] = c;
} else {
delete reviewSelectedMap[k];
}
var n2 = $cbsC.filter(':checked').length;
$masterC.prop('checked', n2 === $cbsC.length);
$masterC.prop('indeterminate', n2 > 0 && n2 < $cbsC.length);
syncReviewSelectedSummary();
});
$('#review-check-all').off('change.reviewAll').on('change.reviewAll', function () {
var on = $(this).prop('checked');
$('#review-company-tbody .review-company-cb').each(function () {
$(this).prop('checked', on).trigger('change');
});
});
$('#btn-review-submit').off('click.reviewSubmit').on('click.reviewSubmit', function () {
var selected = [];
$.each(reviewSelectedMap, function (k, c) {
if (c) {
selected.push(c);
}
});
if (!selected.length) {
Toastr.warning('请至少选择一个下发单位');
return;
}
var cons;
try {
cons = JSON.parse($('#c-row-json').val() || '{}');
} catch (e) {
cons = {};
}
Fast.api.ajax({
url: 'procuremen/review',
type: 'POST',
data: {
__token__: $('input[name=\'__token__\']').val(),
row_json: JSON.stringify(cons),
companies_json: JSON.stringify(selected),
}
}, function (data, ret) {
var msg = (ret && ret.msg) ? ret.msg : '操作成功';
if (typeof parent !== 'undefined' && parent.Toastr) {
parent.Toastr.success(msg);
}
if (parent && parent.$ && parent.$('#table').length) {
parent.$('#table').bootstrapTable('refresh');
}
var index = parent.Layer.getFrameIndex(window.name);
parent.Layer.close(index);
return false;
});
});
Fast.api.ajax({
url: 'procuremen/snapshotToProcure',
type: 'POST',
data: {
__token__: $('input[name=\'__token__\']').val(),
row_json: JSON.stringify(row)
}
}, function () {
Fast.api.ajax({
url: 'procuremen/reviewCompanies',
type: 'GET',
loading: false
}, function (data) {
reviewCompaniesAll = Array.isArray(data) ? data : [];
reviewSelectedMap = {};
activeReviewCategory = null;
reviewCompanySearchQ = '';
$('#review-company-search').val('');
var counts = {};
var total = 0;
$.each(reviewCompaniesAll, function (i, c) {
if (!c || typeof c !== 'object') {
return;
}
total++;
var raw = (c.company_type != null && String(c.company_type).trim() !== '')
? String(c.company_type).trim()
: String(c.category || '').trim();
var segs = [];
if (!raw) {
segs = ['未分类'];
} else {
var parts = raw.split('、');
var seen = {};
$.each(parts, function (idx, p) {
var tt = String(p).trim();
if (!tt || seen[tt]) {
return;
}
seen[tt] = true;
segs.push(tt);
});
if (!segs.length) {
segs = ['未分类'];
}
}
$.each(segs, function (j, seg) {
counts[seg] = (counts[seg] || 0) + 1;
});
});
var cats = Object.keys(counts);
cats.sort(function (a, b) {
return a.localeCompare(b, 'zh-CN');
});
var $list = $('#review-category-list').empty();
var $all = $('').append(
$('').text('全部 '),
$('').text('(' + total + ')')
);
$all.toggleClass('active', activeReviewCategory === null);
$list.append($all);
$.each(cats, function (i, cat) {
var $it = $('').append(
$('').text(cat + ' '),
$('').text('(' + counts[cat] + ')')
);
$it.data('reviewCat', cat);
$it.toggleClass('active', activeReviewCategory === cat);
$list.append($it);
});
var q = reviewCompanySearchQ;
var searchActive = q.length > 0;
var list = [];
$.each(reviewCompaniesAll, function (i, c) {
if (!c || typeof c !== 'object') {
return;
}
if (!searchActive && activeReviewCategory !== null) {
var segOk = activeReviewCategory == null || activeReviewCategory === '';
if (!segOk) {
var rawCat = (c.company_type != null && String(c.company_type).trim() !== '')
? String(c.company_type).trim()
: String(c.category || '').trim();
var segsB = [];
if (!rawCat) {
segsB = ['未分类'];
} else {
var partsB = rawCat.split('、');
var seenB = {};
$.each(partsB, function (idx, p) {
var ttB = String(p).trim();
if (!ttB || seenB[ttB]) {
return;
}
seenB[ttB] = true;
segsB.push(ttB);
});
if (!segsB.length) {
segsB = ['未分类'];
}
}
if ($.inArray(activeReviewCategory, segsB) === -1) {
return;
}
}
}
if (q) {
var blob = [
c.name, c.company_name, c.username, c.email, c.phone,
c.company_type, c.category
].map(function (x) {
return x == null ? '' : String(x);
}).join(' ').toLowerCase();
if (blob.indexOf(q) === -1) {
return;
}
}
list.push(c);
});
var $tbody = $('#review-company-tbody').empty();
if (!list.length) {
$tbody.append($('
').append($(' | ').text('暂无符合条件的单位')));
} else {
$.each(list, function (i, c) {
var $cb = $('');
$cb.data('company', c);
var k3 = (!c || typeof c !== 'object') ? '' : [String(c.email || ''), String(c.phone || ''), String(c.name || c.company_name || '')].join('\x01');
if (k3 && reviewSelectedMap[k3]) {
$cb.prop('checked', true);
}
var $tr = $('
');
$tr.append($(' | ').append($cb));
$tr.append($(' | ').text(c.name || c.company_name || ''));
$tr.append($(' | ').text(c.username || ''));
$tr.append($(' | ').text(c.email || ''));
$tr.append($(' | ').text(c.phone || ''));
$tr.append($(' | ').text((c.company_type != null && String(c.company_type).trim() !== '') ? String(c.company_type).trim() : (c.category || '')));
$tbody.append($tr);
});
}
var $cbsF = $('#review-company-tbody .review-company-cb');
var $masterF = $('#review-check-all');
if (!$cbsF.length) {
$masterF.prop('checked', false).prop('indeterminate', false);
} else {
var nF = $cbsF.filter(':checked').length;
$masterF.prop('checked', nF === $cbsF.length);
$masterF.prop('indeterminate', nF > 0 && nF < $cbsF.length);
}
syncReviewSelectedSummary();
return false;
});
return false;
});
},
api: {
bindevent: function () {
Form.api.bindevent($('form[role=form]'));
}
}
};
return Controller;
});