eduQuestionList.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <%@ page contentType="text/html;charset=UTF-8" %>
  2. <script>
  3. $(document).ready(function() {
  4. $('#eduQuestionTable').bootstrapTable({
  5. //请求方法
  6. method: 'post',
  7. //类型json
  8. dataType: "json",
  9. contentType: "application/x-www-form-urlencoded",
  10. //显示检索按钮
  11. showSearch: true,
  12. //显示刷新按钮
  13. showRefresh: true,
  14. //显示切换手机试图按钮
  15. showToggle: true,
  16. //显示 内容列下拉框
  17. showColumns: true,
  18. //显示到处按钮
  19. showExport: false,
  20. //显示切换分页按钮
  21. showPaginationSwitch: true,
  22. //显示详情按钮
  23. detailView: true,
  24. //显示详细内容函数
  25. detailFormatter: "detailFormatter",
  26. //最低显示2行
  27. minimumCountColumns: 2,
  28. //是否显示行间隔色
  29. striped: true,
  30. //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  31. cache: false,
  32. //是否显示分页(*)
  33. pagination: true,
  34. //排序方式
  35. sortOrder: "asc",
  36. //初始化加载第一页,默认第一页
  37. pageNumber:1,
  38. //每页的记录行数(*)
  39. pageSize: 10,
  40. //可供选择的每页的行数(*)
  41. pageList: [10, 25, 50, 100],
  42. //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
  43. url: "${ctx}/exam/eduQuestion/data",
  44. //默认值为 'limit',传给服务端的参数为:limit, offset, search, sort, order Else
  45. //queryParamsType:'',
  46. ////查询参数,每次调用是会带上这个参数,可自定义
  47. queryParams : function(params) {
  48. var searchParam = $("#searchForm").serializeJSON();
  49. searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
  50. searchParam.pageSize = params.limit === undefined? -1 : params.limit;
  51. searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+ params.order;
  52. return searchParam;
  53. },
  54. //分页方式:client客户端分页,server服务端分页(*)
  55. sidePagination: "server",
  56. contextMenuTrigger:"right",//pc端 按右键弹出菜单
  57. contextMenuTriggerMobile:"press",//手机端 弹出菜单,click:单击, press:长按。
  58. contextMenu: '#context-menu',
  59. onContextMenuItem: function(row, $el){
  60. if($el.data("item") == "view"){
  61. view(row.id);
  62. } else if($el.data("item") == "delete"){
  63. jp.confirm('确认要删除该试题记录吗?', function(){
  64. jp.loading();
  65. jp.get("${ctx}/exam/eduQuestion/delete?id="+row.id, function(data){
  66. if(data.success){
  67. $('#eduQuestionTable').bootstrapTable('refresh');
  68. jp.success(data.msg);
  69. }else{
  70. jp.error(data.msg);
  71. }
  72. })
  73. });
  74. }
  75. },
  76. onClickRow: function(row, $el){
  77. },
  78. onShowSearch: function () {
  79. $("#search-collapse").slideToggle();
  80. },
  81. columns: [{
  82. checkbox: true
  83. }
  84. ,{
  85. field: 'title',
  86. title: '题干',
  87. sortable: true,
  88. sortName: 'title'
  89. ,formatter:function(value, row , index){
  90. value = jp.unescapeHTML(value);
  91. <c:choose>
  92. <c:when test="${fns:hasPermission('exam:eduQuestion:edit')}">
  93. return "<a href='javascript:view(\""+row.id+"\")'>"+value+"</a>";
  94. </c:when>
  95. <c:when test="${fns:hasPermission('exam:eduQuestion:view')}">
  96. return "<a href='javascript:view(\""+row.id+"\")'>"+value+"</a>";
  97. </c:when>
  98. <c:otherwise>
  99. return value;
  100. </c:otherwise>
  101. </c:choose>
  102. }
  103. }
  104. ,{
  105. field: 'types',
  106. title: '题型',
  107. sortable: true,
  108. sortName: 'types',
  109. formatter:function(value, row , index){
  110. if(value == '1'){
  111. return '单选'
  112. }else if (value == '2'){
  113. return '多选'
  114. }else if (value == '3'){
  115. return '判断'
  116. }
  117. }
  118. },
  119. {
  120. field: 'isFix',
  121. title: '固定试题',
  122. sortable: true,
  123. sortName: 'isFix'
  124. ,formatter:function(value, row , index){
  125. value = jp.unescapeHTML(value);
  126. return jp.getDictLabel(${fns:toJson(fns:getDictList('yes_no'))}, value, "-");
  127. }
  128. }
  129. ,{
  130. field: 'points',
  131. title: '分值',
  132. sortable: true,
  133. sortName: 'points',
  134. formatter:function(value, row , index){
  135. return value === '' ? '0' : value;
  136. }
  137. }
  138. ]
  139. });
  140. if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端
  141. $('#eduQuestionTable').bootstrapTable("toggleView");
  142. }
  143. $('#eduQuestionTable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
  144. 'check-all.bs.table uncheck-all.bs.table', function () {
  145. $('#remove').prop('disabled', !isEditable());
  146. $('#view').prop('disabled', $('#eduQuestionTable').bootstrapTable('getSelections').length!=1);
  147. $('#edit').prop('disabled',!isEditable())
  148. });
  149. $("#btnImport").click(function(){
  150. jp.open({
  151. type: 2,
  152. area: [500, 200],
  153. auto: true,
  154. title:"导入数据",
  155. content: "${ctx}/tag/importExcel" ,
  156. btn: ['下载模板','确定', '关闭'],
  157. btn1: function(index, layero){
  158. jp.downloadFile('${ctx}/exam/eduQuestion/import/template');
  159. },
  160. btn2: function(index, layero){
  161. var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
  162. iframeWin.contentWindow.importExcel('${ctx}/exam/eduQuestion/import', function (data) {
  163. if(data.success){
  164. jp.success(data.msg);
  165. refresh();
  166. }else{
  167. jp.error(data.msg);
  168. }
  169. });//调用保存事件
  170. jp.close(index);
  171. },
  172. btn3: function(index){
  173. jp.close(index);
  174. }
  175. });
  176. });
  177. $("#export").click(function(){//导出Excel文件
  178. jp.downloadFile('${ctx}/exam/eduQuestion/export');
  179. });
  180. $("#search").click("click", function() {// 绑定查询按扭
  181. $('#eduQuestionTable').bootstrapTable('refresh');
  182. });
  183. $("#reset").click("click", function() {// 绑定查询按扭
  184. $("#searchForm input").val("");
  185. $("#searchForm select").val("");
  186. $("#searchForm .select-item").html("");
  187. $('#eduQuestionTable').bootstrapTable('refresh');
  188. });
  189. });
  190. function getIdSelections() {
  191. return $.map($("#eduQuestionTable").bootstrapTable('getSelections'), function (row) {
  192. return row.id
  193. });
  194. }
  195. function deleteAll(){
  196. jp.confirm('确认要删除该试题记录吗?', function(){
  197. jp.loading();
  198. jp.get("${ctx}/exam/eduQuestion/deleteAll?ids=" + getIdSelections(), function(data){
  199. if(data.success){
  200. $('#eduQuestionTable').bootstrapTable('refresh');
  201. jp.success(data.msg);
  202. }else{
  203. jp.error(data.msg);
  204. }
  205. })
  206. })
  207. }
  208. //刷新列表
  209. function refresh() {
  210. $('#eduQuestionTable').bootstrapTable('refresh');
  211. }
  212. function add(){
  213. jp.openSaveDialog('新增试题', "${ctx}/exam/eduQuestion/form",'900px', '550px');
  214. }
  215. function edit(id){//没有权限时,不显示确定按钮
  216. if(id == undefined){
  217. id = getIdSelections();
  218. }
  219. jp.openSaveDialog('编辑试题', "${ctx}/exam/eduQuestion/form?id=" + id, '900px', '550px');
  220. }
  221. function view(id){//没有权限时,不显示确定按钮
  222. if(id == undefined){
  223. id = getIdSelections();
  224. }
  225. jp.openViewDialog('查看试题', "${ctx}/exam/eduQuestion/form?id=" + id, '900px', '550px');
  226. }
  227. //是否可编辑 可编辑返回true 不可编辑返回false
  228. function isEditable() {
  229. debugger;
  230. var rows = $('#eduQuestionTable').bootstrapTable('getSelections');
  231. //校验选择数量 num为1
  232. var num = rows.length;
  233. if(num !== 1){
  234. return false;
  235. }else {
  236. //校验是否回答 回答了就不可编辑
  237. return !rows[0].isAnswered;
  238. }
  239. }
  240. function detailFormatter(index, row) {
  241. var htmltpl = $("#eduQuestionChildrenTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
  242. var html = Mustache.render(htmltpl, {
  243. idx:row.id
  244. });
  245. $.get("${ctx}/exam/eduQuestion/detail?id="+row.id, function(eduQuestion){
  246. var eduQuestionChild1RowIdx = 0, eduQuestionChild1Tpl = $("#eduQuestionChild1Tpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
  247. var data1 = eduQuestion.eduQuestionOptionList;
  248. console.log(data1);
  249. for (var i=0; i<data1.length; i++){
  250. data1[i].dict = {};
  251. if(data1[i].isAnswer === '1'){
  252. data1[i].isAnswer = "√"
  253. }else{
  254. data1[i].isAnswer = ""
  255. }
  256. addRow('#eduQuestionChild-'+row.id+'-1-List', eduQuestionChild1RowIdx, eduQuestionChild1Tpl, data1[i]);
  257. eduQuestionChild1RowIdx = eduQuestionChild1RowIdx + 1;
  258. }
  259. })
  260. return html;
  261. }
  262. function addRow(list, idx, tpl, row){
  263. $(list).append(Mustache.render(tpl, {
  264. idx: idx, delBtn: true, row: row
  265. }));
  266. }
  267. </script>
  268. <script type="text/template" id="eduQuestionChildrenTpl">//<!--
  269. <div class="tabs-container">
  270. <ul class="nav nav-tabs">
  271. <li class="active"><a data-toggle="tab" href="#tab-{{idx}}-1" aria-expanded="true">试题选项</a></li>
  272. </ul>
  273. <div class="tab-content">
  274. <div id="tab-{{idx}}-1" class="tab-pane fade in active">
  275. <table class="ani table">
  276. <thead>
  277. <tr>
  278. <th width="800">选项</th>
  279. <th>正确答案</th>
  280. </tr>
  281. </thead>
  282. <tbody id="eduQuestionChild-{{idx}}-1-List">
  283. </tbody>
  284. </table>
  285. </div>
  286. </div>//-->
  287. </script>
  288. <script type="text/template" id="eduQuestionChild1Tpl">//<!--
  289. <tr style="height: 40px;">
  290. <td>
  291. {{row.title}}
  292. </td>
  293. <td style="font-size: 20px; color: red;text-align: center;">
  294. {{row.isAnswer}}
  295. </td>
  296. </tr>//-->
  297. </script>