| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <script src="../Script/Common/huayi.load.js"></script>
- <script src="../Script/Common/huayi.config.js"></script>
- <link href="../css/init.css" rel="stylesheet" />
- <link href="../css/eid/bootstrap-editable.css" rel="stylesheet" />
- <title>试题选项</title>
- <style>
- .Content {
- padding: 10px;
- }
-
- .btn {
- background: #249fea;
- color: #fff;
- }
-
- .Btn_box {
- margin-top: 20px;
- color: #fff;
- }
-
- .inpBox select {
- width: 150px;
- padding: 3px 6px;
- }
-
- .F_Remark {
- width: 100%;
- }
-
- .tab {
- border-bottom: 1px solid #ccc;
- }
-
- .rightAdd {
- margin-bottom: 20px;
- }
- </style>
- </head>
- <body>
- <div>
- <div class="Content">
- <div class="Check_box">
- <button class="rightAdd btn size-14"><i class="fa fa-plus size-14"></i>增加</button>
- <table id="tbr" style="width: 100%;">
- <thead>
- <tr>
- <th data-align="center" data-field="id" data-formatter="setCode">序号</th>
- <th data-align="center" data-field="questname" data-formatter="Check">内容</th>
- <th data-align="center" data-field="grade" data-formatter="formatterFraction">分数</th>
- <th data-align="center" data-field="id" data-formatter="Removes">操作</th>
- </tr>
- </thead>
- <tbody>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- <script src="../js/eid/bootstrap-editable.js"></script>
- <script>
- var wid = helper.request.queryString("Str");
- var $tableLeft = $('#tbr');
- //console.log(wid);
- $(document).ready(function() {
- if(wid) {
- loadTable()
- //添加行
- $(".rightAdd ").click(function() {
- var index = $tableLeft.bootstrapTable('getData').length;
- //console.log(index)
- $.ajax({
- type: 'get',
- url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/AddTestQuestion",
- data: {
- testid: wid,
- questname: '',
- grade: '',
- token: $.cookie("token")
- },
- dataType: 'JSON',
- success: function(data) {
- if(data.state.toLowerCase() == 'success') {
- // $tableLeft.bootstrapTable('insertRow', {
- // index: index,
- // row: {
- // }
- // });
- $tableLeft.bootstrapTable('refresh');
- }
- },
- error: function() {
- alert("error");
- }
- });
- });
- }
- //列表
- });
- //序号
- function setCode(value, row, index) {
- return index + 1;
- }
- //修改
- function Check(value, row, index) {
- return '<a title="点击编辑" class="username" id="' + row.id + '" index="' + row.testid + '"fraction="' + row.grade + '">' + value + '</a>'
- }
- function formatterFraction(value, row, index) {
- return '<a title="点击编辑" class="fraction" id="' + row.id + '" index="' + row.testid + '"questname="' + row.questname + '">' + value + '</a>'
- }
- //操作
- function Removes(value, row, index) {
- var idStr = JSON.stringify(value).replace(/\"/g,"'");
- return '<div style="color: red"><a onclick="Remove(' + idStr + ')" >删除<i class="fa fa-remove size-14"></i></a></div>'
- }
- function loadTable() {
- //销毁表格
- $tableLeft.bootstrapTable('destroy');
- // 初始化表格,动态从服务器加载数据
- $tableLeft.bootstrapTable({
- method: "get", //使用get请求到服务器获取数据
- url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/Gettestquestinfo",
- striped: true, //表格显示条纹
- smartDisplay:false, //不显示分页,总条数
- pagination: false, //启动分页
- pageSize: 5, //每页显示的记录数
- pageNumber: 1, //当前第几页
- pageList: [5, 20, 50, 100], //记录数可选列表
- search: false, //是否启用查询
- showColumns: false, //显示下拉框勾选要显示的列
- showRefresh: false, //显示刷新按钮
- sidePagination: "server", //表示服务端请求
- //设置为undefined可以获取pageNumber,pageSize,searchText,sortName,sortOrder
- //设置为limit可以获取limit, offset, search, sort, order
- queryParamsType: "undefined",
- queryParams: function queryParams(params) { //设置查询参数
- var param = {
- pageindex: params.pageNumber,
- pagesize: params.pageSize,
- testid: wid,
- token: $.cookie("token"),
- };
- return param;
- },
- responseHandler: function(res) {
- return {
- // "total": res.data.total, //总页数
- "rows": res.data //数据
- };
- },
- onLoadSuccess: function() { //加载成功时执行
- editOptions();
- editFraction();
- //layer.msg("加载成功");
- },
- onLoadError: function() { //加载失败时执行
- //layer.msg("加载数据失败", { time: 1500, icon: 2 });
- }
- });
- }
- //删除
- function Remove(val) {
- $.ajax({
- type: 'get',
- url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/DelQuestion",
- data: {
- id: val,
- token: $.cookie("token")
- },
- dataType: 'JSON',
- success: function(data) {
- if(data.state.toLowerCase() == 'success') {
- var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
- parent.layer.close(index); //再执行关闭
- parent.Finish();
- parent.layer.msg("删除成功");
- }
- },
- error: function() {
- alert("error");
- }
- });
- }
- //编辑
- function editOptions() {
- $("#tbr a.username").editable({
- type: "text", //编辑框的类型。支持text|textarea|select|date|checklist等
- disabled: false, //是否禁用编辑
- emptytext: "请输入选项", //空值的默认文本
- mode: "inline", //编辑框的模式:支持popup和inline两种模式,默认是popup
- url: function(params) {
- $.ajax({
- type: 'get',
- url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/updateQuestion",
- data: {
- Id: $(this).attr("id"),
- questname: params.value,
- grade: $(this).attr("fraction"),
- testid: $(this).attr("index"),
- token: $.cookie("token")
- },
- dataType: 'JSON',
- success: function(data) {
- if(data.state.toLowerCase() == 'success') {
- var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
- //parent.layer.close(index); //再执行关闭
- parent.Finish();
- parent.layer.msg("保存成功");
- }
- },
- });
- },
- });
- }
- function editFraction() {
- $("#tbr a.fraction").editable({
- type: "text", //编辑框的类型。支持text|textarea|select|date|checklist等
- disabled: false, //是否禁用编辑
- emptytext: "请输入选项", //空值的默认文本
- mode: "inline", //编辑框的模式:支持popup和inline两种模式,默认是popup
- url: function(params) {
- $.ajax({
- type: 'get',
- url: huayi.config.callcenter_url + "testusertypeapi/api/TestUserType/updateQuestion",
- data: {
- Id: $(this).attr("id"),
- grade: params.value,
- questname: $(this).attr("questname"),
- testid: $(this).attr("index"),
- token: $.cookie("token")
- },
- dataType: 'JSON',
- success: function(data) {
- if(data.state.toLowerCase() == 'success') {
- var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
- //parent.layer.close(index); //再执行关闭
- parent.Finish();
- parent.layer.msg("保存成功");
- }
- },
- });
- },
- });
- }
-
- </script>
- </body>
- </html>
|