trainactive.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree'], function ($, undefined, Backend, Table, Form) {
  2. //读取选中的条目
  3. $.jstree.core.prototype.get_all_checked = function (full) {
  4. var obj = this.get_selected(), i, j;
  5. for (i = 0, j = obj.length; i < j; i++) {
  6. obj = obj.concat(this.get_node(obj[i]).parents);
  7. }
  8. obj = $.grep(obj, function (v, i, a) {
  9. return v != '#';
  10. });
  11. obj = obj.filter(function (itm, i, a) {
  12. return i == a.indexOf(itm);
  13. });
  14. return full ? $.map(obj, $.proxy(function (i) {
  15. return this.get_node(i);
  16. }, this)) : obj;
  17. };
  18. var Controller = {
  19. index: function () {
  20. // 初始化表格参数配置
  21. Table.api.init({
  22. extend: {
  23. index_url: 'trainactive/index' + location.search,
  24. add_url: 'trainactive/add',
  25. edit_url: 'trainactive/edit',
  26. del_url: 'trainactive/del',
  27. multi_url: 'trainactive/multi',
  28. import_url: 'trainactive/import',
  29. table: 'train_active',
  30. }
  31. });
  32. var table = $("#table");
  33. // 初始化表格
  34. table.bootstrapTable({
  35. url: $.fn.bootstrapTable.defaults.extend.index_url,
  36. pk: 'id',
  37. sortName: 'id',
  38. fixedColumns: true,
  39. fixedRightNumber: 1,
  40. columns: [
  41. [
  42. {checkbox: true},
  43. {field: 'id', title: __('Id')},
  44. {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, formatter: Table.api.formatter.status},
  45. {field: 'logo_image', title: __('Logo_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  46. {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  47. {field: 'number', title: __('Number'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  48. {field: 'version', title: __('Version'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  49. {field: 'bianzhiren', title: __('Bianzhiren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  50. {field: 'pizhunren', title: __('Pizhunren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  51. {field: 'shenheren', title: __('Shenheren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  52. {field: 'kongzhiren', title: __('Kongzhiren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  53. {field: 'department', title: __('Department'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  54. {field: 'wenjianstatus', title: __('Wenjianstatus'), operate: 'LIKE', formatter: Table.api.formatter.status},
  55. {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  56. // {field: 'cate_id', title: __('Cate_id')},
  57. {field: 'cate.name', title: __('Cate.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  58. // {field: 'level_id', title: __('Level_id')},
  59. {field: 'level.name', title: __('Level.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  60. {field: 'fangshi', title: __('Fangshi'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  61. {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  62. {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  63. {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  64. {field: 'zhuchiren', title: __('Zhuchiren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  65. {field: 'zhujiangren', title: __('Zhujiangren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  66. // {field: 'type_id', title: __('Type_id')},
  67. {field: 'type.name', title: __('Type.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  68. {field: 'info', title: __('Info'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  69. {field: 'files', title: __('Files'), operate: false, formatter: Table.api.formatter.files},
  70. {field: 'pingjia_image', title: __('Pingjia_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  71. {field: 'pingjia_time', title: __('Pingjia_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  72. {field: 'pingjia_uid', title: __('Pingjia_uid')},
  73. {field: 'sign_endtime', title: __('Sign_endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  74. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  75. {field: 'usercount', title: __('Usercount')},
  76. {field: 'userauth_status', title: __('Userauth_status'), searchList: {"0":__('Userauth_status 0'),"1":__('Userauth_status 1')}, formatter: Table.api.formatter.status},
  77. {field: 'operate', title: __('Operate'), table: table,
  78. buttons:[
  79. {
  80. name:'selectuser',
  81. text:'选择用户',
  82. title:'选择用户',
  83. icon:'fa fa-exclamation-circle',
  84. classname:'btn btn-xs btn-info btn-dialog',
  85. url:'trainactive/selectuser/id/{ids}?dialog=1',
  86. target:'_self',
  87. },
  88. {
  89. name:'qrcode',
  90. text:'二维码',
  91. title:'二维码',
  92. icon:'fa fa-exclamation-circle',
  93. classname:'btn btn-xs btn-info btn-dialog',
  94. url:'trainactive/qrcode/id/{ids}?dialog=1',
  95. target:'_self',
  96. },
  97. {
  98. name:'showinfo',
  99. text:'打印',
  100. title:'打印',
  101. icon:'fa fa-exclamation-circle',
  102. classname:'btn btn-xs btn-info btn-addtabs',
  103. url:'trainactive/showinfo/id/{ids}',
  104. target:'_blank',
  105. },
  106. {
  107. name:'nograde',
  108. text:'未到',
  109. title:'未到',
  110. icon:'fa fa-exclamation-circle',
  111. classname:'btn btn-xs btn-info btn-dialog btn-nograde',
  112. url:'trainactive/nograde/id/{ids}',
  113. target:'_self',
  114. }
  115. ],
  116. events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  117. ]
  118. ]
  119. });
  120. // 为表格绑定事件
  121. Table.api.bindevent(table);
  122. },
  123. recyclebin: function () {
  124. // 初始化表格参数配置
  125. Table.api.init({
  126. extend: {
  127. 'dragsort_url': ''
  128. }
  129. });
  130. var table = $("#table");
  131. // 初始化表格
  132. table.bootstrapTable({
  133. url: 'trainactive/recyclebin' + location.search,
  134. pk: 'id',
  135. sortName: 'id',
  136. columns: [
  137. [
  138. {checkbox: true},
  139. {field: 'id', title: __('Id')},
  140. {field: 'title', title: __('Title'), align: 'left'},
  141. {
  142. field: 'deletetime',
  143. title: __('Deletetime'),
  144. operate: 'RANGE',
  145. addclass: 'datetimerange',
  146. formatter: Table.api.formatter.datetime
  147. },
  148. {
  149. field: 'operate',
  150. width: '140px',
  151. title: __('Operate'),
  152. table: table,
  153. events: Table.api.events.operate,
  154. buttons: [
  155. {
  156. name: 'Restore',
  157. text: __('Restore'),
  158. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  159. icon: 'fa fa-rotate-left',
  160. url: 'trainactive/restore',
  161. refresh: true
  162. },
  163. {
  164. name: 'Destroy',
  165. text: __('Destroy'),
  166. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  167. icon: 'fa fa-times',
  168. url: 'trainactive/destroy',
  169. refresh: true
  170. }
  171. ],
  172. formatter: Table.api.formatter.operate
  173. }
  174. ]
  175. ]
  176. });
  177. // 为表格绑定事件
  178. Table.api.bindevent(table);
  179. },
  180. add: function () {
  181. Controller.api.bindevent();
  182. },
  183. selectuser: function () {
  184. Controller.api.bindevent();
  185. },
  186. qrcode: function () {
  187. Controller.api.bindevent();
  188. },
  189. edit: function () {
  190. Controller.api.bindevent();
  191. },
  192. showinfo: function () {
  193. Controller.api.bindevent();
  194. },
  195. api: {
  196. /*bindevent: function () {
  197. Form.api.bindevent($("form[role=form]"));
  198. }*/
  199. bindevent: function () {
  200. Form.api.bindevent($("form[role=form]"), null, null, function () {
  201. if ($("#treeview").length > 0) {
  202. var r = $("#treeview").jstree("get_all_checked");
  203. $("input[name='row[user_rule]']").val(r.join(','));
  204. }
  205. return true;
  206. });
  207. //渲染权限节点树
  208. //销毁已有的节点树
  209. $("#treeview").jstree("destroy");
  210. Controller.api.rendertree(nodeData);
  211. //全选和展开
  212. $(document).on("click", "#checkall", function () {
  213. $("#treeview").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
  214. });
  215. $(document).on("click", "#expandall", function () {
  216. $("#treeview").jstree($(this).prop("checked") ? "open_all" : "close_all");
  217. });
  218. $("select[name='row[pid]']").trigger("change");
  219. },
  220. rendertree: function (content) {
  221. $("#treeview")
  222. .on('redraw.jstree', function (e) {
  223. $(".layer-footer").attr("domrefresh", Math.random());
  224. })
  225. .jstree({
  226. "themes": {"stripes": true},
  227. "checkbox": {
  228. "keep_selected_style": false,
  229. },
  230. "types": {
  231. "root": {
  232. "icon": "fa fa-folder-open",
  233. },
  234. "menu": {
  235. "icon": "fa fa-folder-open",
  236. },
  237. "file": {
  238. "icon": "fa fa-file-o",
  239. }
  240. },
  241. "plugins": ["checkbox", "types"],
  242. "core": {
  243. 'check_callback': true,
  244. "data": content
  245. }
  246. });
  247. }
  248. }
  249. };
  250. return Controller;
  251. });
  252. //打印切换
  253. $('#left').click(function(){
  254. $('#left_table').show();
  255. $('#right_table').hide();
  256. })
  257. $('#right').click(function(){
  258. $('#left_table').hide();
  259. $('#right_table').show();
  260. })
  261. //打印下载
  262. function jump(url){
  263. console.log(url);
  264. window.location.href = url;
  265. }
  266. //打印ctrl+P
  267. function printPage() {
  268. window.print();
  269. }