index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. {extend name="public/container"}
  2. {block name="head_top"}
  3. <style>
  4. .layui-table-cell img{max-width: 100%;height: 50px;cursor: pointer;}
  5. </style>
  6. {/block}
  7. {block name="content"}
  8. <div class="layui-fluid">
  9. <div class="layui-card">
  10. <div class="layui-card-header">{$type==1 ? '练习列表':'考试列表'}</div>
  11. <div class="layui-card-body">
  12. <form class="layui-form layui-form-pane" action="">
  13. <div class="layui-form-item">
  14. <div class="layui-inline">
  15. <label class="layui-form-label">{$type==1 ? '练习搜索':'考试搜索'}</label>
  16. <div class="layui-input-inline">
  17. <input type="text" name="title" class="layui-input" placeholder="{$type==1 ? '练习':'考试'}标题">
  18. </div>
  19. </div>
  20. <div class="layui-inline">
  21. <label class="layui-form-label">{$type==1 ? '练习分类':'考试分类'}</label>
  22. <div class="layui-input-inline">
  23. <select name="pid" lay-search="">
  24. <option value="0">全部</option>
  25. {volist name='category' id='vc'}
  26. <option {if $vc.pid==0}disabled{/if} value="{$vc.id}">{$vc.html}{$vc.title}</option>
  27. {/volist}
  28. </select>
  29. </div>
  30. </div>
  31. <div class="layui-inline">
  32. <div class="layui-input-inline">
  33. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="search" lay-filter="search">
  34. <i class="layui-icon layui-icon-search"></i>搜索
  35. </button>
  36. </div>
  37. </div>
  38. </div>
  39. </form>
  40. <div class="layui-btn-container">
  41. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" data-type="add" onclick="action.open_add('{:Url('add',['type'=>$type])}',types)">
  42. <i class="layui-icon layui-icon-add-1"></i>{$type==1 ? '添加练习':'添加考试'}
  43. </button>
  44. <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" data-type="refresh" onclick="window.location.reload()">
  45. <i class="layui-icon layui-icon-refresh-1"></i>刷新
  46. </button>
  47. </div>
  48. <table id="List" lay-filter="List"></table>
  49. <input type="hidden" id="check_source_tmp" name="check_source_tmp"/>
  50. <input type="hidden" id="check_questions_tmp" name="check_questions_tmp"/>
  51. <script type="text/html" id="is_show">
  52. <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show' lay-text='显示|隐藏' {{ d.is_show == 1 ? 'checked' : '' }}>
  53. </script>
  54. <script type="text/html" id="image">
  55. <img width="89" height="50" lay-event='open_image' src="{{d.image}}">
  56. </script>
  57. <script type="text/html" id="status">
  58. {{# if(d.status==1){ }}
  59. <span class="layui-badge layui-bg-blue">通过</span>
  60. {{# }else if(d.status==0){ }}
  61. <span class="layui-badge layui-bg-blue">未审核</span>
  62. {{# }else{ }}
  63. <span class="layui-badge">未通过</span>
  64. <span class="layui-badge layui-bg-blue" lay-event='fail'>查看原因</span>
  65. {{# } }}
  66. </script>
  67. <script type="text/html" id="act">
  68. <button type="button" class="layui-btn layui-btn-normal layui-btn-xs" onclick="dropdown(this)">
  69. <i class="layui-icon">&#xe625;</i>操作
  70. </button>
  71. <ul class="layui-nav-child layui-anim layui-anim-upbit">
  72. <li>
  73. <a href="javascript:void(0)" onclick="action.open_add('{:Url('add')}?id={{d.id}}&type={$type}','编辑')">
  74. <i class="fa fa-paste"></i> {$type==1 ? '编辑练习':'编辑考试'}
  75. </a>
  76. </li>
  77. {if $type==2}
  78. <li>
  79. <a href="javascript:void(0)" onclick="$eb.createModalFrame('关联证书','{:Url('certificate')}?related_id='+{{d.id}},{w:800,h:350})">
  80. <i class="layui-icon layui-icon-set"></i> 关联证书
  81. </a>
  82. </li>
  83. {/if}
  84. <li>
  85. <a href="javascript:void(0)" onclick="action.open_add('{:Url('test_paper')}?id={{d.id}}&type={$type}','查看试题')">
  86. <i class="layui-icon layui-icon-set"></i> {$type==1 ? '练习查看':'考试查看'}
  87. </a>
  88. </li>
  89. <li>
  90. <a href="javascript:void(0)" onclick="action.open_add('{:Url('answerNotes')}?type={$type}&test_id={{d.id}}','查看答题')">
  91. <i class="layui-icon layui-icon-set"></i> 查看答题
  92. </a>
  93. </li>
  94. <li>
  95. <a lay-event='delect' href="javascript:void(0)">
  96. <i class="fa fa-trash"></i> {$type==1 ? '删除练习':'删除考试'}
  97. </a>
  98. </li>
  99. </ul>
  100. </script>
  101. </div>
  102. </div>
  103. </div>
  104. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  105. {/block}
  106. {block name="script"}
  107. <script>
  108. var $ = layui.jquery;
  109. var layer = layui.layer;
  110. var type=<?=$type?>;
  111. var types=type==1 ? '添加练习' : '添加考试';
  112. //实例化form
  113. layList.form.render();
  114. layList.date({elem: '#datetime', type: 'datetime', range: '~'});
  115. //加载列表
  116. layList.tableList({o:'List', done:function () {}},"{:Url('getTestPaperExercisesList',['type'=>$type])}",function (){
  117. var join=new Array();
  118. switch (parseInt(type)) {
  119. case 1:
  120. join = [
  121. {field: 'id', title: '编号', width: '4%', align: 'center'},
  122. {field: 'cate', title: '分类', width: '6%'},
  123. {field: 'title', title: '练习标题'},
  124. {field: 'item_number', title: '题目数量', align: 'center', width: '8%'},
  125. {field: 'single_number', title: '单选题数量', align: 'center', width: '8%'},
  126. {field: 'many_number', title: '多选题数量', align: 'center', width: '8%'},
  127. {field: 'judge_number', title: '判断题数量', align: 'center', width: '8%'},
  128. {field: 'answer', title: '答题人数', align: 'center', width: '6%'},
  129. {field: 'is_show', title: '状态', templet: '#is_show', align: 'center', width: '7%'},
  130. {field: 'sort', title: '排序',sort: true,event:'sort',edit:'sort', align: 'center', width: '5%'},
  131. {field: 'status', title: '审核',templet:'#status',align: 'center',width:'8%'},
  132. {title: '操作', align: 'center', toolbar: '#act', width: '7%'},
  133. ];
  134. break;
  135. case 2:
  136. join = [
  137. {field: 'id', title: '编号', width: '4%', align: 'center'},
  138. {field: 'cate', title: '分类', width: '5%'},
  139. {field: 'title', title: '考试标题'},
  140. {field: 'image', title: '封面图', templet: '#image',align: 'center', width: '8%'},
  141. {field: 'item_number', title: '题目数量', align: 'center', width: '5%'},
  142. {field: 'single_number', title: '单选题数量', align: 'center', width: '5%'},
  143. {field: 'many_number', title: '多选题数量', align: 'center', width: '5%'},
  144. {field: 'judge_number', title: '判断题数量', align: 'center', width: '5%'},
  145. {field: 'answer', title: '答题人数', align: 'center', width: '5%'},
  146. {field: 'txamination_time', title: '考试时长/分', align: 'center', width: '5%'},
  147. {field: 'money', title: '价格', align: 'center', width: '5%'},
  148. {field: 'member_money', title: '会员价', align: 'center', width: '5%'},
  149. {field: 'is_show', title: '状态', templet: '#is_show', align: 'center', width: '7%'},
  150. {field: 'sort', title: '排序',sort: true,event:'sort',edit:'sort', align: 'center', width: '5%'},
  151. {field: 'status', title: '审核',templet:'#status',align: 'center',width:'8%'},
  152. {title: '操作', align: 'center', toolbar: '#act', width: '7%'},
  153. ];
  154. break;
  155. }
  156. return join;
  157. });
  158. $(function () {
  159. $(document).on('mouseover', '.recom-item', function () {
  160. var that = this;
  161. layui.use('layer', function () {
  162. var layer = layui.layer;
  163. layer.tips('点击即可取消此推荐', that, {
  164. tips: [1, '#0093dd']
  165. });
  166. });
  167. });
  168. $(document).on('mouseout', '.recom-item', function () {
  169. var that = this;
  170. layui.use('layer', function () {
  171. var layer = layui.layer;
  172. layer.closeAll();
  173. });
  174. });
  175. $(document).on('click', '.recom-item', function () {
  176. var that = this;
  177. var url = layList.U({ a: 'cancel_recommendation', q: { id: that.dataset.id, test_id: that.dataset.pid } });
  178. $eb.$swal(
  179. 'delete',
  180. function () {
  181. $eb.axios
  182. .get(url)
  183. .then(function (res) {
  184. if (res.data.code == 200) {
  185. $eb.$swal('success', res.data.msg);
  186. window.location.reload();
  187. } else {
  188. return Promise.reject(res.data.msg || '删除失败');
  189. }
  190. })
  191. .catch(function (err) {
  192. $eb.$swal('error', err);
  193. });
  194. },
  195. {
  196. title: '确定取消此推荐?',
  197. text: '取消后无法撤销,请谨慎操作!',
  198. confirm: '确定取消'
  199. }
  200. );
  201. });
  202. });
  203. //下拉框
  204. $(document).click(function (e) {
  205. $('.layui-nav-child').hide();
  206. });
  207. function dropdown(that){
  208. var oEvent = arguments.callee.caller.arguments[0] || event;
  209. oEvent.stopPropagation();
  210. var offset = $(that).offset();
  211. var top=offset.top-$(window).scrollTop();
  212. var index = $(that).parents('tr').data('index');
  213. $('.layui-nav-child').each(function (key) {
  214. if (key != index) {
  215. $(this).hide();
  216. }
  217. });
  218. if($(document).height() < top+$(that).next('ul').height()){
  219. $(that).next('ul').css({
  220. 'padding': 10,
  221. 'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height()/2),
  222. 'min-width': 'inherit',
  223. 'position': 'absolute'
  224. }).toggle();
  225. }else{
  226. $(that).next('ul').css({
  227. 'padding': 10,
  228. 'top':$(that).parent('td').height() / 2 + $(that).height(),
  229. 'min-width': 'inherit',
  230. 'position': 'absolute'
  231. }).toggle();
  232. }
  233. }
  234. layList.switch('is_show',function (odj,value) {
  235. var is_show_value = 0
  236. if(odj.elem.checked==true){
  237. var is_show_value = 1
  238. }
  239. action.set_value('is_show',value,is_show_value);
  240. });
  241. //自定义方法
  242. var action= {
  243. set_value: function (field, id, value) {
  244. layList.baseGet(layList.Url({
  245. a: 'set_value',
  246. q: {field: field, id: id, value: value}
  247. }), function (res) {
  248. layList.msg(res.msg);
  249. });
  250. },
  251. //打开新添加页面
  252. open_add: function (url,title) {
  253. layer.open({
  254. type: 2 //Page层类型
  255. ,area: ['100%', '100%']
  256. ,title: title
  257. ,shade: 0.6 //遮罩透明度
  258. ,maxmin: true //允许全屏最小化
  259. ,anim: 1 //0-6的动画形式,-1不开启
  260. ,content: url
  261. ,end:function() {
  262. location.reload();
  263. }
  264. });
  265. }
  266. };
  267. //查询
  268. layList.search('search',function(where){
  269. layList.reload({
  270. pid: where.pid,
  271. title: where.title
  272. },true);
  273. });
  274. //快速编辑
  275. layList.edit(function (obj) {
  276. var id=obj.data.id,value=obj.value;
  277. switch (obj.field) {
  278. case 'sort':
  279. if (value.trim()) {
  280. if (isNaN(value.trim())) {
  281. layList.msg('请输入正确的数字');
  282. } else {
  283. if (value.trim() < 0) {
  284. layList.msg('排序不能小于0');
  285. } else if (value.trim() > 9999) {
  286. layList.msg('排序不能大于9999');
  287. } else if (parseInt(value.trim()) != value.trim()) {
  288. layList.msg('排序不能为小数');
  289. } else {
  290. action.set_value('sort', id, value.trim());
  291. }
  292. }
  293. } else {
  294. layList.msg('排序不能为空');
  295. }
  296. break;
  297. }
  298. });
  299. //监听并执行排序
  300. layList.sort(['id','sort'],true);
  301. //点击事件绑定
  302. layList.tool(function (event,data,obj) {
  303. switch (event) {
  304. case 'delect':
  305. var url=layList.U({a:'delete',q:{id:data.id}});
  306. $eb.$swal('delete',function(){
  307. $eb.axios.get(url).then(function(res){
  308. if(res.status == 200 && res.data.code == 200) {
  309. $eb.$swal('success',res.data.msg);
  310. obj.del();
  311. }else
  312. return Promise.reject(res.data.msg || '删除失败')
  313. }).catch(function(err){
  314. $eb.$swal('error',err);
  315. });
  316. });
  317. break;
  318. case 'open_image':
  319. $eb.openImage(data.image);
  320. break;
  321. case 'fail':
  322. layer.open({
  323. type: 1,
  324. skin: 'layui-layer-rim', //加上边框
  325. area: ['420px', '240px'], //宽高
  326. title: '审核未通过原因',
  327. content: data.fail_message
  328. });
  329. break;
  330. }
  331. })
  332. </script>
  333. {/block}