testPage.vue 8.1 KB

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