123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- search: false,
- commonSearch: true,
- searchFormVisible: true,
- extend: {
- index_url: 'goods/index' + location.search,
- add_url: 'goods/add',
- edit_url: 'goods/edit',
- del_url: 'goods/del',
- multi_url: 'goods/multi',
- import_url: 'goods/import',
- table: 'goods',
- merge_url: 'goods/merge',
- buy_url: 'goods/buy',
- }
- });
- var table = $("#table");
- let mergeAuth=table.data('merge-set')===1;
- let buyAuth=table.data('buy-set')===1;
- $(document).on('click','.btn-merge-set',function (){
- Fast.api.open($.fn.bootstrapTable.defaults.extend.merge_url+`/ids/${$(this).data('id')}`,'合成设置')
- })
- $(document).on('click','.btn-buy-set',function (){
- Fast.api.open($.fn.bootstrapTable.defaults.extend.buy_url+`/ids/${$(this).data('id')}`,'提前购买设置')
- })
- //给添加按钮添加`data-area`属性
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- fixedColumns: true,
- fixedRightNumber: 1,
- columns: [
- [
- {field: 'id', title: __('Id'), operate: false},
- {field: 'name', title: __('Name'), operate: 'LIKE'},
- {field: 'goodscategory.name', title: __('Goodscategory.name'), operate: false},
- {field: 'goods_category_id', title: __('Goodscategory.name'), visible:false,searchList: $.getJSON('goods_category/list')},
- {field: 'author.name', title: __('Author.name'), operate: false},
- {field: 'author_id', title: __('Author.name'),visible:false,searchList: $.getJSON('author/list')},
- {field: 'network.name', title: __('Network.name'), operate: false},
- {field: 'network_id', title: __('Network.name'), visible:false,searchList: $.getJSON('network/list')},
- {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
- // {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
- {field: 'price', title: __('Price'), operate:false},
- // {field: 'desc', title: __('Desc'), operate: 'LIKE'},
- // {field: 'attribute', title: __('Attribute'), operate: false},
- // {field: 'contract', title: __('Contract'), operate: 'LIKE'},
- {field: 'meta_data', title: __('Meta_data'), operate: 'LIKE'},
- {field: 'order', title: __('Order'), operate: false},
- {field: 'stock', title: __('Stock'), operate: false},
- {field: 'sales', title: __('Sales'), operate: false},
- {field: 'surplus', title: __('Surplus'), operate: false},
- {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
- // {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
- {field: 'is_show', title: __('Is_show'), searchList: {"0":__('Is_show 0'),"1":__('Is_show 1')}, formatter: Table.api.formatter.normal},
- {
- field:'',
- title:'合成',
- operate: false,
- formatter(aa,info){
- let a=[],names=[]
- info.merge.forEach(item=>{
- if(item.goods) {
- names.push(`${item.goods.name}(${item.num})`)
- }
- })
- a.push(`<div>开启合成:${info.merge_open?`<span class="text-red">是</span>`:'否'}</div>`)
- a.push(`<div>所需藏品:<div style="color: #00caff">${names.join('<br>')}</div></div>`)
- if(mergeAuth) {
- a.push(`<div><a class="btn btn-success btn-sm btn-merge-set" data-id="${info.id}">设置</a></div>`)
- }
- return a.join('')
- },
- align:'left',
- valign:'top',
- },
- {
- field:'',
- title:'提前购买',
- operate: false,
- formatter(aa,info){
- let a=[],names=[]
- info.buy.forEach(item=>{
- if(item.goods) {
- names.push(`${item.goods.name}(${item.num})`)
- }
- })
- let open=''
- if(info.buy_type===0){
- open='未开启'
- }else if(info.buy_type===1){
- open='提前购买'
- }else if(info.buy_type===2){
- open='空头'
- }
- a.push(`<div>开启方式:${open}</div>`)
- a.push(`<div>时间:${info.buy_before_time}</div>`)
- a.push(`<div>限购:${info.buy_before_user_limit||0}</div>`)
- a.push(`<div style="color: #00caff;">所需藏品:${names.join('')}</div>`)
- if(buyAuth) {
- a.push(`<div><a class="btn btn-success btn-sm btn-buy-set" data-id="${info.id}">设置</a></div>`)
- }
- return a.join('')
- },
- align:'left',
- valign:'top',
- },
- {field:'merge_open',operate: '=',title:'开启合成',searchList: {0:'未开启',1:'开启'},visible: false},
- // {field: 'is_home', title: __('Is_home'), searchList: {"0":__('Is_home 0'),"1":__('Is_home 1')}, formatter: Table.api.formatter.normal},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
- /* buttons:[
- {
- name: 'merge',
- text: '合成设置',
- title: '合成设置',
- classname: 'btn btn-primary btn-dialog btn-sm',
- url: 'goods/merge',
- visible:function(row){
- return $('#table').data('merge-set')===1; //或者return false
- },
- callback: function (data) {
- $(".btn-refresh").trigger("click");
- }
- }
- ]*/
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- merge: function () {
- Controller.api.bindevent();
- $('.btn-add-goods').click(function (){
- goodsNum++
- let a=$('#goodsTemp').html()
- a=a.replace(/\$key/gi,goodsNum)
- $('.form-group-add-btn-field').before(a)
- Controller.api.bindevent();
- })
- $(document).on('click','.goods-one-delete',function (){
- $(this).parents('.goods-one').remove()
- })
- },
- buy: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|