trainactive.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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: 'score_sum', title: __('Score_sum'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  46. {field: 'score_count', title: __('Score_count'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  47. {field: 'score_times', title: __('Score_times'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  48. {field: 'score_avg', title: __('Score_avg'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  49. {field: 'logo_image', title: __('Logo_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  50. {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  51. {field: 'number', title: __('Number'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  52. {field: 'version', title: __('Version'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  53. {field: 'bianzhiren', title: __('Bianzhiren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  54. {field: 'pizhunren', title: __('Pizhunren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  55. {field: 'shenheren', title: __('Shenheren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  56. {field: 'kongzhiren', title: __('Kongzhiren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  57. {field: 'department', title: __('Department'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  58. {field: 'wenjianstatus', title: __('Wenjianstatus'), operate: 'LIKE', formatter: Table.api.formatter.status},
  59. {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  60. // {field: 'cate_id', title: __('Cate_id')},
  61. {field: 'cate.name', title: __('Cate.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  62. // {field: 'level_id', title: __('Level_id')},
  63. {field: 'level.name', title: __('Level.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  64. {field: 'fangshi', title: __('Fangshi'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  65. {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  66. {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  67. {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  68. {field: 'zhuchiren', title: __('Zhuchiren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  69. {field: 'zhujiangren', title: __('Zhujiangren'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  70. // {field: 'type_id', title: __('Type_id')},
  71. {field: 'type.name', title: __('Type.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  72. {field: 'info', title: __('Info'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  73. {field: 'files', title: __('Files'), operate: false, formatter: Table.api.formatter.files},
  74. {field: 'pingjia_image', title: __('Pingjia_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  75. {field: 'pingjia_time', title: __('Pingjia_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  76. {field: 'pingjia_uid', title: __('Pingjia_uid')},
  77. {field: 'sign_endtime', title: __('Sign_endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  78. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  79. {field: 'usercount', title: __('Usercount')},
  80. {field: 'userauth_status', title: __('Userauth_status'), searchList: {"0":__('Userauth_status 0'),"1":__('Userauth_status 1')}, formatter: Table.api.formatter.status},
  81. {field: 'operate', title: __('Operate'), table: table,
  82. buttons:[
  83. {
  84. name:'selectuser',
  85. text:'选择用户',
  86. title:'选择用户',
  87. icon:'fa fa-exclamation-circle',
  88. classname:'btn btn-xs btn-info btn-dialog btn-selectuser',
  89. url:'trainactive/selectuser/id/{ids}?dialog=1',
  90. target:'_self',
  91. },
  92. {
  93. name:'qrcode',
  94. text:'二维码',
  95. title:'二维码',
  96. icon:'fa fa-exclamation-circle',
  97. classname:'btn btn-xs btn-info btn-dialog bt-qrcode',
  98. url:'trainactive/qrcode/id/{ids}?dialog=1',
  99. target:'_self',
  100. },
  101. {
  102. name:'showinfo',
  103. text:'打印',
  104. title:'打印',
  105. icon:'fa fa-exclamation-circle',
  106. classname:'btn btn-xs btn-info btn-addtabs',
  107. url:'trainactive/showinfo/id/{ids}',
  108. target:'_blank',
  109. },
  110. {
  111. name:'nograde',
  112. text:'未到',
  113. title:'未到',
  114. icon:'fa fa-exclamation-circle',
  115. classname:'btn btn-xs btn-info btn-dialog btn-nograde',
  116. url:'trainactive/nograde/id/{ids}',
  117. target:'_self',
  118. }
  119. ],
  120. events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  121. ]
  122. ],
  123. onLoadSuccess:function(){
  124. // 这里就是数据渲染结束后的回调函数
  125. $(".btn-selectuser").data("area", ['80%','80%']);
  126. $(".bt-qrcode").data("area", ['50%','90%']);
  127. }
  128. });
  129. // 为表格绑定事件
  130. Table.api.bindevent(table);
  131. },
  132. recyclebin: function () {
  133. // 初始化表格参数配置
  134. Table.api.init({
  135. extend: {
  136. 'dragsort_url': ''
  137. }
  138. });
  139. var table = $("#table");
  140. // 初始化表格
  141. table.bootstrapTable({
  142. url: 'trainactive/recyclebin' + location.search,
  143. pk: 'id',
  144. sortName: 'id',
  145. columns: [
  146. [
  147. {checkbox: true},
  148. {field: 'id', title: __('Id')},
  149. {field: 'title', title: __('Title'), align: 'left'},
  150. {
  151. field: 'deletetime',
  152. title: __('Deletetime'),
  153. operate: 'RANGE',
  154. addclass: 'datetimerange',
  155. formatter: Table.api.formatter.datetime
  156. },
  157. {
  158. field: 'operate',
  159. width: '140px',
  160. title: __('Operate'),
  161. table: table,
  162. events: Table.api.events.operate,
  163. buttons: [
  164. {
  165. name: 'Restore',
  166. text: __('Restore'),
  167. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  168. icon: 'fa fa-rotate-left',
  169. url: 'trainactive/restore',
  170. refresh: true
  171. },
  172. /* {
  173. name: 'Destroy',
  174. text: __('Destroy'),
  175. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  176. icon: 'fa fa-times',
  177. url: 'trainactive/destroy',
  178. refresh: true
  179. }*/
  180. ],
  181. formatter: Table.api.formatter.operate
  182. }
  183. ]
  184. ]
  185. });
  186. // 为表格绑定事件
  187. Table.api.bindevent(table);
  188. },
  189. add: function () {
  190. Controller.api.bindevent();
  191. },
  192. selectuser: function () {
  193. Controller.apisu.bindevent();
  194. },
  195. qrcode: function () {
  196. Controller.api.bindevent();
  197. },
  198. edit: function () {
  199. Controller.api.bindevent();
  200. },
  201. showinfo: function () {
  202. Controller.api.bindevent();
  203. },
  204. api: {
  205. bindevent: function () {
  206. Form.api.bindevent($("form[role=form]"));
  207. }
  208. },
  209. apisu: {
  210. bindevent: function () {
  211. Form.api.bindevent($("form[role=form]"), null, null, function () {
  212. if ($("#treeview").length > 0) {
  213. var r = $("#treeview").jstree("get_all_checked");
  214. $("input[name='row[user_rule]']").val(r.join(','));
  215. }
  216. return true;
  217. });
  218. //渲染权限节点树
  219. //销毁已有的节点树
  220. $("#treeview").jstree("destroy");
  221. Controller.apisu.rendertree(nodeData);
  222. //全选和展开
  223. $(document).on("click", "#checkall", function () {
  224. $("#treeview").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
  225. });
  226. $(document).on("click", "#expandall", function () {
  227. $("#treeview").jstree($(this).prop("checked") ? "open_all" : "close_all");
  228. });
  229. $("select[name='row[pid]']").trigger("change");
  230. },
  231. rendertree: function (content) {
  232. $("#treeview")
  233. .on('redraw.jstree', function (e) {
  234. $(".layer-footer").attr("domrefresh", Math.random());
  235. })
  236. .jstree({
  237. "themes": {"stripes": true},
  238. "checkbox": {
  239. "keep_selected_style": false,
  240. },
  241. "types": {
  242. "root": {
  243. "icon": "fa fa-folder-open",
  244. },
  245. "menu": {
  246. "icon": "fa fa-folder-open",
  247. },
  248. "file": {
  249. "icon": "fa fa-file-o",
  250. }
  251. },
  252. "plugins": ["checkbox", "types"],
  253. "core": {
  254. 'check_callback': true,
  255. "data": content
  256. }
  257. });
  258. }
  259. }
  260. };
  261. return Controller;
  262. });
  263. //打印切换
  264. $('#left').click(function(){
  265. $('#left_table').show();
  266. $('#right_table').hide();
  267. })
  268. $('#right').click(function(){
  269. $('#left_table').hide();
  270. $('#right_table').show();
  271. })
  272. //打印下载
  273. function jump(url){
  274. console.log(url);
  275. window.location.href = url;
  276. }
  277. //打印ctrl+P
  278. function printPage() {
  279. window.print();
  280. }