testPage.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <view class="bg">
  3. <view class="question_box">
  4. <view style="overflow: hidden;"></view>
  5. <view class="process">
  6. <view class="process_bar" :style="{'width': percentage}"></view>
  7. </view>
  8. <view class="question_num">
  9. <text class="num_front">出题{{currentIndex + 1}}</text><text class="num_behond">/ {{maxLength}}</text>
  10. <text class="tips">请选择你的答案进入下一题</text>
  11. </view>
  12. <view class="question_title">
  13. <text>{{currentQuestion.answer}}</text>
  14. </view>
  15. <view class="answer_list">
  16. <view v-if="currentQuestion.questionType == 5">
  17. <picker-view v-if="true" :value="pickValue" @change="bindChange" indicator-class="indicatorClass"
  18. class="picker-view">
  19. <picker-view-column>
  20. <view class="picker_item"
  21. v-for="(item, index) in getQuestionParam(currentQuestion.questionParam)" :key="index">
  22. {{item.name}}
  23. </view>
  24. </picker-view-column>
  25. </picker-view>
  26. </view>
  27. <view v-else :class="['answer', checkActive(item)]" v-for="(item, index) in currentAnswerList"
  28. @click="nextHandle(item)">
  29. <text>
  30. {{item}}
  31. </text>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="contral_box">
  36. <view class="prev_btn" v-if="currentIndex > 0" @click="prevHandle">
  37. <image src="https://test.jue-ming.com:8849/api/show?filePath=./webo/Mental/prev_btn.png"
  38. mode="widthFix"></image>
  39. </view>
  40. <view class="prev_btn"
  41. v-if="(userAnswerList.length < this.questionList.length - 1) && currentQuestion.questionType == 5"
  42. @click="nextHandle()">
  43. 下一题
  44. </view>
  45. <view class="prev_btn" v-if="userAnswerList.length >= questionList.length" @click="submitResult">
  46. <image src="https://test.jue-ming.com:8849/api/show?filePath=./webo/Mental/submit_btn.png"
  47. mode="widthFix"></image>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import {
  54. getResult,
  55. queryPromotionBySubjectId,
  56. } from "@/api/index.js";
  57. export default {
  58. data() {
  59. return {
  60. isChecked: true,
  61. isShake: false,
  62. scaleDetail: {},
  63. questionList: [],
  64. currentQuestion: {},
  65. currentAnswerList: [],
  66. currentIndex: 0,
  67. userAnswerList: [],
  68. resultId: '',
  69. isLoading: false,
  70. isDisbale: false,
  71. maxLength: 0,
  72. userInfo: {},
  73. userSelectArr: [],
  74. pickValue: [3],
  75. canPrev: false
  76. }
  77. },
  78. computed: {
  79. percentage() {
  80. return (this.userAnswerList.length / this.questionList.length) * 515 + 'rpx'
  81. }
  82. },
  83. created() {
  84. this.loadData();
  85. this.userInfo = uni.getStorageSync('user');
  86. },
  87. methods: {
  88. loadData() {
  89. this.$request
  90. .get({
  91. url: `scaleInfo/20210616235331`,
  92. loadingTip: "加载中...",
  93. data: {},
  94. }).then((res) => {
  95. this.questionList = JSON.parse(JSON.stringify(res.data));
  96. this.maxLength = this.questionList.length;
  97. this.currentQuestion = this.questionList[this.currentIndex];
  98. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  99. })
  100. },
  101. bindChange(item) {
  102. console.log(item);
  103. },
  104. nextHandle(str) {
  105. if (this.isDisbale) {
  106. return;
  107. }
  108. this.isDisbale = true;
  109. this.userAnswerList[this.currentIndex] = JSON.parse(JSON.stringify(this.currentQuestion));
  110. if (this.currentQuestion.questionType == 5) {
  111. let pickItems = this.getQuestionParam(this.currentQuestion.questionParam);
  112. this.userAnswerList[this.currentIndex].checkItems = pickItems[this.pickValue[0]].label;
  113. this.pickValue = [3];
  114. } else {
  115. this.userAnswerList[this.currentIndex].checkItems = str;
  116. }
  117. if (this.currentIndex >= this.questionList.length - 1) {
  118. this.isDisbale = false;
  119. // this.submitResult();
  120. } else {
  121. setTimeout(() => {
  122. this.currentIndex++;
  123. this.currentQuestion = this.questionList[this.currentIndex];
  124. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  125. this.isDisbale = false;
  126. }, 150)
  127. }
  128. },
  129. prevHandle() {
  130. if (this.canPrev || this.currentIndex == 0) {
  131. return;
  132. }
  133. this.canPrev = true;
  134. setTimeout(() => {
  135. this.canPrev = false;
  136. this.currentIndex--;
  137. this.currentQuestion = this.questionList[this.currentIndex];
  138. this.currentAnswerList = this.getAnswerItem(this.currentQuestion.checkItems);
  139. }, 300)
  140. },
  141. submitResult() {
  142. let _this = this;
  143. if (_this.isLoading) {
  144. return
  145. }
  146. _this.isLoading = true;
  147. let params = {
  148. testPlanId: "",
  149. scale_result: _this.userAnswerList,
  150. userId: this.userInfo.id,
  151. };
  152. uni.showLoading({
  153. title: "测试结果生成中",
  154. });
  155. _this.$request
  156. .post({
  157. url: `${getResult}/20210616235331`,
  158. loadingTip: "加载中...",
  159. data: params,
  160. })
  161. .then((res) => {
  162. _this.isLoading = false;
  163. _this.resultId = res.data;
  164. uni.hideLoading();
  165. // 跳转支付页面
  166. uni.navigateTo({
  167. url: `/newScale/paymentPage/index?tName=Mental&resultId=${_this.resultId}`
  168. });
  169. })
  170. .catch((err) => {
  171. _this.isLoading = false;
  172. uni.showToast({
  173. icon: "none",
  174. title: "提交失败",
  175. });
  176. uni.hideLoading();
  177. });
  178. },
  179. // 获取支付金额
  180. async getQueryPromotionBySubjectId() {
  181. let _this = this;
  182. let urls = queryPromotionBySubjectId + "/20210616235331";
  183. await _this.$request
  184. .get({
  185. url: urls,
  186. loadingTip: "加载中...",
  187. data: {},
  188. })
  189. .then((res) => {
  190. console.log('量表支付信息', res.data);
  191. let data = res.data;
  192. if (data.price == 0) {
  193. uni.navigateTo({
  194. url: `/newScale/Mental/testResult?resultId=${_this.resultId}&messageShare=1`
  195. });
  196. } else {
  197. let params = {
  198. productId: '20210616235331',
  199. userId: _this.userInfo?.id,
  200. resultId: _this.resultId,
  201. description: data.name,
  202. total: data.price,
  203. sceneType: uni.getSystemInfoSync().platform == "android" ?
  204. "Android" : "iOS",
  205. };
  206. uni.setStorageSync('orderInfo', params);
  207. uni.navigateTo({
  208. url: "/newScale/paymentPage/index?tName=Mental"
  209. });
  210. }
  211. });
  212. },
  213. checkActive(item) {
  214. return this.userAnswerList[this.currentIndex] && this.userAnswerList[this.currentIndex]
  215. .checkItems ==
  216. item ? 'active' : ''
  217. },
  218. getAnswerItem(arr) {
  219. return arr.split(';')
  220. },
  221. getQuestionParam(str) {
  222. return JSON.parse(str)
  223. }
  224. }
  225. }
  226. </script>
  227. <style scoped>
  228. .bg {
  229. width: 750rpx;
  230. min-height: 100vh;
  231. background: #000000;
  232. overflow: hidden;
  233. }
  234. .tips {
  235. font-family: 'Alibaba PuHuiTi 2.0';
  236. font-weight: normal;
  237. font-size: 24rpx;
  238. color: #666666;
  239. line-height: 60rpx;
  240. text-align: center;
  241. position: absolute;
  242. right: 49rpx;
  243. top: 4rpx;
  244. }
  245. .question_box {
  246. box-sizing: border-box;
  247. width: 702rpx;
  248. height: 1223rpx;
  249. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Mental/question_box_bg.png) no-repeat top;
  250. background-size: cover;
  251. margin: 44rpx auto 0;
  252. position: relative;
  253. }
  254. .question_title {
  255. width: 80%;
  256. margin: 40rpx auto 40rpx;
  257. font-family: 'Alibaba PuHuiTi 2.0';
  258. font-weight: normal;
  259. font-size: 36rpx;
  260. color: #333333;
  261. line-height: 46rpx;
  262. }
  263. .answer_list {
  264. width: 602rpx;
  265. height: 600rpx;
  266. margin-left: 41rpx;
  267. }
  268. .answer {
  269. display: flex;
  270. align-items: center;
  271. width: 498rpx;
  272. line-height: 88rpx;
  273. padding-left: 94rpx;
  274. margin-bottom: 36rpx;
  275. font-family: 'Alibaba PuHuiTi 2.0';
  276. font-weight: normal;
  277. font-size: 36rpx;
  278. color: #333333;
  279. cursor: pointer;
  280. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Mental/answer_bg.png);
  281. background-size: 100% 100%;
  282. transition: background 200ms linear;
  283. }
  284. .answer.active {
  285. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Mental/answer_bg_active.png);
  286. background-size: cover;
  287. color: #FFFFFF;
  288. }
  289. .prev_btn image {
  290. width: 288rpx;
  291. }
  292. .process {
  293. box-sizing: border-box;
  294. width: 521rpx;
  295. height: 20rpx;
  296. padding: 2rpx;
  297. background: #FFFFFF;
  298. box-shadow: 0rpx 0rpx 3rpx 0rpx rgba(133, 14, 45, 0.5);
  299. border-radius: 12rpx;
  300. overflow: hidden;
  301. margin: 20rpx 0 0 57rpx;
  302. }
  303. .process_bar {
  304. height: 14rpx;
  305. background: #FFA800;
  306. border-radius: 10rpx;
  307. transition: width 200ms linear;
  308. }
  309. .question_num {
  310. margin: 30rpx 0 0 28rpx;
  311. position: relative;
  312. }
  313. .num_front {
  314. font-family: 'Alibaba PuHuiTi 2.0';
  315. font-weight: bold;
  316. font-size: 48rpx;
  317. color: #471705;
  318. line-height: 55rpx;
  319. }
  320. .num_behond {
  321. font-family: 'Alibaba PuHuiTi 2.0';
  322. font-weight: normal;
  323. font-size: 32rpx;
  324. color: #471705;
  325. line-height: 55rpx;
  326. }
  327. .contral_box {
  328. display: flex;
  329. justify-content: center;
  330. align-items: center;
  331. margin: 17rpx 0 100rpx 0;
  332. }
  333. .prev_btn {
  334. margin: 0 20rpx;
  335. }
  336. .prev_btn image {
  337. width: 304rpx;
  338. }
  339. .paperclip {
  340. width: 55rpx;
  341. position: absolute;
  342. top: -40rpx;
  343. left: 38rpx;
  344. }
  345. .picker-view {
  346. width: 100%;
  347. height: 400rpx;
  348. }
  349. /deep/ .indicatorClass {
  350. height: 104rpx;
  351. border-top: 1px solid #5269FF;
  352. border-bottom: 1px solid #5269FF;
  353. }
  354. .picker_item {
  355. height: 104rpx;
  356. line-height: 104rpx;
  357. text-align: center;
  358. }
  359. </style>