testPage.vue 9.9 KB

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