| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- function exportCan(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 () {
- var currYm = Controller.api.currentYm();
- $('#export-preview-ym').val(currYm);
- function listUrl(ym) {
- ym = (ym || '').trim();
- if (!/^\d{4}-\d{2}$/.test(ym)) {
- ym = Controller.api.currentYm();
- }
- return Fast.api.fixurl('procuremenexport/index?ym=' + encodeURIComponent(ym));
- }
- function refreshTable() {
- var ym = ($('#export-preview-ym').val() || '').trim();
- if (!/^\d{4}-\d{2}$/.test(ym)) {
- ym = Controller.api.currentYm();
- $('#export-preview-ym').val(ym);
- }
- $('#table').bootstrapTable('refresh', {url: listUrl(ym)});
- }
- Table.api.init({
- extend: {
- index_url: listUrl(currYm),
- table: 'purchase_order',
- }
- });
- var table = $('#table');
- table.bootstrapTable({
- url: listUrl(currYm),
- pk: 'id',
- sortName: 'id',
- sortOrder: 'desc',
- sidePagination: 'server',
- pagination: true,
- pageSize: Config.pagesize || localStorage.getItem('pagesize') || 20,
- pageList: [10, 15, 20, 25, 50],
- showJumpto: true,
- commonSearch: true,
- search: true,
- queryParams: function (params) {
- var ym = ($('#export-preview-ym').val() || '').trim();
- if (!/^\d{4}-\d{2}$/.test(ym)) {
- ym = Controller.api.currentYm();
- }
- params.ym = ym;
- return params;
- },
- columns: [
- [
- {field: 'ym', title: '月份', width: 88, operate: false},
- {field: 'CCYDH', title: '订单号', operate: 'LIKE'},
- {field: 'CYJMC', title: '印件名称', class: 'autocontent', operate: 'LIKE', formatter: Table.api.formatter.content},
- {field: 'CGYMC', title: '工序名称', class: 'autocontent', operate: 'LIKE', formatter: Table.api.formatter.content},
- {
- field: 'picked_supplier',
- title: '已选供应商',
- class: 'autocontent',
- operate: 'LIKE',
- formatter: Table.api.formatter.content
- },
- {field: 'createtime_text', title: '完结时间', width: 165, operate: 'LIKE'},
- {
- field: 'operate',
- title: '操作',
- width: 88,
- align: 'center',
- operate: false,
- formatter: function (value, row) {
- var sid = row && row.scydgy_id;
- if (!sid) {
- return '';
- }
- if (!exportCan('details')) {
- return '';
- }
- return '<a href="javascript:;" class="btn btn-xs btn-info btn-export-details" data-scydgy-id="' + sid + '" title="详情"><i class="fa fa-file-text-o"></i> 详情</a>';
- }
- }
- ]
- ]
- });
- Table.api.bindevent(table);
- $('.btn-refresh').off('click.procuremenExportRefresh').on('click.procuremenExportRefresh', function () {
- refreshTable();
- });
- $('#export-preview-ym').off('change.procuremenExportYm').on('change.procuremenExportYm', function () {
- refreshTable();
- });
- function buildMonthExportUrl(action) {
- var ym = ($('#export-preview-ym').val() || '').trim();
- if (!/^\d{4}-\d{2}$/.test(ym)) {
- Toastr.warning('请选择有效月份');
- return '';
- }
- var opts = table.bootstrapTable('getOptions') || {};
- var search = $.trim(opts.searchText || '');
- if (!search) {
- search = $.trim(table.closest('.bootstrap-table').find('.fixed-table-toolbar .search input').val() || '');
- }
- var filter = '';
- var op = '';
- try {
- var $cs = table.closest('.panel-intro').find('form.form-commonsearch');
- if ($cs.length) {
- var filterObj = {};
- var opObj = {};
- $cs.find('input[name], select[name]').each(function () {
- var $el = $(this);
- var name = ($el.attr('name') || '').trim();
- if (!name || name === 'search' || name.indexOf('[') >= 0) {
- return;
- }
- var val = $.trim($el.val() || '');
- if (val === '') {
- return;
- }
- filterObj[name] = val;
- var operate = $el.data('operate') || $el.attr('data-operate') || 'LIKE';
- opObj[name] = operate;
- });
- if (Object.keys(filterObj).length) {
- filter = JSON.stringify(filterObj);
- op = JSON.stringify(opObj);
- }
- }
- } catch (eFilter) {
- }
- var url = Fast.api.fixurl('procuremen/' + action + '?ym=' + encodeURIComponent(ym));
- if (search) {
- url += '&search=' + encodeURIComponent(search);
- }
- if (filter) {
- url += '&filter=' + encodeURIComponent(filter);
- }
- if (op) {
- url += '&op=' + encodeURIComponent(op);
- }
- return url;
- }
- $(document).off('click.procuremenExportMonth', '#btn-export-month-outward').on('click.procuremenExportMonth', '#btn-export-month-outward', function () {
- if (!exportCan('export_month_outward')) {
- Toastr.error('无导出权限');
- return;
- }
- var url = buildMonthExportUrl('export_month_outward');
- if (url) {
- window.open(url, '_blank');
- }
- });
- $(document).off('click.procuremenExportQuote', '#btn-export-month-quote').on('click.procuremenExportQuote', '#btn-export-month-quote', function () {
- if (!exportCan('export_month_quote') && !exportCan('export_month_outward')) {
- Toastr.error('无导出权限');
- return;
- }
- var url = buildMonthExportUrl('export_month_quote');
- if (url) {
- window.open(url, '_blank');
- }
- });
- $(document).off('click.procuremenExportDetails', '.btn-export-details').on('click.procuremenExportDetails', '.btn-export-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: ['100%', '100%']});
- });
- },
- api: {
- currentYm: function () {
- var d = new Date();
- return d.getFullYear() + '-' + ('0' + (d.getMonth() + 1)).slice(-2);
- },
- bindevent: function () {
- Form.api.bindevent($('form[role=form]'));
- }
- }
- };
- return Controller;
- });
|