| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'pingyinUntil', 'jstree'], function ($, undefined, Backend, Table, Form, pingyinUntil, jstree) {
- var Controller = {
- index: function () {
- $(".btn-detail").data("area", ['90%', '90%']);
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'stock/goods/index',
- add_url: 'stock/goods/add',
- edit_url: 'stock/goods/edit',
- del_url: 'stock/goods/del',
- import_url: 'stock/goods/import',
- multi_url: 'stock/goods/multi',
- detail_url: 'stock/goods/detail',
- table: 'stock_goods',
- }
- });
- var table = $("#table");
- var categoryids="";
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'goods.id',
- height: $(window).height() - 97,
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id'), },
- {field: 'goodscategory.name', title: __('goodscategory'), sortable: true},
- {field: 'volnum', title: __('volnum'), sortable: true},
- {field: 'goodsname', title: __('Goodsname'), sortable: true},
- {field: 'productmodel', title: __('Productmodel')},
- {field: 'barcode', title: __('Barcode')},
- {field: 'measureunit', title: __('Measureunit')},
- {field: 'univalence', title: '单桶重量(kg)', operate: 'BETWEEN'},
- {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
- {field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
- ]
- ],
- queryParams: function (params) {
- params.categoryids=categoryids
- return params;
- },
- onPostBody: function () {
- $(".btn-detailone").data("area", ['90%', '90%']);
- }
- });
- $(function () {
- var autoWidth = $(window).width() - 220;
- $('.table-content').css({'width': autoWidth, "position": "absolute", "left": "210px"});
- $("#treeview").jstree({
- "themes": {"stripes": true},
- "checkbox": {
- "keep_selected_style": true,
- "whole_node":false,
- three_state:false,
- },
- "plugins": ["checkbox"],
- "core": {
- 'check_callback': true,
- "data": {
- url: "stock/goodscategory/getjsTree",
- }
- }
- }).on("select_node.jstree deselect_node.jstree", function (e, data) {
- var treenode=$("#treeview").jstree(true);
- categoryids=treenode.get_checked().join(",");
- $("#table").bootstrapTable("refresh", {query: {categoryids: treenode.get_checked().join(",")}});
- });
- });
- // 出入明细事件
- $('.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]['id']}, table);
- Fast.api.open(url, __('Inoutdetail'), $(that).data() || {});
- } else {
- Toastr.error(selectedrow.length > 1 ? 'Only one record can be selected!' : 'Please select a record!')
- }
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- detail: function () {
- Table.api.init({
- extend: {
- detail_url: 'stock/goods/detail',
- },
- showFooter: true
- });
- var table = $("#table");
- // 初始化表格
- var ids = $('#c-ids').val();
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.detail_url,
- queryParams: function (params) {
- params.ids = ids;
- return params;
- },
- pk: 'id',
- sortName: 'a.riqi',
- height: $(window).height() - 97,
- columns: [
- [
- {checkbox: true},
- {
- field: 'leixing', title: __('InoutType'), sortable: true,
- footerFormatter: function () {
- return '';
- }
- },
- {
- field: 'volnum', title: __('Volnum'), sortable: true,
- footerFormatter: function () {
- return '';
- }
- },
- {
- field: 'goodsname', title: __('Goodsname'), sortable: true,
- footerFormatter: function () {
- return '';
- }
- },
- {
- field: 'productmodel', title: __('Productmodel'),
- footerFormatter: function () {
- return '';
- }
- },
- {
- field: 'measureunit', title: __('Measureunit'),
- footerFormatter: function () {
- return '';
- }
- },
- {
- field: 'univalence', title: '单桶重量(kg)', operate: 'BETWEEN',
- footerFormatter: function () {
- return '';
- }
- },
- {
- field: 'stockinnums', title: __('stockInNum'),
- footerFormatter: function (data) {
- if (data.length > 0) {
- return data[0].sum.totalstockinnums;
- }
- }
- },
- {
- field: 'stockinamount', title: '入库总重(kg)',
- footerFormatter: function (data) {
- if (data.length > 0) {
- return data[0].sum.totalstockinamount;
- }
- }
- },
- {
- field: 'stockoutnums', title: __('stockOutNum'),
- footerFormatter: function (data) {
- if (data.length > 0) {
- return data[0].sum.totalstockoutnums;
- }
- }
- },
- {
- field: 'stockoutamount', title: '出库总重(kg)',
- footerFormatter: function (data) {
- if (data.length > 0) {
- return data[0].sum.totalstockoutamount;
- }
- }
- },
- {
- field: 'riqi', title: __('InoutTime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime, datetimeFormat: "YYYY-MM-DD",
- footerFormatter: function () {
- return '';
- }
- },
- ]
- ]
- });
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- function getPinyin() {
- var value = document.getElementById('c-goodsname').value;
- var result = '';
- result = pinyinUtil.getFirstLetter(value, false);
- document.getElementById('c-spell').value = result;
- }
- document.getElementById('c-goodsname').addEventListener('input', getPinyin);
- //ajax请求根据商品类别产生商品商品代码
- function madevolnum() {
- if ($('#c-goodscategoryid').val() != "") {
- Fast.api.ajax({
- url: 'stock/goods/madevolnum',
- type: 'POST', //GET
- async: true, //或false,是否异步
- timeout: 5000, //超时时间
- dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
- data: {goodscategoryid: $('#c-goodscategoryid').val()}
- },
- function (data) {
- $('#c-volnum').val(data.volnum);
- $('#c-goodscategoryid').val(data.goodscategory);
- }
- );
- }
- }
- $('#c-goodscategoryid').change(madevolnum);
- }
- }
- };
- return Controller;
- });
|