testPage.vue 9.5 KB

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