testPage.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <view class="bg">
  3. <view class="question_box">
  4. <view style="overflow: hidden;"></view>
  5. <view style="display: flex; justify-content: space-between;align-items: center; margin: 38rpx 0 0 80rpx;">
  6. <view class="question_num">
  7. <text class="num_front">出题{{currentIndex + 1}}</text><text class="num_behond">/{{maxLength}}</text>
  8. </view>
  9. <view class="tips">请选择你的答案进入下一题</view>
  10. </view>
  11. <view class="question_title">
  12. <text>{{currentQuestion.answer}}</text>
  13. </view>
  14. <view class="answer_list">
  15. <view :class="['answer', checkActive(item)]" v-for="(item, index) in currentAnswerList"
  16. @click="nextHandle(item)">
  17. <text>
  18. {{item}}
  19. </text>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="contral_box">
  24. <view class="prev_btn" v-if="currentIndex > 0" @click="prevHandle">
  25. 上一题
  26. </view>
  27. <view class="prev_btn" v-if="userAnswerList.length >= questionList.length" @click="submitResult">
  28. 提交
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import {
  35. getResult,
  36. queryPromotionBySubjectId,
  37. } from "@/api/index.js";
  38. export default {
  39. data() {
  40. return {
  41. isChecked: true,
  42. isShake: false,
  43. scaleDetail: {},
  44. questionList: [],
  45. currentQuestion: {},
  46. currentAnswerList: [],
  47. currentIndex: 0,
  48. userAnswerList: [],
  49. resultId: '',
  50. isLoading: false,
  51. isDisbale: false,
  52. maxLength: 0,
  53. userInfo: {},
  54. questionImgList: [{
  55. 'qImg': 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/question1.png',
  56. 'answerImglist': [
  57. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer1-A.png',
  58. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer1-B.png',
  59. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer1-C.png'
  60. ]
  61. },
  62. {
  63. 'qImg': 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/question2.png',
  64. 'answerImglist': [
  65. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer2-A.png',
  66. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer2-B.png',
  67. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer2-C.png'
  68. ]
  69. },
  70. {
  71. 'qImg': 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/question3.png',
  72. 'answerImglist': [
  73. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer3-A.png',
  74. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer3-B.png',
  75. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer3-C.png'
  76. ]
  77. },
  78. {
  79. 'qImg': 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/question4.png',
  80. 'answerImglist': [
  81. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer4-A.png',
  82. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer4-B.png',
  83. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer4-C.png'
  84. ]
  85. },
  86. {
  87. 'qImg': 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/question5.png',
  88. 'answerImglist': [
  89. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer5-A.png',
  90. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer5-B.png',
  91. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Mbti/answer5-C.png'
  92. ]
  93. },
  94. ],
  95. userSelectArr: [],
  96. canPrev: false
  97. }
  98. },
  99. computed: {
  100. percentage() {
  101. return (this.userAnswerList.length / this.questionList.length) * 496 + 'rpx'
  102. }
  103. },
  104. created() {
  105. this.loadData();
  106. this.userInfo = uni.getStorageSync('user');
  107. },
  108. methods: {
  109. loadData() {
  110. this.$request
  111. .get({
  112. url: `scaleInfo/20210804162506`,
  113. loadingTip: "加载中...",
  114. data: {},
  115. }).then((res) => {
  116. this.questionList = JSON.parse(JSON.stringify(res.data));
  117. this.maxLength = this.questionList.length;
  118. this.currentQuestion = this.questionList[this.currentIndex];
  119. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  120. })
  121. },
  122. nextHandle(str) {
  123. if (this.isDisbale) {
  124. return;
  125. }
  126. this.isDisbale = true;
  127. this.userAnswerList[this.currentIndex] = JSON.parse(JSON.stringify(this.currentQuestion));
  128. this.userAnswerList[this.currentIndex].checkItems = str;
  129. if (this.currentIndex >= this.questionList.length - 1) {
  130. this.isDisbale = false;
  131. // this.submitResult();
  132. } else {
  133. setTimeout(() => {
  134. this.currentIndex++;
  135. this.currentQuestion = this.questionList[this.currentIndex];
  136. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  137. this.isDisbale = false;
  138. }, 150)
  139. }
  140. },
  141. prevHandle() {
  142. if (this.canPrev || this.currentIndex == 0) {
  143. return;
  144. }
  145. this.canPrev = true;
  146. setTimeout(() => {
  147. this.canPrev = false;
  148. this.currentIndex--;
  149. this.currentQuestion = this.questionList[this.currentIndex];
  150. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  151. }, 300)
  152. },
  153. submitResult() {
  154. let _this = this;
  155. if (_this.isLoading) {
  156. return
  157. }
  158. _this.isLoading = true;
  159. let params = {
  160. testPlanId: "",
  161. scale_result: _this.userAnswerList,
  162. userId: this.userInfo.id,
  163. };
  164. uni.showLoading({
  165. title: "测试结果生成中",
  166. });
  167. _this.$request
  168. .post({
  169. url: `${getResult}/20210804162506`,
  170. loadingTip: "加载中...",
  171. data: params,
  172. })
  173. .then((res) => {
  174. _this.isLoading = false;
  175. _this.resultId = res.data;
  176. uni.hideLoading();
  177. // 跳转支付页面
  178. uni.navigateTo({
  179. url: `/newScale/paymentPage/index?tName=Burnout&resultId=${_this.resultId}`
  180. });
  181. })
  182. .catch((err) => {
  183. _this.isLoading = false;
  184. uni.showToast({
  185. icon: "none",
  186. title: "提交失败",
  187. });
  188. uni.hideLoading();
  189. });
  190. },
  191. // 获取支付金额
  192. async getQueryPromotionBySubjectId() {
  193. let _this = this;
  194. let urls = queryPromotionBySubjectId + "/20210804162506";
  195. await _this.$request
  196. .get({
  197. url: urls,
  198. loadingTip: "加载中...",
  199. data: {},
  200. })
  201. .then((res) => {
  202. console.log('量表支付信息', res.data);
  203. let data = res.data;
  204. if (data.price == 0) {
  205. uni.navigateTo({
  206. url: `/newScale/Burnout/testResult?resultId=${_this.resultId}&messageShare=1`
  207. });
  208. } else {
  209. let params = {
  210. productId: '20210804162506',
  211. userId: _this.userInfo?.id,
  212. resultId: _this.resultId,
  213. description: data.name,
  214. total: data.price,
  215. sceneType: uni.getSystemInfoSync().platform == "android" ?
  216. "Android" : "iOS",
  217. };
  218. uni.setStorageSync('orderInfo', params);
  219. uni.navigateTo({
  220. url: "/newScale/paymentPage/index?tName=Burnout",
  221. });
  222. }
  223. });
  224. },
  225. checkActive(item) {
  226. return this.userAnswerList[this.currentIndex] && this.userAnswerList[this.currentIndex]
  227. .checkItems ==
  228. item ? 'active' : ''
  229. },
  230. getAnswerItem(arr) {
  231. return arr.split(';')
  232. }
  233. }
  234. }
  235. </script>
  236. <style scoped>
  237. .bg {
  238. width: 100%;
  239. min-height: 100vh;
  240. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Burnout/testPage_bg.png) no-repeat top;
  241. background-size: 100% auto;
  242. overflow: hidden;
  243. }
  244. .tips {
  245. font-family: 'Alibaba PuHuiTi 2.0';
  246. font-weight: normal;
  247. font-size: 24rpx;
  248. color: #999999;
  249. line-height: 60rpx;
  250. text-align: center;
  251. margin-right: 80rpx;
  252. }
  253. .question_box {
  254. box-sizing: border-box;
  255. width: 742rpx;
  256. height: 1053rpx;
  257. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Burnout/question_box_bg.png) no-repeat top;
  258. background-size: cover;
  259. margin: 220rpx auto 0;
  260. position: relative;
  261. }
  262. .question_title {
  263. width: 70%;
  264. height: 101rpx;
  265. margin: 37rpx 0 0 139rpx;
  266. font-family: 'Alibaba PuHuiTi 2.0';
  267. font-weight: normal;
  268. font-size: 36rpx;
  269. color: #333333;
  270. line-height: 46rpx;
  271. }
  272. .answer_list {
  273. width: 602rpx;
  274. height: 525rpx;
  275. margin: 10rpx 0 0 120rpx;
  276. }
  277. .answer {
  278. box-sizing: border-box;
  279. display: flex;
  280. align-items: center;
  281. width: 540rpx;
  282. height: 66rpx;
  283. padding: 0 5% 4rpx 16%;
  284. margin: 33rpx 0;
  285. font-family: 'Alibaba PuHuiTi 2.0';
  286. font-weight: normal;
  287. font-size: 32rpx;
  288. color: #333333;
  289. cursor: pointer;
  290. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Burnout/answer_bg.png) no-repeat center;
  291. background-size: cover;
  292. transition: background 200ms linear;
  293. }
  294. .answer.active {
  295. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Burnout/answer_bg_active.png) no-repeat center;
  296. background-size: cover;
  297. color: #FFFFFF;
  298. }
  299. .prev_btn {
  300. width: 288rpx;
  301. line-height: 71rpx;
  302. background: #fed23e;
  303. border: 2rpx solid #161616;
  304. border-radius: 36rpx;
  305. font-family: 'Alibaba PuHuiTi 2.0';
  306. font-weight: normal;
  307. font-size: 36rpx;
  308. color: #333333;
  309. text-align: center;
  310. }
  311. .process {
  312. box-sizing: border-box;
  313. width: 496rpx;
  314. height: 24rpx;
  315. background: #B63535;
  316. box-shadow: 0rpx 0rpx 3rpx 0rpx rgba(133, 14, 45, 0.5);
  317. border-radius: 12rpx;
  318. overflow: hidden;
  319. margin-right: 10rpx;
  320. }
  321. .process_bar {
  322. height: 24rpx;
  323. background: linear-gradient(91deg, #44FBA3 0%, #DAFA45 100%);
  324. border-radius: 10rpx;
  325. transition: width 200ms linear;
  326. }
  327. .question_num {
  328. text-align: right;
  329. }
  330. .num_front {
  331. font-family: Alibaba PuHuiTi 2.0;
  332. font-weight: bold;
  333. font-size: 48rpx;
  334. color: #FEFEFE;
  335. line-height: 55rpx;
  336. text-shadow: 2rpx 2rpx 5rpx rgba(146, 9, 0, 0.45);
  337. }
  338. .num_behond {
  339. font-family: Alibaba PuHuiTi 2.0;
  340. font-weight: bold;
  341. font-size: 32rpx;
  342. color: #FEFEFE;
  343. line-height: 55rpx;
  344. text-shadow: 2rpx 2rpx 5rpx rgba(146, 9, 0, 0.45);
  345. }
  346. .contral_box {
  347. display: flex;
  348. justify-content: center;
  349. align-items: center;
  350. margin: 57rpx 0 100rpx 0;
  351. }
  352. .prev_btn {
  353. margin: 0 20rpx;
  354. }
  355. .prev_btn image {
  356. width: 304rpx;
  357. }
  358. .paperclip {
  359. width: 55rpx;
  360. position: absolute;
  361. top: -40rpx;
  362. left: 38rpx;
  363. }
  364. </style>