Bez popisu

addCheck.html 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <script src="../Script/Common/huayi.load.js"></script>
  6. <script src="../Script/Common/huayi.config.js"></script>
  7. <link href="../css/init.css" rel="stylesheet" />
  8. <link href="../css/eid/bootstrap-editable.css" rel="stylesheet" />
  9. <title>试题选项</title>
  10. <style>
  11. .Content {
  12. padding: 10px;
  13. }
  14. .btn {
  15. background: #249fea;
  16. color: #fff;
  17. }
  18. .Btn_box {
  19. margin-top: 20px;
  20. color: #fff;
  21. }
  22. .inpBox select {
  23. width: 150px;
  24. padding: 3px 6px;
  25. }
  26. .F_Remark {
  27. width: 100%;
  28. }
  29. .tab {
  30. border-bottom: 1px solid #ccc;
  31. }
  32. .rightAdd {
  33. margin-bottom: 20px;
  34. }
  35. </style>
  36. </head>
  37. <body>
  38. <div>
  39. <div class="Content">
  40. <div class="Check_box">
  41. <button class="rightAdd btn size-14"><i class="fa fa-plus size-14"></i>增加</button>
  42. <table id="tbr" style="width: 100%;">
  43. <thead>
  44. <tr>
  45. <th data-align="center" data-field="id" data-formatter="setCode">序号</th>
  46. <th data-align="center" data-field="questname" data-formatter="Check">内容</th>
  47. <th data-align="center" data-field="grade" data-formatter="formatterFraction">分数</th>
  48. <th data-align="center" data-field="id" data-formatter="Removes">操作</th>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. </tbody>
  53. </table>
  54. </div>
  55. </div>
  56. </div>
  57. <script src="../js/eid/bootstrap-editable.js"></script>
  58. <script>
  59. var wid = helper.request.queryString("Str");
  60. var $tableLeft = $('#tbr');
  61. //console.log(wid);
  62. $(document).ready(function() {
  63. if(wid) {
  64. loadTable()
  65. //添加行
  66. $(".rightAdd ").click(function() {
  67. var index = $tableLeft.bootstrapTable('getData').length;
  68. //console.log(index)
  69. $.ajax({
  70. type: 'get',
  71. url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/AddTestQuestion",
  72. data: {
  73. testid: wid,
  74. questname: '',
  75. grade: '',
  76. token: $.cookie("token")
  77. },
  78. dataType: 'JSON',
  79. success: function(data) {
  80. if(data.state.toLowerCase() == 'success') {
  81. // $tableLeft.bootstrapTable('insertRow', {
  82. // index: index,
  83. // row: {
  84. // }
  85. // });
  86. $tableLeft.bootstrapTable('refresh');
  87. }
  88. },
  89. error: function() {
  90. alert("error");
  91. }
  92. });
  93. });
  94. }
  95. //列表
  96. });
  97. //序号
  98. function setCode(value, row, index) {
  99. return index + 1;
  100. }
  101. //修改
  102. function Check(value, row, index) {
  103. return '<a title="点击编辑" class="username" id="' + row.id + '" index="' + row.testid + '"fraction="' + row.grade + '">' + value + '</a>'
  104. }
  105. function formatterFraction(value, row, index) {
  106. return '<a title="点击编辑" class="fraction" id="' + row.id + '" index="' + row.testid + '"questname="' + row.questname + '">' + value + '</a>'
  107. }
  108. //操作
  109. function Removes(value, row, index) {
  110. var idStr = JSON.stringify(value).replace(/\"/g,"'");
  111. return '<div style="color: red"><a onclick="Remove(' + idStr + ')" >删除<i class="fa fa-remove size-14"></i></a></div>'
  112. }
  113. function loadTable() {
  114. //销毁表格
  115. $tableLeft.bootstrapTable('destroy');
  116. // 初始化表格,动态从服务器加载数据
  117. $tableLeft.bootstrapTable({
  118. method: "get", //使用get请求到服务器获取数据
  119. url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/Gettestquestinfo",
  120. striped: true, //表格显示条纹
  121. smartDisplay:false, //不显示分页,总条数
  122. pagination: false, //启动分页
  123. pageSize: 5, //每页显示的记录数
  124. pageNumber: 1, //当前第几页
  125. pageList: [5, 20, 50, 100], //记录数可选列表
  126. search: false, //是否启用查询
  127. showColumns: false, //显示下拉框勾选要显示的列
  128. showRefresh: false, //显示刷新按钮
  129. sidePagination: "server", //表示服务端请求
  130. //设置为undefined可以获取pageNumber,pageSize,searchText,sortName,sortOrder
  131. //设置为limit可以获取limit, offset, search, sort, order
  132. queryParamsType: "undefined",
  133. queryParams: function queryParams(params) { //设置查询参数
  134. var param = {
  135. pageindex: params.pageNumber,
  136. pagesize: params.pageSize,
  137. testid: wid,
  138. token: $.cookie("token"),
  139. };
  140. return param;
  141. },
  142. responseHandler: function(res) {
  143. for(var i=0;i<res.data.length;i++){
  144. console.log(res.data[i]);
  145. if(res.data[i].questname==null&&res.data[i].grade==null){
  146. res.data[i].questname="请输入内容";
  147. res.data[i].grade="×";
  148. }
  149. }
  150. return {
  151. // "total": res.data.total, //总页数
  152. "rows": res.data //数据
  153. };
  154. },
  155. onLoadSuccess: function() { //加载成功时执行
  156. editOptions();
  157. editFraction();
  158. //layer.msg("加载成功");
  159. },
  160. onLoadError: function() { //加载失败时执行
  161. //layer.msg("加载数据失败", { time: 1500, icon: 2 });
  162. }
  163. });
  164. }
  165. //删除
  166. function Remove(val) {
  167. layer.confirm('确定删除当前记录?', {
  168. btn: ['是', '否'] //按钮
  169. }, function() {
  170. $.ajax({
  171. type: 'get',
  172. url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/DelQuestion",
  173. data: {
  174. id: val,
  175. token: $.cookie("token")
  176. },
  177. dataType: 'JSON',
  178. success: function(data) {
  179. if(data.state.toLowerCase() == 'success') {
  180. var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  181. parent.layer.close(index); //再执行关闭
  182. parent.Finish();
  183. parent.layer.msg("删除成功");
  184. }
  185. },
  186. error: function() {
  187. alert("error");
  188. }
  189. });
  190. });
  191. // $.ajax({
  192. // type: 'get',
  193. // url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/DelQuestion",
  194. // data: {
  195. // id: val,
  196. // token: $.cookie("token")
  197. // },
  198. // dataType: 'JSON',
  199. // success: function(data) {
  200. // if(data.state.toLowerCase() == 'success') {
  201. // var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  202. // parent.layer.close(index); //再执行关闭
  203. // parent.Finish();
  204. // parent.layer.msg("删除成功");
  205. // }
  206. // },
  207. // error: function() {
  208. // alert("error");
  209. // }
  210. // });
  211. }
  212. //编辑
  213. function editOptions() {
  214. $("#tbr a.username").editable({
  215. type: "text", //编辑框的类型。支持text|textarea|select|date|checklist等
  216. disabled: false, //是否禁用编辑
  217. emptytext: "请输入选项", //空值的默认文本
  218. mode: "inline", //编辑框的模式:支持popup和inline两种模式,默认是popup
  219. url: function(params) {
  220. $.ajax({
  221. type: 'get',
  222. url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/updateQuestion",
  223. data: {
  224. Id: $(this).attr("id"),
  225. questname: params.value,
  226. grade: $(this).attr("fraction"),
  227. testid: $(this).attr("index"),
  228. token: $.cookie("token")
  229. },
  230. dataType: 'JSON',
  231. success: function(data) {
  232. if(data.state.toLowerCase() == 'success') {
  233. var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  234. //parent.layer.close(index); //再执行关闭
  235. parent.Finish();
  236. parent.layer.msg("保存成功");
  237. }
  238. },
  239. });
  240. },
  241. });
  242. }
  243. function editFraction() {
  244. $("#tbr a.fraction").editable({
  245. type: "text", //编辑框的类型。支持text|textarea|select|date|checklist等
  246. disabled: false, //是否禁用编辑
  247. emptytext: "请输入选项", //空值的默认文本
  248. mode: "inline", //编辑框的模式:支持popup和inline两种模式,默认是popup
  249. url: function(params) {
  250. $.ajax({
  251. type: 'get',
  252. url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/updateQuestion",
  253. data: {
  254. Id: $(this).attr("id"),
  255. grade: params.value,
  256. questname: $(this).attr("questname"),
  257. testid: $(this).attr("index"),
  258. token: $.cookie("token")
  259. },
  260. dataType: 'JSON',
  261. success: function(data) {
  262. if(data.state.toLowerCase() == 'success') {
  263. var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  264. //parent.layer.close(index); //再执行关闭
  265. parent.Finish();
  266. parent.layer.msg("保存成功");
  267. }
  268. },
  269. });
  270. },
  271. });
  272. }
  273. </script>
  274. </body>
  275. </html>