123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'wwh/archives/index' + location.search,
- add_url: 'wwh/archives/add',
- edit_url: 'wwh/archives/edit',
- del_url: 'wwh/archives/del',
- multi_url: 'wwh/archives/multi',
- import_url: 'wwh/archives/import',
- table: 'wwh_archives',
- dragsort_url:'',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'weigh',
- fixedColumns: true,
- fixedRightNumber: 1,
- columns: [
- [
- {
- checkbox: true, formatter:function (value,row,index){
- if (row.status == 1){
- return{
- disabled:true
- };
- }
- }
- },
- {field: 'id', title: __('Id')},
- {
- field: 'column',
- title: __('Column_id'),
- formatter: function (val,data) {
- var lang = data.lang == 2?val.e_name:val.name;
- return lang;
- }
- },
- {
- field: 'column_id',
- title: __('Column_id'),
- visible: false,
- addclass: 'selectpage',
- extend: 'data-source="wwh/column/index" data-field="name"',
- operate: 'in',
- formatter: Table.api.formatter.search
- },
- {
- field: 'title', title: __('Title'), align: 'left', operate: 'like', customField: 'rec_data', formatter: function (value, row, index) {
- var flagObj = $.extend({}, this, {searchList: {"0":__('Rec_data 0'),"1":__('Rec_data 1'),"10":__('Rec_data 10')},custom: {0: 'primary', 1: 'success', 10: 'warning'}});
- if (row.rec_data == 0){
- return '<div class="archives-title"><a href="' + row.url + '" target="_blank"><span style="color:' + (row.style_color ? row.style_color : 'inherit') + ';font-weight:' + (row.style_bold ? 'bold' : 'normal') + '">' + value + '</span></a></div>';
- } else {
- return '<div class="archives-title"><a href="' + row.url + '" target="_blank"><span style="color:' + (row.style_color ? row.style_color : 'inherit') + ';font-weight:' + (row.style_bold ? 'bold' : 'normal') + '">' + value + '</span></a></div>' +
- '<div class="archives-label">' + Table.api.formatter.flag.call(flagObj, row['rec_data'], row, index) + '</div>';
- }
- }
- },
- {field: 'rec_data', title: __('Rec_data'), operate: 'find_in_set', visible: false, searchList: Config.recDataList, formatter: Table.api.formatter.flag},
- {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
- {
- field: 'weigh',
- title: __('Weigh'),
- operate: false,
- sortable: true,
- formatter: function (value, row, index) {
- return '<input type="text" class="form-control text-center text-weigh" data-id="' + row.id + '" value="' + value + '" style="width:50px;margin:0 auto;" />';
- },
- events: {
- "dblclick .text-weigh": function (e) {
- e.preventDefault();
- e.stopPropagation();
- return false;
- }
- }
- },
- {field: 'views', title: __('Views')},
- {field: 'time', title: __('Time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
- {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, custom: {0: 'grey', 1: 'info'}, formatter: Table.api.formatter.flag},
- {field: 'lang', title: __('Lang'), searchList: {"1":__('Lang 1'),"2":__('Lang 2')}, custom: {1: 'success', 2: 'warning'}, formatter: Table.api.formatter.normal},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
- buttons: [
- {
- name: 'faudit',
- text: __('反审核'),
- title: __('反审核'),
- classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
- // icon: 'fa fa-close',
- url: 'wwh/archives/faudit',
- hidden:function(row){
- if(row.status != '1'){
- return true;
- }
- },
- success: function (data, ret) {
- table.bootstrapTable('refresh'); //自动刷新
- },
- }
- ],
- formatter: function (value, row, index) {
- var that = $.extend({}, this);
- var table = $(that.table).clone(true);
- if (row.status == 1){
- $(table).data("operate-edit",null);
- $(table).data("operate-del",null);
- }
- that.table = table;
- return Table.api.formatter.operate.call(that, value, row, index);
- }}
- ]
- ]
- });
- // 权重修改
- $(document).on("change", ".text-weigh", function () {
- $(this).data("params", {weigh: $(this).val()});
- Table.api.multi('', [$(this).data("id")], table, this);
- return false;
- });
- // 审核
- $(document).on("click", ".btn-audit", function () {
- var data = table.bootstrapTable('getSelections');
- var ids = [];
- if (data.length === 0) {
- Toastr.error("请选择操作信息");
- return;
- }
- for (var i = 0; i < data.length; i++) {
- ids[i] = data[i]['id']
- }
- Layer.confirm(
- '确认选中'+ids.length+'条审核吗?',
- {icon: 3, title: __('Warning'), offset: '40%', shadeClose: true},
- function (index) {
- Layer.close(index);
- Backend.api.ajax({
- url: "wwh/archives/audit",
- data: {ids:ids}
- }, function(data, ret){//成功的回调
- if (ret.code === 1) {
- table.bootstrapTable('refresh');
- Layer.close(index);
- } else {
- Layer.close(index);
- Toastr.error(ret.msg);
- }
- }, function(data, ret){//失败的回调
- console.log(ret);
- Layer.close(index);
- });
- }
- );
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- // 弹窗窗口大小
- table.on('post-body.bs.table',function(e, settings, json, xhr){
- $(".btn-add").data("area", ['80%','80%']);
- $(".btn-editone").data("area", ['80%','80%']);
- });
- // TAB选项卡默认选中简体中文
- $('ul.nav-tabs li a[data-toggle="tab"]').eq(0).trigger("click");
- // 获取TAB选项卡值,通过options.extend.add_url传递
- $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
- var options = table.bootstrapTable('getOptions');
- options.extend.add_url = 'wwh/archives/add?lang=' + $(this).data('value');
- });
- $(document).on("click", "a.btn-column", function () {
- $("#archivespanel").toggleClass("col-md-9", $("#columnbar").hasClass("hidden"));
- $("#archivespanel").toggleClass("col-full-width", !$("#columnbar").hasClass("hidden"));
- $("#columnbar").toggleClass("hidden");
- });
- require(['jstree'], function () {
- // 全选和展开
- $(document).on("click", "#checkall", function () {
- $("#columntree").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
- });
- $(document).on("click", "#expandall", function () {
- $("#columntree").jstree($(this).prop("checked") ? "open_all" : "close_all");
- });
- $('#columntree').on("changed.jstree", function (e, data) {
- $(".commonsearch-table input[name=column_id]").val(data.selected.join(","));
- table.bootstrapTable('refresh', {});
- return false;
- });
- $('#columntree').jstree({
- "themes": {
- "stripes": true
- },
- "checkbox": {
- "keep_selected_style": false,
- },
- "types": {
- "column": {
- "icon": false,
- },
- "list": {
- "icon": false,
- },
- "link": {
- "icon": false,
- },
- "disabled": {
- "check_node": false,
- "uncheck_node": false
- }
- },
- 'plugins': ["types", "checkbox"],
- "core": {
- "multiple": true,
- 'check_callback': true,
- "data": Config.columnList
- }
- });
- });
- },
- add: function () {
- // 将TAB选项卡赋值给lang
- $('#c-lang option').each(function(){
- if($(this).attr('value') == Fast.api.query('lang'))
- {
- $(this).attr('selected', 'selected');
- }
- });
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- $("input[name='row[type]']:checked").trigger("fa.event.typeupdated", "edit");
- },
- api: {
- formatter: {
- subnode: function (value, row, index) {
- return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Toggle sub menu') + '" data-id="' + row.id + '" data-parent_id="' + row.parent_id + '" class="btn btn-xs '
- + (row.haschild == 1 || row.ismenu == 1 ? 'btn-success' : 'btn-default disabled') + ' btn-node-sub"><i class="fa fa-' + (row.haschild == 1 || row.ismenu == 1 ? 'sitemap' : 'list') + '"></i></a>';
- }
- },
- bindevent: function () {
- // 根据类型显示隐藏对应字段
- $(document).on("click fa.event.typeupdated", "input[name='row[type]']", function (e, ref) {
- $(".tf").addClass("hidden");
- $(".tf.tf-" + $(this).val()).removeClass("hidden");
- });
- // 不验证隐藏元素
- $('form[role=form]').data("validator-options", {
- ignore: ':hidden'
- });
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|