| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- 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',
- pagination: true,
- pageSize: Config.pagesize || localStorage.getItem('pagesize') || 20,
- pageList: [10, 15, 20, 25, 50],
- showJumpto: true,
- commonSearch: false,
- search: false,
- columns: [
- [
- {field: 'ym', title: '月份', width: 88},
- {field: 'CCYDH', title: '订单号'},
- {field: 'CYJMC', title: '印件名称', class: 'autocontent', formatter: Table.api.formatter.content},
- {field: 'CGYMC', title: '工序名称', class: 'autocontent', formatter: Table.api.formatter.content},
- {field: 'createtime_text', title: '完结时间', width: 165},
- {field: 'row_count', title: '工序数', width: 72, align: 'center'},
- {field: 'total_amount', title: '金额合计', formatter: function (value, row) {
- return row.total_amount_text != null && row.total_amount_text !== ''
- ? row.total_amount_text
- : (value != null ? String(value) : '');
- }},
- {
- field: 'operate',
- title: '操作',
- width: 88,
- align: 'center',
- 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();
- });
- $(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 ym = ($('#export-preview-ym').val() || '').trim();
- if (!/^\d{4}-\d{2}$/.test(ym)) {
- Toastr.warning('请选择有效月份');
- return;
- }
- var url = Fast.api.fixurl('procuremen/export_month_outward?ym=' + encodeURIComponent(ym));
- 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: ['92%', '88%']});
- });
- },
- 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;
- });
|