eduPaperDetailList.js 10 KB

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