testPage.vue 9.8 KB

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