archives.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'wwh/archives/index' + location.search,
  8. add_url: 'wwh/archives/add',
  9. edit_url: 'wwh/archives/edit',
  10. del_url: 'wwh/archives/del',
  11. multi_url: 'wwh/archives/multi',
  12. import_url: 'wwh/archives/import',
  13. table: 'wwh_archives',
  14. dragsort_url:'',
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'weigh',
  23. fixedColumns: true,
  24. fixedRightNumber: 1,
  25. columns: [
  26. [
  27. {
  28. checkbox: true, formatter:function (value,row,index){
  29. if (row.status == 1){
  30. return{
  31. disabled:true
  32. };
  33. }
  34. }
  35. },
  36. {field: 'id', title: __('Id')},
  37. {
  38. field: 'column',
  39. title: __('Column_id'),
  40. formatter: function (val,data) {
  41. var lang = data.lang == 2?val.e_name:val.name;
  42. return lang;
  43. }
  44. },
  45. {
  46. field: 'column_id',
  47. title: __('Column_id'),
  48. visible: false,
  49. addclass: 'selectpage',
  50. extend: 'data-source="wwh/column/index" data-field="name"',
  51. operate: 'in',
  52. formatter: Table.api.formatter.search
  53. },
  54. {
  55. field: 'title', title: __('Title'), align: 'left', operate: 'like', customField: 'rec_data', formatter: function (value, row, index) {
  56. var flagObj = $.extend({}, this, {searchList: {"0":__('Rec_data 0'),"1":__('Rec_data 1'),"10":__('Rec_data 10')},custom: {0: 'primary', 1: 'success', 10: 'warning'}});
  57. if (row.rec_data == 0){
  58. 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>';
  59. } else {
  60. 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>' +
  61. '<div class="archives-label">' + Table.api.formatter.flag.call(flagObj, row['rec_data'], row, index) + '</div>';
  62. }
  63. }
  64. },
  65. {field: 'rec_data', title: __('Rec_data'), operate: 'find_in_set', visible: false, searchList: Config.recDataList, formatter: Table.api.formatter.flag},
  66. {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  67. {
  68. field: 'weigh',
  69. title: __('Weigh'),
  70. operate: false,
  71. sortable: true,
  72. formatter: function (value, row, index) {
  73. return '<input type="text" class="form-control text-center text-weigh" data-id="' + row.id + '" value="' + value + '" style="width:50px;margin:0 auto;" />';
  74. },
  75. events: {
  76. "dblclick .text-weigh": function (e) {
  77. e.preventDefault();
  78. e.stopPropagation();
  79. return false;
  80. }
  81. }
  82. },
  83. {field: 'views', title: __('Views')},
  84. {field: 'time', title: __('Time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  85. {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, custom: {0: 'grey', 1: 'info'}, formatter: Table.api.formatter.flag},
  86. {field: 'lang', title: __('Lang'), searchList: {"1":__('Lang 1'),"2":__('Lang 2')}, custom: {1: 'success', 2: 'warning'}, formatter: Table.api.formatter.normal},
  87. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  88. buttons: [
  89. {
  90. name: 'faudit',
  91. text: __('反审核'),
  92. title: __('反审核'),
  93. classname: 'btn btn-xs btn-danger btn-magic btn-ajax',
  94. // icon: 'fa fa-close',
  95. url: 'wwh/archives/faudit',
  96. hidden:function(row){
  97. if(row.status != '1'){
  98. return true;
  99. }
  100. },
  101. success: function (data, ret) {
  102. table.bootstrapTable('refresh'); //自动刷新
  103. },
  104. }
  105. ],
  106. formatter: function (value, row, index) {
  107. var that = $.extend({}, this);
  108. var table = $(that.table).clone(true);
  109. if (row.status == 1){
  110. $(table).data("operate-edit",null);
  111. $(table).data("operate-del",null);
  112. }
  113. that.table = table;
  114. return Table.api.formatter.operate.call(that, value, row, index);
  115. }}
  116. ]
  117. ]
  118. });
  119. // 权重修改
  120. $(document).on("change", ".text-weigh", function () {
  121. $(this).data("params", {weigh: $(this).val()});
  122. Table.api.multi('', [$(this).data("id")], table, this);
  123. return false;
  124. });
  125. // 审核
  126. $(document).on("click", ".btn-audit", function () {
  127. var data = table.bootstrapTable('getSelections');
  128. var ids = [];
  129. if (data.length === 0) {
  130. Toastr.error("请选择操作信息");
  131. return;
  132. }
  133. for (var i = 0; i < data.length; i++) {
  134. ids[i] = data[i]['id']
  135. }
  136. Layer.confirm(
  137. '确认选中'+ids.length+'条审核吗?',
  138. {icon: 3, title: __('Warning'), offset: '40%', shadeClose: true},
  139. function (index) {
  140. Layer.close(index);
  141. Backend.api.ajax({
  142. url: "wwh/archives/audit",
  143. data: {ids:ids}
  144. }, function(data, ret){//成功的回调
  145. if (ret.code === 1) {
  146. table.bootstrapTable('refresh');
  147. Layer.close(index);
  148. } else {
  149. Layer.close(index);
  150. Toastr.error(ret.msg);
  151. }
  152. }, function(data, ret){//失败的回调
  153. console.log(ret);
  154. Layer.close(index);
  155. });
  156. }
  157. );
  158. });
  159. // 为表格绑定事件
  160. Table.api.bindevent(table);
  161. // 弹窗窗口大小
  162. table.on('post-body.bs.table',function(e, settings, json, xhr){
  163. $(".btn-add").data("area", ['80%','80%']);
  164. $(".btn-editone").data("area", ['80%','80%']);
  165. });
  166. // TAB选项卡默认选中简体中文
  167. $('ul.nav-tabs li a[data-toggle="tab"]').eq(0).trigger("click");
  168. // 获取TAB选项卡值,通过options.extend.add_url传递
  169. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  170. var options = table.bootstrapTable('getOptions');
  171. options.extend.add_url = 'wwh/archives/add?lang=' + $(this).data('value');
  172. });
  173. $(document).on("click", "a.btn-column", function () {
  174. $("#archivespanel").toggleClass("col-md-9", $("#columnbar").hasClass("hidden"));
  175. $("#archivespanel").toggleClass("col-full-width", !$("#columnbar").hasClass("hidden"));
  176. $("#columnbar").toggleClass("hidden");
  177. });
  178. require(['jstree'], function () {
  179. // 全选和展开
  180. $(document).on("click", "#checkall", function () {
  181. $("#columntree").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
  182. });
  183. $(document).on("click", "#expandall", function () {
  184. $("#columntree").jstree($(this).prop("checked") ? "open_all" : "close_all");
  185. });
  186. $('#columntree').on("changed.jstree", function (e, data) {
  187. $(".commonsearch-table input[name=column_id]").val(data.selected.join(","));
  188. table.bootstrapTable('refresh', {});
  189. return false;
  190. });
  191. $('#columntree').jstree({
  192. "themes": {
  193. "stripes": true
  194. },
  195. "checkbox": {
  196. "keep_selected_style": false,
  197. },
  198. "types": {
  199. "column": {
  200. "icon": false,
  201. },
  202. "list": {
  203. "icon": false,
  204. },
  205. "link": {
  206. "icon": false,
  207. },
  208. "disabled": {
  209. "check_node": false,
  210. "uncheck_node": false
  211. }
  212. },
  213. 'plugins': ["types", "checkbox"],
  214. "core": {
  215. "multiple": true,
  216. 'check_callback': true,
  217. "data": Config.columnList
  218. }
  219. });
  220. });
  221. },
  222. add: function () {
  223. // 将TAB选项卡赋值给lang
  224. $('#c-lang option').each(function(){
  225. if($(this).attr('value') == Fast.api.query('lang'))
  226. {
  227. $(this).attr('selected', 'selected');
  228. }
  229. });
  230. Controller.api.bindevent();
  231. },
  232. edit: function () {
  233. Controller.api.bindevent();
  234. $("input[name='row[type]']:checked").trigger("fa.event.typeupdated", "edit");
  235. },
  236. api: {
  237. formatter: {
  238. subnode: function (value, row, index) {
  239. 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 '
  240. + (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>';
  241. }
  242. },
  243. bindevent: function () {
  244. // 根据类型显示隐藏对应字段
  245. $(document).on("click fa.event.typeupdated", "input[name='row[type]']", function (e, ref) {
  246. $(".tf").addClass("hidden");
  247. $(".tf.tf-" + $(this).val()).removeClass("hidden");
  248. });
  249. // 不验证隐藏元素
  250. $('form[role=form]').data("validator-options", {
  251. ignore: ':hidden'
  252. });
  253. Form.api.bindevent($("form[role=form]"));
  254. }
  255. }
  256. };
  257. return Controller;
  258. });