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