123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'qingdongams/product/goods/index' + location.search,
- add_url: 'qingdongams/product/goods/add',
- edit_url: 'qingdongams/product/goods/edit',
- detail_url: 'qingdongams/product/goods/detail',
- multi_url: 'qingdongams/product/goods/multi',
- import_url: 'qingdongams/product/goods/import',
- table: 'qingdongams_goods',
- }
- });
- var isselect=false;
- var pselect = true;
- var q = {};
- location.search.replace(/([^?&=]+)=([^&]+)/g,(_,k,v)=>q[k]=v);
- if (q.isselect == 1) {
- isselect= true;
- pselect = false;
- }
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {
- field : 'name', title : '商品名称', operate : 'like', fixedColumns : true, formatter : function (value, row, index) {
- return "<a href='javascript:void(0);' data-id='" + row.id + "' class='show-goods' >" + value + "</a>";
- }
- },
- {
- field: 'type.name', title: '商品分类', operate: false
- },
- {field: 'type_id', title: __('商品分类'), searchList: $.getJSON("qingdongams/product/goods/get_product_type"),visible:false},
- {field: 'cost_price', title: __('采购价'), operate: 'LIKE'},
- {field: 'unit', title: __('单位'), operate: 'LIKE'},
- {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- {
- field: 'operate2', title: __('Operate'),visible:isselect, events: {
- 'click .btn-chooseone': function (e, value, row, index) {
- Fast.api.close(row);
- },
- }, formatter: function () {
- return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
- }
- },
- {
- field: 'operate', title: __('Operate'),table: table,visible:pselect,
- events: Table.api.events.operate, formatter: Table.api.formatter.buttons,
- buttons: [
- {
- name: 'edit',
- text: __('编辑'),
- title: __('编辑'),
- extend:'data-area=["90%","90%"]',
- classname: 'records btn-dialog',
- url: 'qingdongams/product/goods/edit',
- },
- {
- name: 'detail',
- text: __('详情'),
- title: __('详情'),
- extend:'data-area=["95%","95%"]',
- classname: 'records btn-dialog',
- url: 'qingdongams/product/goods/detail',
- },
- ]
- },
- ]
- ],
- search:false,
- //启用普通表单搜索
- commonSearch : true,
- searchFormVisible:true,
- showSearch : true,
- pageSize : 10,
- onLoadSuccess: function () {
- // 这里就是数据渲染结束后的回调函数
- $(".btn-add").data("area", ["90%", "90%"]);
- $(".btn-edit").data("area", ["90%", "90%"]);
- }
- });
- $(document).on('click', '.show-goods', function (data) {
- var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
- var options = {
- shadeClose : false,
- shade : [0.3, '#393D49'],
- area : area,
- refresh:true,
- callback : function (value) {
- //在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
- },
- end:function (){
- $('.btn-refresh').trigger('click');
- }
- };
- Fast.api.open($.fn.bootstrapTable.defaults.extend.detail_url + "?ids=" + $(this).data('id'), '商品详情', options);
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- recyclebin: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- 'dragsort_url': ''
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: 'qingdongams/product/goods/recyclebin' + location.search,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'name', title: __('Name'), align: 'left'},
- {
- field: 'deletetime',
- title: __('Deletetime'),
- operate: 'RANGE',
- addclass: 'datetimerange',
- formatter: Table.api.formatter.datetime
- },
- {
- field: 'operate',
- width: '130px',
- title: __('Operate'),
- table: table,
- events: Table.api.events.operate,
- buttons: [
- {
- name: 'Restore',
- text: __('Restore'),
- classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
- icon: 'fa fa-rotate-left',
- url: 'qingdongams/product/goods/restore',
- refresh: true
- },
- {
- name: 'Destroy',
- text: __('Destroy'),
- classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
- icon: 'fa fa-times',
- url: 'qingdongams/product/goods/destroy',
- refresh: true
- }
- ],
- formatter: Table.api.formatter.operate
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- $(document).on('change','input[name="row[specs_type]"]',function (){
- var specs = $(this).val();
- if(specs == 1){
- $('.specesinfo').show();
- $('.goodsinfo').hide();
- }else{
- $('.specesinfo').hide();
- $('.goodsinfo').show();
- }
- });
- Controller.api.bindevent();
- },
- edit: function () {
- //后续操作
- var ids = $('#ids').val();
- var specs_id=$("#specs_id").val();
- var price=$('#c-price').val();
- $.post('qingdongams/product/goods/get_specs_detail',{specs_id:specs_id,ids:ids},function (data){
- if(data.code == 1){
- var result=[];
- var specslist='';
- $.each(data.data,function (index,params){
- params.type=params.name;
- params.name='['+params.name+']';
- params.price=price;
- params.remarks="";
- params.avatar="";
- params.index=index;
- result.push(params);
- var dataparams=JSON.stringify(params);
- if(params.check && params.check == 1){
- specslist+='<a class="label label-default label-specs label-info" data-params=\''+dataparams+'\' data-id="'+index+'" data-show="1" checked="checked">'+params.name+'</a> ';
- }else{
- specslist+='<a class="label label-default label-specs" data-params=\''+dataparams+'\' data-id="'+index+'" data-show="0" >'+params.name+'</a> ';
- }
- });
- $('#specslist').html(specslist);
- }
- },'json');
- $(document).on('change','input[name="row[specs_type]"]',function (){
- var specs = $(this).val();
- if(specs == 1){
- $('.specesinfo').show();
- $('.goodsinfo').hide();
- }else{
- $('.specesinfo').hide();
- $('.goodsinfo').show();
- }
- });
- Controller.api.bindevent();
- },
- import: function () {
- Controller.api.bindevent();
- },
- detail: function () {
- // 初始化表格参数配置
- Table.api.init({});
- var id = $('#ids').val();
- //产品信息
- var table1 = $("#operation_product");
- // 初始化表格
- table1.bootstrapTable({
- url : 'qingdongams/product/goods/get_product?goods_id=' +id,
- pk : 'id',
- sortName : 'id',
- toolbar: '#toolbar_product',
- operate : false,
- commonSearch : false,
- search : false,
- visible : false,
- showColumns : false,
- showExport : false,
- showToggle : false,
- columns : [
- [
- {
- field : 'producttype.name', title : '产品分类'
- },
- {
- field : 'name', title : '产品名称', operate : 'like', fixedColumns : true, formatter : function (value, row, index) {
- return "<a href='javascript:void(0);' class='btn-dialog' " +
- "data-url='qingdongams/product/product/detail/ids/"+row.id+"' data-shade='0.3' data-title='产品详情' >" + value + "</a>";
- }
- },
- {field : 'num', title : '产品编码', operate : 'like'},
- {field: 'img', title: '产品图片', operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
- {field : 'unit', title : '产品单位', operate : false},
- {field : 'price', title : '零售价', operate : false},
- {field : 'wholesale', title : '批发价', operate : false},
- {field : 'cost_price', title : '采购价', operate : false},
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table1);
- //编辑
- $(document).on('click','.btn-edit',function () {
- var id=$('#ids').val();
- Fast.api.open("qingdongams/product/goods/edit?ids="+id, "编辑",{
- shadeClose: false,
- shade: false,
- maxmin: false,
- moveOut: false,
- scrollbars:false,
- 'area':['90%','90%'],
- callback:function () {
- location.reload()
- }
- });
- });
- $(document).on('click', ".btn-del", function () {//删除
- var id = $('#ids').val();
- Layer.confirm('确定删除当前商品吗?', {
- btn : ['确定', '取消'],
- title : '提示',
- }, function (index, layero) {
- Fast.api.ajax("qingdongams/product/goods/del?ids=" + id, function (data, ret) {
- if (ret.code == 1) {
- Layer.close(index);
- parent.location.reload();
- }
- }, function (data, ret) {
- });
- });
- });
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- $(document).on("fa.event.appendfieldlist", '.fieldlist', function(){
- //通用的表单组件事件绑定和组件渲染
- Form.events.selectpage($("form"));
- Form.events.plupload($("form"));
- });
- $("#specs_id").data("eSelect", function(){
- //后续操作
- var specs_id=$("#specs_id").val();
- var price=$('#c-price').val();
- $.post('qingdongams/product/goods/get_specs_detail',{specs_id:specs_id},function (data){
- if(data.code == 1){
- var result=[];
- var specslist='';
- $.each(data.data,function (index,params){
- params.type=params.name;
- params.name='['+params.name+']';
- params.price=price;
- params.remarks="";
- params.avatar="";
- params.index=index;
- result.push(params);
- var dataparams=JSON.stringify(params);
- specslist+='<a class="label label-default label-specs" data-params=\''+dataparams+'\' data-id="'+index+'" data-show="0" >'+params.name+'</a> ';
- });
- $('#specslist').html(specslist);
- }
- },'json');
- });
- $(document).on('click','.label-specs',function (){
- var is_show=$(this).attr('data-show');
- var product=$('textarea[name="row[product]"]').val();
- if(is_show == 1){
- $(this).attr({'data-show':0});
- $(this).removeClass('label-info');
- var id=$(this).data('id');
- product=JSON.parse(product);
- var result=[];
- $.each(product,function (index,params){
- if(params.index != id){
- result.push(params);
- }
- });
- result=JSON.stringify(result);
- $('textarea[name="row[product]"]').val(result);
- $(".fieldlist").trigger("fa.event.refreshfieldlist");
- $('textarea[name="row[product]"]').trigger("fa.event.refreshfieldlist");
- }else{
- $(this).addClass('label-info');
- $(this).attr({'data-show':1});
- var params=$(this).data('params');
- product=JSON.parse(product);
- product.push(params);
- var res=JSON.stringify(product);
- $('textarea[name="row[product]"]').val(res);
- $(".fieldlist").trigger("fa.event.refreshfieldlist");
- $('textarea[name="row[product]"]').trigger("fa.event.refreshfieldlist");
- }
- });
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|