trainactive.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 btn-selectuser',
  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 bt-qrcode',
  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. onLoadSuccess:function(){
  120. // 这里就是数据渲染结束后的回调函数
  121. $(".btn-selectuser").data("area", ['80%','80%']);
  122. $(".bt-qrcode").data("area", ['50%','90%']);
  123. }
  124. });
  125. // 为表格绑定事件
  126. Table.api.bindevent(table);
  127. },
  128. recyclebin: function () {
  129. // 初始化表格参数配置
  130. Table.api.init({
  131. extend: {
  132. 'dragsort_url': ''
  133. }
  134. });
  135. var table = $("#table");
  136. // 初始化表格
  137. table.bootstrapTable({
  138. url: 'trainactive/recyclebin' + location.search,
  139. pk: 'id',
  140. sortName: 'id',
  141. columns: [
  142. [
  143. {checkbox: true},
  144. {field: 'id', title: __('Id')},
  145. {field: 'title', title: __('Title'), align: 'left'},
  146. {
  147. field: 'deletetime',
  148. title: __('Deletetime'),
  149. operate: 'RANGE',
  150. addclass: 'datetimerange',
  151. formatter: Table.api.formatter.datetime
  152. },
  153. {
  154. field: 'operate',
  155. width: '140px',
  156. title: __('Operate'),
  157. table: table,
  158. events: Table.api.events.operate,
  159. buttons: [
  160. {
  161. name: 'Restore',
  162. text: __('Restore'),
  163. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  164. icon: 'fa fa-rotate-left',
  165. url: 'trainactive/restore',
  166. refresh: true
  167. },
  168. /* {
  169. name: 'Destroy',
  170. text: __('Destroy'),
  171. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  172. icon: 'fa fa-times',
  173. url: 'trainactive/destroy',
  174. refresh: true
  175. }*/
  176. ],
  177. formatter: Table.api.formatter.operate
  178. }
  179. ]
  180. ]
  181. });
  182. // 为表格绑定事件
  183. Table.api.bindevent(table);
  184. },
  185. add: function () {
  186. Controller.api.bindevent();
  187. },
  188. selectuser: function () {
  189. Controller.apisu.bindevent();
  190. },
  191. qrcode: function () {
  192. Controller.api.bindevent();
  193. },
  194. edit: function () {
  195. Controller.api.bindevent();
  196. },
  197. showinfo: function () {
  198. Controller.api.bindevent();
  199. },
  200. api: {
  201. bindevent: function () {
  202. Form.api.bindevent($("form[role=form]"));
  203. }
  204. },
  205. apisu: {
  206. bindevent: function () {
  207. Form.api.bindevent($("form[role=form]"), null, null, function () {
  208. if ($("#treeview").length > 0) {
  209. var r = $("#treeview").jstree("get_all_checked");
  210. $("input[name='row[user_rule]']").val(r.join(','));
  211. }
  212. return true;
  213. });
  214. //渲染权限节点树
  215. //销毁已有的节点树
  216. $("#treeview").jstree("destroy");
  217. Controller.apisu.rendertree(nodeData);
  218. //全选和展开
  219. $(document).on("click", "#checkall", function () {
  220. $("#treeview").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
  221. });
  222. $(document).on("click", "#expandall", function () {
  223. $("#treeview").jstree($(this).prop("checked") ? "open_all" : "close_all");
  224. });
  225. $("select[name='row[pid]']").trigger("change");
  226. },
  227. rendertree: function (content) {
  228. $("#treeview")
  229. .on('redraw.jstree', function (e) {
  230. $(".layer-footer").attr("domrefresh", Math.random());
  231. })
  232. .jstree({
  233. "themes": {"stripes": true},
  234. "checkbox": {
  235. "keep_selected_style": false,
  236. },
  237. "types": {
  238. "root": {
  239. "icon": "fa fa-folder-open",
  240. },
  241. "menu": {
  242. "icon": "fa fa-folder-open",
  243. },
  244. "file": {
  245. "icon": "fa fa-file-o",
  246. }
  247. },
  248. "plugins": ["checkbox", "types"],
  249. "core": {
  250. 'check_callback': true,
  251. "data": content
  252. }
  253. });
  254. }
  255. }
  256. };
  257. return Controller;
  258. });
  259. //打印切换
  260. $('#left').click(function(){
  261. $('#left_table').show();
  262. $('#right_table').hide();
  263. })
  264. $('#right').click(function(){
  265. $('#left_table').hide();
  266. $('#right_table').show();
  267. })
  268. //打印下载
  269. function jump(url){
  270. console.log(url);
  271. window.location.href = url;
  272. }
  273. //打印ctrl+P
  274. function printPage() {
  275. window.print();
  276. }