testPage.vue 7.8 KB

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