testPage.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <template>
  2. <view class="bg">
  3. <view class="question_box">
  4. <view style="overflow: hidden;"></view>
  5. <image class="paperclip" src="https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/paperclip.png"
  6. mode="widthFix"></image>
  7. <view class="question_num">
  8. <text class="num_front">出题{{currentIndex + 1}}</text><text class="num_behond">/{{maxLength}}</text>
  9. </view>
  10. <view class="process">
  11. <view class="process_bar" :style="{'width': percentage}"></view>
  12. </view>
  13. <view class="question_box_wrap">
  14. <view class="question_title">
  15. <text>{{currentQuestion.answer}}</text>
  16. </view>
  17. <view class="answer_list">
  18. <view :class="['answer', checkActive(item)]" v-for="(item, index) in currentAnswerList"
  19. @click="nextHandle(item)">
  20. <text>
  21. {{item}}
  22. </text>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="tips">请选择你的答案进入下一题</view>
  27. </view>
  28. <view class="contral_box">
  29. <view class="prev_btn" v-if="currentIndex > 0" @click="prevHandle">
  30. <image src="https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/prev_btn.png" mode="widthFix">
  31. </image>
  32. </view>
  33. <view class="prev_btn" v-if="userAnswerList.length >= 20" @click="submitResult">
  34. <image src="https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/submit_btn.png"
  35. mode="widthFix"></image>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import {
  42. getResult,
  43. queryPromotionBySubjectId,
  44. } from "@/api/index.js";
  45. export default {
  46. data() {
  47. return {
  48. isChecked: true,
  49. isShake: false,
  50. scaleDetail: {},
  51. questionList: [],
  52. currentQuestion: {},
  53. currentAnswerList: [],
  54. currentIndex: 0,
  55. userAnswerList: [],
  56. resultId: '',
  57. isLoading: false,
  58. isDisbale: false,
  59. maxLength: 0,
  60. userInfo: {},
  61. questionImgList: [{
  62. 'qImg': 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/question1.png',
  63. 'answerImglist': [
  64. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer1-A.png',
  65. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer1-B.png',
  66. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer1-C.png'
  67. ]
  68. },
  69. {
  70. 'qImg': 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/question2.png',
  71. 'answerImglist': [
  72. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer2-A.png',
  73. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer2-B.png',
  74. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer2-C.png'
  75. ]
  76. },
  77. {
  78. 'qImg': 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/question3.png',
  79. 'answerImglist': [
  80. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer3-A.png',
  81. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer3-B.png',
  82. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer3-C.png'
  83. ]
  84. },
  85. {
  86. 'qImg': 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/question4.png',
  87. 'answerImglist': [
  88. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer4-A.png',
  89. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer4-B.png',
  90. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer4-C.png'
  91. ]
  92. },
  93. {
  94. 'qImg': 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/question5.png',
  95. 'answerImglist': [
  96. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer5-A.png',
  97. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer5-B.png',
  98. 'https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer5-C.png'
  99. ]
  100. },
  101. ],
  102. userSelectArr: [],
  103. canPrev: false
  104. }
  105. },
  106. computed: {
  107. percentage() {
  108. return (this.userAnswerList.length / this.questionList.length) * 613 + 'rpx'
  109. }
  110. },
  111. created() {
  112. this.loadData();
  113. this.userInfo = uni.getStorageSync('user');
  114. },
  115. methods: {
  116. loadData() {
  117. this.$request
  118. .get({
  119. url: `scaleInfo/20210804164957`,
  120. loadingTip: "加载中...",
  121. data: {},
  122. }).then((res) => {
  123. this.questionList = JSON.parse(JSON.stringify(res.data));
  124. this.maxLength = this.questionList.length;
  125. this.currentQuestion = this.questionList[this.currentIndex];
  126. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  127. })
  128. },
  129. nextHandle(str) {
  130. if (this.isDisbale) {
  131. return;
  132. }
  133. this.isDisbale = true;
  134. this.userAnswerList[this.currentIndex] = JSON.parse(JSON.stringify(this.currentQuestion));
  135. this.userAnswerList[this.currentIndex].checkItems = str;
  136. if (this.currentIndex >= this.questionList.length - 1) {
  137. this.isDisbale = false;
  138. // this.submitResult();
  139. } else {
  140. setTimeout(() => {
  141. this.currentIndex++;
  142. this.currentQuestion = this.questionList[this.currentIndex];
  143. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  144. this.isDisbale = false;
  145. }, 150)
  146. }
  147. },
  148. prevHandle() {
  149. if (this.canPrev || this.currentIndex == 0) {
  150. return;
  151. }
  152. this.canPrev = true;
  153. setTimeout(() => {
  154. this.canPrev = false;
  155. this.currentIndex--;
  156. this.currentQuestion = this.questionList[this.currentIndex];
  157. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  158. }, 300)
  159. },
  160. submitResult() {
  161. let _this = this;
  162. if (_this.isLoading) {
  163. return
  164. }
  165. _this.isLoading = true;
  166. let params = {
  167. testPlanId: "",
  168. scale_result: _this.userAnswerList,
  169. userId: this.userInfo.id,
  170. };
  171. uni.showLoading({
  172. title: "测试结果生成中",
  173. });
  174. _this.$request
  175. .post({
  176. url: `${getResult}/20210804164957`,
  177. loadingTip: "加载中...",
  178. data: params,
  179. })
  180. .then((res) => {
  181. _this.isLoading = false;
  182. _this.resultId = res.data;
  183. // _this.$request.post({
  184. // url: `scaleExternalSource/save`,
  185. // loadingTip: "加载中...",
  186. // data: {
  187. // currentUserId: _this.userInfo.id,
  188. // resultId: _this.resultId,
  189. // uid: _this.uid,
  190. // source: _this.source,
  191. // flag: _this.flag,
  192. // },
  193. // }).then(() => {})
  194. uni.hideLoading();
  195. // 答题结束获取支付
  196. _this.getQueryPromotionBySubjectId();
  197. })
  198. .catch(() => {
  199. _this.isLoading = false;
  200. uni.showToast({
  201. icon: "none",
  202. title: "提交失败",
  203. });
  204. uni.hideLoading();
  205. });
  206. },
  207. // 获取支付金额
  208. async getQueryPromotionBySubjectId() {
  209. let _this = this;
  210. let urls = queryPromotionBySubjectId + "/20210804164957";
  211. await _this.$request
  212. .get({
  213. url: urls,
  214. loadingTip: "加载中...",
  215. data: {},
  216. })
  217. .then((res) => {
  218. console.log('量表支付信息', res.data);
  219. let data = res.data;
  220. if (data.price == 0) {
  221. uni.navigateTo({
  222. url: `/newScale/Charm/testResult?resultId=${_this.resultId}&messageShare=1`
  223. });
  224. } else {
  225. let params = {
  226. productId: '20210804164957',
  227. userId: _this.userInfo?.id,
  228. resultId: _this.resultId,
  229. description: data.name,
  230. total: data.price,
  231. sceneType: uni.getSystemInfoSync().platform == "android" ?
  232. "Android" : "iOS",
  233. };
  234. uni.setStorageSync('orderInfo', params);
  235. uni.navigateTo({
  236. url: "/newScale/paymentPage/index?tName=Charm"
  237. });
  238. }
  239. });
  240. },
  241. checkActive(item) {
  242. return this.userAnswerList[this.currentIndex] && this.userAnswerList[this.currentIndex]
  243. .checkItems ==
  244. item ? 'active' : ''
  245. },
  246. getAnswerItem(arr) {
  247. return arr.split(';')
  248. }
  249. }
  250. }
  251. </script>
  252. <style scoped>
  253. .bg {
  254. width: 100%;
  255. min-height: 100vh;
  256. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/testPage_bg.png) no-repeat top;
  257. background-size: 100% auto;
  258. overflow: hidden;
  259. }
  260. .tips {
  261. font-family: 'Alibaba PuHuiTi 2.0';
  262. font-weight: normal;
  263. font-size: 28rpx;
  264. color: #FFFFFF;
  265. line-height: 60rpx;
  266. text-align: center;
  267. }
  268. .question_box {
  269. box-sizing: border-box;
  270. width: 702rpx;
  271. height: 1021rpx;
  272. background: linear-gradient(0deg, #EA1750 0%, #FF8189 100%);
  273. border-radius: 26rpx;
  274. padding: 0 15rpx;
  275. margin: 43rpx auto;
  276. position: relative;
  277. }
  278. .question_box_wrap {
  279. width: 668rpx;
  280. height: 830rpx;
  281. background: linear-gradient(0deg, #FFFFFF 76%, #FFEAEF 100%);
  282. box-shadow: 0rpx 0rpx 3rpx 0rpx rgba(133, 14, 45, 0.5);
  283. border-radius: 20rpx;
  284. border: 2px solid #FFFFFF;
  285. }
  286. .question_title {
  287. box-sizing: border-box;
  288. width: 100%;
  289. height: 160rpx;
  290. font-family: 'YanShiXieHeiTi';
  291. font-size: 40rpx;
  292. text-align: justify;
  293. color: #EA1750;
  294. padding: 16px 30rpx 0 30rpx;
  295. }
  296. .question_box text.qs_txt {
  297. padding-bottom: 4rpx;
  298. border-bottom: 4rpx solid #2E9AFF;
  299. line-height: 1.6;
  300. }
  301. .item00 {
  302. width: 262rpx;
  303. position: absolute;
  304. top: 115rpx;
  305. left: 16rpx;
  306. }
  307. .item01 {
  308. width: 341rpx;
  309. position: absolute;
  310. top: -16rpx;
  311. right: 6rpx;
  312. }
  313. .item02 {
  314. width: 362rpx;
  315. position: absolute;
  316. bottom: 36rpx;
  317. left: 203rpx;
  318. }
  319. .item10 {
  320. width: 294rpx;
  321. position: absolute;
  322. top: 44rpx;
  323. left: 26rpx;
  324. }
  325. .item11 {
  326. width: 266rpx;
  327. position: absolute;
  328. top: 83rpx;
  329. right: 49rpx;
  330. }
  331. .item12 {
  332. width: 303rpx;
  333. position: absolute;
  334. bottom: 50rpx;
  335. left: 177rpx;
  336. }
  337. .item20 {
  338. width: 275rpx;
  339. position: absolute;
  340. top: 32rpx;
  341. left: 210rpx;
  342. }
  343. .item21 {
  344. width: 272rpx;
  345. position: absolute;
  346. left: 59rpx;
  347. bottom: 132rpx;
  348. }
  349. .item22 {
  350. width: 248rpx;
  351. position: absolute;
  352. bottom: 71rpx;
  353. right: 32rpx;
  354. }
  355. .item30 {
  356. width: 362rpx;
  357. position: absolute;
  358. top: 21rpx;
  359. left: 0rpx;
  360. }
  361. .item31 {
  362. width: 358rpx;
  363. position: absolute;
  364. right: 7rpx;
  365. top: 116rpx;
  366. }
  367. .item32 {
  368. width: 386rpx;
  369. position: absolute;
  370. bottom: 0;
  371. left: 64rpx;
  372. }
  373. .item40 {
  374. width: 269rpx;
  375. position: absolute;
  376. top: 149rpx;
  377. left: 36rpx;
  378. }
  379. .item41 {
  380. width: 263rpx;
  381. position: absolute;
  382. right: 9rpx;
  383. top: 129rpx;
  384. }
  385. .item42 {
  386. width: 269rpx;
  387. position: absolute;
  388. right: 122rpx;
  389. bottom: 42rpx;
  390. }
  391. .answer_list {
  392. box-sizing: border-box;
  393. width: 100%;
  394. height: 725rpx;
  395. padding-top: 56rpx;
  396. position: relative;
  397. }
  398. .answer {
  399. box-sizing: border-box;
  400. display: flex;
  401. align-items: center;
  402. width: 602rpx;
  403. height: 137rpx;
  404. padding: 0 6% 4rpx 14%;
  405. margin: 33rpx 0;
  406. font-family: 'Alibaba PuHuiTi 2.0';
  407. font-weight: normal;
  408. font-size: 32rpx;
  409. color: #333333;
  410. cursor: pointer;
  411. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer_bg.png);
  412. background-size: 100% 100%;
  413. transition: background 200ms linear;
  414. margin: 0 auto 45rpx;
  415. }
  416. .answer.active {
  417. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/answer_bg_active.png);
  418. background-size: 100% 100%;
  419. color: #FFFFFF;
  420. }
  421. .prev_btn {
  422. text-align: center;
  423. }
  424. .process {
  425. box-sizing: border-box;
  426. width: 613rpx;
  427. height: 16rpx;
  428. padding: 0;
  429. background: linear-gradient(0deg, #FFFFFF 0%, #FFEAEF 100%);
  430. box-shadow: 0rpx 0rpx 3rpx 0rpx rgba(133, 14, 45, 0.5);
  431. border-radius: 8rpx;
  432. border: 1px solid #FFFFFF;
  433. overflow: hidden;
  434. margin: 6rpx auto 14rpx;
  435. }
  436. .process_bar {
  437. height: 12rpx;
  438. background: #F54E6D;
  439. border-radius: 10rpx;
  440. transition: width 200ms linear;
  441. }
  442. .question_num {
  443. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Charm/question_num_bg.png) no-repeat;
  444. background-size: cover;
  445. text-align: right;
  446. margin: 14rpx 53rpx 0 0;
  447. }
  448. .num_front {
  449. font-family: Alibaba PuHuiTi 2.0;
  450. font-weight: bold;
  451. font-size: 48rpx;
  452. color: #FEFEFE;
  453. line-height: 55rpx;
  454. text-shadow: 2rpx 2rpx 5rpx rgba(146, 9, 0, 0.45);
  455. }
  456. .num_behond {
  457. font-family: Alibaba PuHuiTi 2.0;
  458. font-weight: bold;
  459. font-size: 32rpx;
  460. color: #FEFEFE;
  461. line-height: 55rpx;
  462. text-shadow: 2rpx 2rpx 5rpx rgba(146, 9, 0, 0.45);
  463. }
  464. .contral_box {
  465. display: flex;
  466. justify-content: center;
  467. align-items: center;
  468. margin: 54rpx 0 100rpx 0;
  469. }
  470. .prev_btn {
  471. margin: 0 20rpx;
  472. }
  473. .prev_btn image {
  474. width: 304rpx;
  475. }
  476. .paperclip {
  477. width: 55rpx;
  478. position: absolute;
  479. top: -40rpx;
  480. left: 38rpx;
  481. }
  482. </style>