testPage.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_index = require("../../api/index.js");
  4. const _sfc_main = {
  5. data() {
  6. return {
  7. isChecked: true,
  8. isShake: false,
  9. scaleDetail: {},
  10. questionList: [],
  11. currentQuestion: {},
  12. currentAnswerList: [],
  13. currentIndex: 0,
  14. userAnswerList: [],
  15. resultId: "",
  16. isLoading: false,
  17. isDisbale: false,
  18. maxLength: 0,
  19. userInfo: {}
  20. };
  21. },
  22. computed: {
  23. percentage() {
  24. return this.currentIndex / this.maxLength * 652 + "rpx";
  25. }
  26. },
  27. created() {
  28. this.loadData();
  29. this.userInfo = JSON.parse(sessionStorage.getItem("user"));
  30. },
  31. methods: {
  32. loadData() {
  33. this.$request.get({
  34. url: `scaleInfo/20210820143117`,
  35. loadingTip: "加载中...",
  36. data: {}
  37. }).then((res) => {
  38. this.questionList = JSON.parse(JSON.stringify(res.data));
  39. this.maxLength = this.questionList.length;
  40. this.currentQuestion = this.questionList[this.currentIndex];
  41. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  42. });
  43. },
  44. nextHandle(str) {
  45. if (this.isDisbale) {
  46. return;
  47. }
  48. this.isDisbale = true;
  49. this.userAnswerList[this.currentIndex] = JSON.parse(JSON.stringify(this.currentQuestion));
  50. this.userAnswerList[this.currentIndex].checkItems = str;
  51. if (this.currentIndex >= this.questionList.length - 1) {
  52. this.isDisbale = false;
  53. } else {
  54. setTimeout(() => {
  55. this.currentIndex++;
  56. this.currentQuestion = this.questionList[this.currentIndex];
  57. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  58. this.isDisbale = false;
  59. }, 150);
  60. }
  61. },
  62. prevHandle() {
  63. setTimeout(() => {
  64. this.currentIndex--;
  65. this.currentQuestion = this.questionList[this.currentIndex];
  66. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  67. }, 300);
  68. },
  69. submitResult() {
  70. let _this = this;
  71. if (_this.isLoading) {
  72. return;
  73. }
  74. _this.isLoading = true;
  75. let params = {
  76. testPlanId: "",
  77. scale_result: _this.userAnswerList,
  78. userId: JSON.parse(sessionStorage.getItem("user")).id
  79. };
  80. common_vendor.index.showLoading({
  81. title: "测试结果生成中"
  82. });
  83. _this.$request.post({
  84. url: `${api_index.getResult}/20210820143117`,
  85. loadingTip: "加载中...",
  86. data: params
  87. }).then((res) => {
  88. _this.resultId = res.data;
  89. common_vendor.index.hideLoading();
  90. _this.getQueryPromotionBySubjectId();
  91. _this.isLoading = false;
  92. }).catch(() => {
  93. common_vendor.index.showToast({
  94. icon: "none",
  95. title: "提交失败"
  96. });
  97. common_vendor.index.hideLoading();
  98. _this.isLoading = false;
  99. });
  100. },
  101. // 获取支付金额
  102. async getQueryPromotionBySubjectId() {
  103. let _this = this;
  104. let urls = api_index.queryPromotionBySubjectId + "/20210820143117";
  105. await _this.$request.get({
  106. url: urls,
  107. loadingTip: "加载中...",
  108. data: {}
  109. }).then((res) => {
  110. var _a;
  111. console.log("量表支付信息", res.data);
  112. let data = res.data;
  113. if (data.price == 0) {
  114. common_vendor.index.navigateTo({
  115. url: `/newScale/EQtest/testResult?resultId=${_this.resultId}&messageShare=1`
  116. });
  117. } else {
  118. let params = {
  119. productId: "20210820143117",
  120. userId: (_a = _this.userInfo) == null ? void 0 : _a.id,
  121. resultId: _this.resultId,
  122. description: data.name,
  123. total: data.price,
  124. sceneType: common_vendor.index.getSystemInfoSync().platform == "android" ? "Android" : "iOS"
  125. };
  126. sessionStorage.setItem("orderInfo", JSON.stringify(params));
  127. common_vendor.index.navigateTo({
  128. url: "/newScale/EQtest/paymentPage"
  129. });
  130. }
  131. });
  132. },
  133. checkActive(item) {
  134. return this.userAnswerList[this.currentIndex] && this.userAnswerList[this.currentIndex].checkItems == item ? "active" : "";
  135. },
  136. getAnswerItem(arr) {
  137. return arr.split(";");
  138. }
  139. }
  140. };
  141. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  142. return {
  143. a: $options.percentage,
  144. b: common_vendor.t($data.currentIndex + 1),
  145. c: common_vendor.t($data.maxLength),
  146. d: common_vendor.t($data.currentQuestion.answer),
  147. e: common_vendor.f($data.currentAnswerList, (item, index, i0) => {
  148. return {
  149. a: common_vendor.t(item),
  150. b: common_vendor.n(`answer${index + 1}`),
  151. c: common_vendor.n($options.checkActive(item)),
  152. d: common_vendor.o(($event) => $options.nextHandle(item))
  153. };
  154. }),
  155. f: $data.currentIndex > 0,
  156. g: common_vendor.o((...args) => $options.prevHandle && $options.prevHandle(...args)),
  157. h: $data.currentIndex >= $data.maxLength - 1,
  158. i: common_vendor.o((...args) => $options.submitResult && $options.submitResult(...args))
  159. };
  160. }
  161. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-a0c71dc4"], ["__file", "E:/psy_web_share/newScale/EQtest/testPage.vue"]]);
  162. tt.createPage(MiniProgramPage);