| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- function archiveEscHtml(s) {
- return String(s == null ? '' : s)
- .replace(/&/g, '&')
- .replace(/</g, '<')
- .replace(/>/g, '>')
- .replace(/"/g, '"');
- }
- function archiveCan(rule) {
- var map = (typeof Config !== 'undefined' && Config.procuremenAuth) ? Config.procuremenAuth : null;
- if (!map) {
- return false;
- }
- var key = String(rule || '').toLowerCase().replace(/^procuremen\//, '');
- var v = map[key];
- return v === true || v === 1 || v === '1';
- }
- var Controller = {
- index: function () {
- Table.api.init({
- extend: {
- index_url: 'procuremenarchive/index' + location.search,
- table: 'purchase_order',
- }
- });
- var table = $("#table");
- function archiveCellText(value) {
- var text = archiveEscHtml(value == null ? '' : value);
- return "<div class='autocontent-item' style='white-space:nowrap;text-overflow:ellipsis;overflow:hidden;max-width:100%;width:100%;box-sizing:border-box;'>" + text + "</div>";
- }
- /** 让省略宽度跟单元格实际宽度一致,避免列很宽却只显示 250px */
- function archiveFitAutocontent() {
- if ($('body').hasClass('fa-sidebar-resizing')) {
- return;
- }
- table.closest('.bootstrap-table').find('td.autocontent').each(function () {
- var td = this;
- var $item = $(td).children('.autocontent-item').first();
- if (!$item.length) {
- return;
- }
- var cs = window.getComputedStyle(td);
- var pad = (parseFloat(cs.paddingLeft) || 0) + (parseFloat(cs.paddingRight) || 0);
- var w = Math.floor(td.clientWidth - pad);
- if (w > 0) {
- $item.css({maxWidth: w + 'px', width: w + 'px'});
- }
- });
- }
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'scydgy_id',
- sortName: 'id',
- sortOrder: 'desc',
- commonSearch: true,
- search: true,
- pagination: true,
- smartDisplay: false,
- pageSize: Config.pagesize || localStorage.getItem('pagesize') || 20,
- pageList: [10, 15, 20, 25, 50],
- showJumpto: true,
- columns: [
- [
- {checkbox: true, width: 36},
- {field: 'CCYDH', title: '订单号', operate: 'LIKE', width: 140, align: 'left'},
- {
- field: 'CYJMC',
- title: '印件名称',
- operate: 'LIKE',
- class: 'autocontent',
- formatter: function (value) {
- return archiveCellText(value);
- }
- },
- {
- field: 'CGYMC',
- title: '工序名称',
- operate: 'LIKE',
- width: 140,
- class: 'autocontent',
- formatter: function (value) {
- return archiveCellText(value);
- }
- },
- {
- field: 'pick_company_name',
- title: '已选供应商',
- operate: 'LIKE',
- width: 180,
- class: 'autocontent',
- formatter: function (value) {
- return archiveCellText(value);
- }
- },
- {
- field: 'createtime',
- title: '完结时间',
- operate: 'RANGE',
- addclass: 'datetimerange',
- autocomplete: false,
- width: 165,
- formatter: function (value, row) {
- if (row.createtime_text) {
- return row.createtime_text;
- }
- if (value == null || value === '') {
- return '';
- }
- var n = parseInt(value, 10);
- if (!isNaN(n) && n > 946684800) {
- return Table.api.formatter.datetime.call(this, value, row);
- }
- return String(value);
- }
- },
- {
- field: 'operate',
- title: '操作',
- width: 100,
- align: 'center',
- operate: false,
- table: table,
- formatter: function (value, row) {
- var sid = row && row.scydgy_id;
- if (!sid) {
- return '';
- }
- if (!archiveCan('details')) {
- return '';
- }
- return '<a href="javascript:;" class="btn btn-xs btn-info btn-archive-details" data-scydgy-id="' + sid + '" title="详情"><i class="fa fa-file-text-o"></i> 详情</a>';
- },
- events: {}
- }
- ]
- ]
- });
- Table.api.bindevent(table);
- table.on('post-body.bs.table load-success.bs.table', function () {
- setTimeout(archiveFitAutocontent, 0);
- });
- $(window).off('resize.procuremenArchive').on('resize.procuremenArchive', function () {
- if ($('body').hasClass('fa-sidebar-resizing')) {
- return;
- }
- setTimeout(archiveFitAutocontent, 40);
- });
- $(document).off('fa.sidebar.resized.procuremenArchive fa.table.relayout.procuremenArchive')
- .on('fa.sidebar.resized.procuremenArchive fa.table.relayout.procuremenArchive', function () {
- setTimeout(archiveFitAutocontent, 40);
- });
- $(document).off('click.procuremenArchiveCommonSearch', 'button[name="commonSearch"]').on('click.procuremenArchiveCommonSearch', 'button[name="commonSearch"]', function () {
- setTimeout(archiveFitAutocontent, 150);
- });
- $(document).off('click.procuremenArchiveDetails', '.btn-archive-details').on('click.procuremenArchiveDetails', '.btn-archive-details', function (e) {
- e.preventDefault();
- var sid = $(this).data('scydgy-id') || $(this).attr('data-scydgy-id');
- if (!sid) {
- return;
- }
- var url = Fast.api.fixurl('procuremen/details?ids=' + encodeURIComponent(String(sid)));
- Backend.api.open(url, '详情', {area: ['92%', '88%']});
- });
- $(document).off('click.procuremenArchiveAbandon', '#btn-archive-abandon').on('click.procuremenArchiveAbandon', '#btn-archive-abandon', function (e) {
- e.preventDefault();
- if (!archiveCan('archiveabandon')) {
- Toastr.error('无重新下发权限');
- return;
- }
- var sel = table.bootstrapTable('getSelections') || [];
- if (!sel.length) {
- Toastr.warning('请先勾选至少 1 条订单');
- return;
- }
- var idSet = {};
- var rowsHtml = '<table class="table table-bordered table-condensed" style="margin:8px 0 0;font-size:12px;">'
- + '<thead><tr><th>订单号</th><th>工序名称</th><th>印件名称</th></tr></thead><tbody>';
- $.each(sel, function (i, row) {
- var sid = row && row.scydgy_id;
- if (sid != null && sid !== '' && String(sid) !== '0') {
- idSet[String(sid)] = true;
- }
- rowsHtml += '<tr><td>' + archiveEscHtml(String(row.CCYDH || '').trim() || '—') + '</td>'
- + '<td>' + archiveEscHtml(String(row.CGYMC || '').trim() || '—') + '</td>'
- + '<td>' + archiveEscHtml(String(row.CYJMC || '').trim() || '—') + '</td></tr>';
- });
- rowsHtml += '</tbody></table>';
- var idList = Object.keys(idSet);
- if (!idList.length) {
- Toastr.warning('所选行无效,请重新勾选');
- return;
- }
- var abandonMsg = '<div style="text-align:left;line-height:1.65;font-size:13px;">'
- + '<p style="margin:0 0 8px 0;">即将从历史存证退回协助初选并重新下发以下 <strong>' + idList.length + '</strong> 个订单(历史记录会保留):</p>'
- + rowsHtml
- + '<p style="margin:10px 0 0;color:#a94442;"><strong>提示:</strong>退回后需重新选择供应商下发。</p></div>';
- Layer.confirm(abandonMsg, {
- title: '重新下发确认',
- area: ['560px', 'auto'],
- icon: 3,
- btn: ['确认重新下发', '取消']
- }, function (idx) {
- Layer.close(idx);
- Fast.api.ajax({
- url: 'procuremen/archiveabandon',
- type: 'POST',
- data: {
- scydgy_ids_json: JSON.stringify(idList),
- __token__: $('input[name=\'__token__\']').val() || Config.token
- }
- }, function () {
- table.bootstrapTable('refresh');
- return false;
- });
- });
- });
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|