define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'orders/configorder/index' + location.search, //add_url: 'orders/configorder/add', edit_url: 'orders/configorder/edit', // del_url: 'orders/configorder/del', multi_url: 'orders/configorder/multi', import_url: 'orders/configorder/import', table: 'order', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', fixedColumns: true, fixedRightNumber: 1, columns: [ [ {field: 'id', title: __('Id')}, {field: 'order_no', title: __('Order_no'), operate: '='}, // {field: 'customer', title: __('Customer'), operate: 'LIKE'}, //{field: 'tel', title: __('Tel'), operate: 'LIKE'}, //{field: 'dispatch.worker_name', title: __('Dispatch.worker_name'), operate: 'LIKE'}, //{field: 'dispatch.worker_tel', title: __('Dispatch.worker_tel'), operate: 'LIKE'}, {field: 'dispatchadmin.nickname', title: __('Dispatch.admin_user'), operate: false}, {field: 'dispatch_admin_id', title: __('派单员'), searchList:$.getJSON("orders/configorder/getadminuser"),operate: 'IN',visible:false}, {field: 'status', title: __('Status'), searchList: {"40":__('Status 40'),"41":__('Status 41')}, formatter: Table.api.formatter.status}, {field: 'audit_remark', title: __('审核备注'), operate:false}, // {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, {field: 'source_total_name', title: __('Source_shop'), operate: false}, // {field: 'source', title: __('Source')}, // {field: 'source_uid', title: __('Source_uid'), operate: 'LIKE'}, {field: 'item_title', title: __('Item_title'), operate: false}, {field: 'total', title: __('Total'), operate:false}, {field: 'online_amount', title: __('Online_amount'), operate:false}, {field: 'online_amount_last', title: __('Online_amount_last'), operate:false}, {field: 'offline_amount', title: __('Offline_amount'), operate:false}, {field: 'offline_amount_type_text', title: __('Offline_amount_type'), operate:false}, { field: 'source', title: '订单渠道', searchList: function (column) { return Template('source', {}); }, formatter: function (value, row, index) { return '无'; }, visible: false }, {field: 'refund_amount', title: __('Refund_amount'), operate:false}, {field: 'real_amount', title: __('Real_amount'), operate:false}, {field: 'cost', title: __('Cost'), operate:false}, { field: 'material_cost_text', title: '材料成本', operate: false, cellStyle: {css: {"text-align": "left !important"}}, formatter: function (val, row) { if (row.is_material_used === 1) { return `¥${row.material_cost}` } return '无' }}, {field: 'material_images', title: __('材料凭证'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images}, {field: 'performance', title: __('Performance'), operate:false}, // {field: 'dispatch_type', title: __('Dispatch_type')}, {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, {field: 'update_time', title: __('Update_time'), operate:false, addclass:'datetimerange', autocomplete:false}, // {field: 'dispatch.finish_time', title: __('Dispatch.finish_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, buttons: [ { name: 'edit', text:"配置", title:"配置订单", icon: 'fa fa-pencil', //title: __('Edit'), extend: 'data-toggle="tooltip" data-container="body"', classname: 'btn btn-xs btn-success btn-editone', /*visible:function(row){ if(row.status == 50){ return true; } return false; }*/ } ], } ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { Controller.api.bindevent(); }, edit: function () { Controller.api.bindevent(); // 浮点数转两位小数(避免精度问题) function toFixedNum(num) { return (Math.round((num + Number.EPSILON) * 100) / 100).toFixed(2); } // 利润计算函数 function calcProfit() { var online = parseFloat($('#c-online_amount').val()) || 0; var online2 = parseFloat($('#c-online_amount_last').val()) || 0; var offline = parseFloat($('#c-offline_amount').val()) || 0; var cost = parseFloat($('#c-cost').val()) || 0; var material = parseFloat($('#c-material_cost').val()) || 0; var profit = online + online2 + offline - cost - material; $('#c-performance').val(toFixedNum(profit)); } // 监听字段变化,实时计算利润 $('#c-online_amount_last, #c-offline_amount, #c-cost, #c-material_cost').on('input', function () { calcProfit(); }); // 页面加载时自动计算一次利润,避免空白 calcProfit(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); } } }; return Controller; });