testPage.vue 12 KB

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