satisfaction.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. new Vue({
  2. el: "#app",
  3. data: {
  4. questions: [],
  5. questioncode: "03deb476eb634436b4d72b9965539065",
  6. answers: [],
  7. count: 0,
  8. toUserId: "",
  9. messageId:"",
  10. },
  11. mounted: function() {
  12. var vm = this
  13. var query = GetRequest();
  14. vm.messageId = query.messageId;
  15. var oauthInfo = JSON.parse(sessionStorage.getItem("oauthInfo"));
  16. vm.toUserId = oauthInfo.id
  17. vm.getQuestions()
  18. },
  19. methods: {
  20. getQuestions: function() {
  21. var vm = this
  22. jiuzhenAPI.getSatisfactionQuestionws({
  23. surveyTemplateCode: vm.questioncode
  24. }).then(function(res) {
  25. vm.questions = res.obj.questions
  26. })
  27. },
  28. checkRadio: function(q_sort, a_sort) {
  29. var vm = this
  30. q_sort = q_sort - 1
  31. var answer = $.extend(true, {}, vm.questions[q_sort])
  32. a_sort = a_sort - 1
  33. vm.pushAnswers(answer, q_sort, a_sort)
  34. },
  35. pushAnswers: function(answer, q_sort, a_sort) {
  36. var vm = this
  37. var options = answer.options[a_sort]
  38. answer.options = options
  39. //未答题
  40. if(answer.isAnswer == undefined) {
  41. vm.questions[q_sort].isAnswer = true
  42. vm.questions[q_sort].aid = vm.count
  43. vm.answers.push(answer)
  44. vm.count++
  45. } else {
  46. //已答题
  47. var count = vm.questions[q_sort].aid
  48. vm.answers[count] = answer
  49. }
  50. },
  51. sumbit: function() {
  52. var vm = this
  53. var all = vm.questions.length
  54. if(vm.answers.length < all) {
  55. var answer = vm.answers.concat()
  56. var answer1 = _.sortBy(answer, function(item) {
  57. return item.sort;
  58. })
  59. for(var i = 0; i < all; i++) {
  60. var j = i + 1
  61. if(answer1[i].sort != j) {
  62. toastr.warning("第" + j + "题未作答!")
  63. break;
  64. }
  65. }
  66. } else {
  67. var jsonData = {
  68. "userId": vm.toUserId,
  69. "surveyCode": vm.questioncode,
  70. "questions": vm.answers,
  71. "messageId": vm.messageId,
  72. }
  73. jiuzhenAPI.postSatisfactionAnswers({
  74. jsonData: JSON.stringify(jsonData)
  75. }).then(function(res) {
  76. toastr.success("提交答案成功。谢谢配合!")
  77. setTimeout(function(){vm.close()},3000)
  78. }).catch(function(err) {
  79. console.log(err)
  80. })
  81. }
  82. },
  83. close: function() {
  84. var index = top.layer.getFrameIndex(window.name);
  85. top.layer.close(index);
  86. }
  87. }
  88. });