No Description

addOrEditStfQestions.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * 满意度试题 增加或编辑
  3. * */
  4. $(function() {
  5. autosize($('textarea'));
  6. var lid = helper.request.queryString("lid");
  7. var edit_id = helper.request.queryString("edit_id");
  8. getQCategoryAlllist()
  9. .then(function() {
  10. if(lid != "undefined") {
  11. $('#pro_classify').val(lid);
  12. }
  13. if(edit_id) { //修改
  14. getProject(edit_id);
  15. }
  16. });
  17. //添加编辑保存按钮点击
  18. $('#pro_save').on('click', saveProject);
  19. });
  20. //获取详情
  21. function getProject(ids) {
  22. $.getJSON(huayi.config.callcenter_url + "Questionnaire/GetQuestionModel", {
  23. id: ids,
  24. token: $.cookie("token")
  25. }, function(data) {
  26. if(data.state == "success") {
  27. var res = data.data;
  28. if(res) {
  29. $('#pro_classify').val(res.F_CategoryId); //分类
  30. $('#pro_type').val(res.F_Type); //题型
  31. $('#pro_title').val(res.F_Title); // 是 string 名称
  32. $('#pro_remark').val(res.F_Remark); // 是 string 备注
  33. }
  34. }
  35. });
  36. }
  37. //保存项目
  38. function saveProject() {
  39. var edit_id = helper.request.queryString("edit_id");
  40. var wUrl;
  41. if(!$.trim($('#pro_classify').val())) {
  42. layer.confirm('试题分类不能为空', {
  43. icon: 2,
  44. btn: ['确定'] //按钮
  45. });
  46. return;
  47. }
  48. if(!$.trim($('#pro_title').val())) {
  49. layer.confirm('试题标题不能为空', {
  50. icon: 2,
  51. btn: ['确定'] //按钮
  52. });
  53. return;
  54. }
  55. if(edit_id) {
  56. wURL = "Questionnaire/CreateOrUpdateQuestion";
  57. } else {
  58. wURL = "Questionnaire/CreateOrUpdateQuestion";
  59. }
  60. $.post(huayi.config.callcenter_url + wURL, {
  61. F_QuestionId: edit_id, //试题ID
  62. F_CategoryId: $('#pro_classify').val(), //分类ID
  63. F_Title: $('#pro_title').val(), //试题标题
  64. //F_Content://试题内容
  65. F_Type: $("#pro_type").val(), //题型(1.问答题;2.单选题;3.多选题)
  66. F_Remark: $("#pro_remark").val(), //试题说明
  67. token: $.cookie("token"),
  68. }, function(data) {
  69. data = JSON.parse(data);
  70. if(data.state == "success") {
  71. var index = parent.layer.getFrameIndex(window.name);
  72. parent.layer.close(index);
  73. parent.$('#tbr').bootstrapTable('refresh');
  74. parent.layer.msg("保存成功");
  75. }
  76. });
  77. }
  78. //获取试题分类
  79. function getQCategoryAlllist() {
  80. var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
  81. $.ajax({
  82. type: "get",
  83. url: huayi.config.callcenter_url + "Questionnaire/GetQCategoryAlllist",
  84. dataType: 'json',
  85. async: true,
  86. data: {
  87. token: $.cookie("token")
  88. },
  89. success: function(data) {
  90. /*验证请求*/
  91. if(data.state == "success") {
  92. for(var i = 0; i < data.data.length; i++) {
  93. var html = '<option value="' + data.data[i].F_CategoryId + '">' + data.data[i].F_CategoryName + '</option>'
  94. $(html).appendTo("#pro_classify");
  95. }
  96. dtd.resolve(); // 改变Deferred对象的执行状态
  97. }
  98. }
  99. });
  100. return dtd.promise(); // 返回promise对象
  101. }