define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { Table.api.init({ extend: { index_url: 'invoice/index' + location.search, detail_url: 'invoice/detail', edit_url: 'invoice/edit', table: 'invoice', } }); var table = $("#table"); table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', sortOrder: 'desc', fixedColumns: false, fixedRightNumber: 0, columns: [ [ {field: 'index', title: '序号', operate: false, formatter: Table.api.formatter.index, width: '55px'}, {field: 'invoice_sn', title: '申请单号', operate: 'LIKE'}, { field: 'title', title: '发票抬头 / 税号', operate: 'LIKE', align: 'left', formatter: function (v, row) { var html = '
' + Fast.api.escape(v || '-') + '
'; if (row.tax_no) { html += '
' + Fast.api.escape(row.tax_no) + '
'; } return html; } }, {field: 'tax_no', title: '税号', operate: 'LIKE', visible: false}, {field: 'title_type', title: '抬头类型', searchList: {"personal":__('Personal'),"enterprise":__('Enterprise')}, visible: false}, {field: 'type', title: '发票类型', searchList: {"normal":__('Ordinary'),"special":__('Special')}, formatter: Table.api.formatter.label, custom: {normal: 'info', special: 'warning'}}, {field: 'amount', title: '开票金额', operate: 'BETWEEN', formatter: function (v, row) { var ordTxt = Number(row.order_count) > 0 ? (row.order_count + ' 笔工单') : '按额度'; return '¥' + Number(v || 0).toFixed(2) + '
' + ordTxt + '
'; }}, { field: 'merchant.name', title: '申请主体 / 邮箱', operate: 'LIKE', align: 'left', formatter: function (value, row) { var nick = (row.user && row.user.nickname) ? Fast.api.escape(row.user.nickname) : ''; var main = value ? ('' + Fast.api.escape(value) + '') : (nick || '个人用户'); var sub = row.email ? Fast.api.escape(row.email) : (nick && value ? nick : '-'); return '
' + main + '
' + sub + '
'; } }, {field: 'user.nickname', title: '申请用户', operate: 'LIKE', visible: false}, {field: 'email', title: '接收邮箱', operate: 'LIKE', visible: false}, {field: 'status', title: '处理状态', searchList: {"wait":__('Wait'),"issued":__('Issued'),"reject":__('Reject'),"cancel":__('Cancel')}, formatter: Table.api.formatter.status, custom: {wait: 'warning', issued: 'success', reject: 'danger', cancel: 'gray'}}, {field: 'invoice_no', title: '发票号码 / 附件', operate: 'LIKE', formatter: function (v, row) { var html = v ? ('' + Fast.api.escape(v) + '') : '-'; if (row.invoice_file) { html += ' 电子票'; } return html; }}, {field: 'audit_msg', title: '处理说明', operate: 'LIKE', visible: false}, {field: 'createtime', title: '申请时间', operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime, width: '145px'}, {field: 'operate', title: '操作', table: table, events: Table.api.events.operate, buttons: [ { name: 'detail', text: '详情', title: '开票申请详情', classname: 'btn btn-xs btn-info btn-detailone', extend: 'data-area=\'["920px","86%"]\'' }, { name: 'edit', text: '开票处理', title: '财务开票处理', classname: 'btn btn-xs btn-success btn-editone', extend: 'data-area=\'["920px","86%"]\'', visible: function (row) { return row.status === 'wait'; } } ], formatter: Table.api.formatter.operate} ] ] }); Table.api.bindevent(table); }, edit: function () { $(document).on('change', 'input[name="row[status]"]', function () { var val = $(this).val(); if (val === 'reject') { $('#box-issued-fields').slideUp(150); } else { $('#box-issued-fields').slideDown(150); } }); Controller.api.bindevent(); }, detail: function () { Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); } } }; return Controller; });