define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form, jstree, Echarts, undefined) { var Controller = { index: function () { $(".btn-detail").data("area", ['90%', '90%']); // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'stock/stockcur/index', add_url: 'stock/stockcur/add', edit_url: 'stock/stockcur/edit', del_url: 'stock/stockcur/del', multi_url: 'stock/stockcur/multi', table: 'stock_stockcur', } }); var table = $("#table"); $(function () { var autoWidth = $(window).width() - 220; $('.table-content').css({ 'width': autoWidth, "position": "absolute", "left": "210px" }); $("#treeview").jstree({ "themes": { "stripes": true }, "checkbox": { "keep_selected_style": false, }, "plugins": ["checkbox"], "core": { 'check_callback': true, "data": { url: "stock/goodscategory/getjsTree", } } }).on("select_node.jstree deselect_node.jstree", function (e, data) { $("#table").bootstrapTable("refresh", { query: { categoryids: data.selected.join(",") } }); }); $.fn.bootstrapTable.locales[Table.defaults.locale]['formatSearch'] = function () { return '搜索[商品代码、商品名]'; }; }); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', height: $(window).height() - 97, columns: [ [ { checkbox: true }, { field: 'id', title: __('Id'), width: 50, searchable: false }, { field: 'stockgoods.volnum', title: __('商品代码'), sortable: true, operate: "LIKE" }, { field: 'stockgoods.goodsname', title: __('stock_goods.goodsname'), sortable: true, operate: "LIKE" }, { field: 'stockgoods.productmodel', title: '型号', searchable: false }, { field: 'stockgoods.measureunit', title: '单位', searchable: false }, { field: 'stockgoods.univalence', title: '单桶重量', searchable: false }, { field: 'totalcurnums', title: __('库存数量'), searchable: false }, ] ] }); // 为表格绑定事件 Table.api.bindevent(table); // 出入明细事件 $('.btn-detail').click(function (event) { var that = this; var selectedrow = table.bootstrapTable('getSelections'); if (selectedrow.length == 1) { var url = 'stock/goods/detail'; var url = Table.api.replaceurl(url, { ids: selectedrow[0]['stock_goods_id'] }, table); Fast.api.open(url, __('出入明细'), $(that).data() || {}); } else { Toastr.error(selectedrow.length > 1 ? '只能选择一条记录' : '请选择一条记录') } }); }, mainpage: function () { var goodscategory_list = []; var linechartdata = []; //商品分类 $.ajax({ url: 'stock/goodscategory/category', type: 'GET', //GET async: false, //或false,是否异步 timeout: 5000, //超时时间 dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text success: function (data) { goodscategory_list = []; if (data) { for (var i = 0; i < data.length; i++) { var value = data[i]['id']; goodscategory_list[value] = data[i]['name']; } } } }); //库存饼状图 $.ajax({ url: 'stock/stockcur/countData', type: 'POST', //GET async: true, //或false,是否异步 timeout: 5000, //超时时间 dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text success: function (data) { var datalist = data.rows; var legendData = []; for (var i = 0; i < datalist.length; i++) { legendData.push(goodscategory_list[datalist[i]['stock_goods']['goodscategoryid']]); } var totalItemAmount = []; var totalAmount = 0; for (var i = 0; i < datalist.length; i++) { totalItemAmount[i] = { 'value': datalist[i].totalitemamount, 'name': goodscategory_list[datalist[i]['stock_goods']['goodscategoryid']] }; totalAmount += parseFloat(datalist[i].totalitemamount); } var totalNum = []; var totalNumAdd = 0; for (var i = 0; i < datalist.length; i++) { totalNum[i] = { 'value': datalist[i].totalnum, 'name': goodscategory_list[datalist[i]['stock_goods']['goodscategoryid']] }; totalNumAdd += parseFloat(datalist[i].totalnum); } madePie(legendData, totalItemAmount, 'stockcur_amount', '库存重量', '库存总重量' + totalAmount.toFixed(2) + '千克'); madePie(legendData, totalNum, 'stockcur_num', '库存总件数', '库存共' + totalNumAdd + '件'); } }); function madePie(legendData, seriesData, elementId, titleText, titleSubText) { var myChart = Echarts.init(document.getElementById(elementId), 'walden'); var option = { title: { text: titleText, subtext: titleSubText, x: 'center' }, tooltip: { trigger: 'item', formatter: "{b} : {c} ({d}%)" }, legend: { orient: 'vertical', x: 'left', data: legendData, }, toolbox: { show: true, feature: { mark: { show: true }, dataView: { show: true, readOnly: false }, magicType: { show: true, type: ['pie', 'funnel'], option: { funnel: { x: '25%', width: '50%', funnelAlign: 'left', max: 1548 } } }, restore: { show: true }, saveAsImage: { show: true } } }, calculable: true, series: [{ type: 'pie', radius: '55%', center: ['50%', '60%'], data: seriesData, }] }; myChart.setOption(option); }; //折线图 $.ajax({ url: 'stock/stockin/countData', type: 'POST', //GET async: true, //或false,是否异步 timeout: 5000, //超时时间 dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text success: function (data) { linechartdata=data; var myChart = Echarts.init(document.getElementById('linechart'), 'walden'); var option = { title: { text: '出入库重量折线图', subtext: '' }, legend: { data: ["入库重量", "出库重量"] }, xAxis: { type: 'category', boundaryGap: false, data: linechartdata.month, axisLabel:{ interval:0, rotate:45 } }, yAxis: { type: 'value' }, series: [{ name: "入库重量", type: 'line', smooth: true, data: linechartdata.indata }, { name: "出库重量", type: 'line', smooth: true, data: linechartdata.outdata }] }; myChart.setOption(option); } }); }, add: function () { Controller.api.bindevent(); }, edit: function () { Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); } } }; return Controller; });