testPage.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. // _this.$request.post({
  165. // url: `scaleExternalSource/save`,
  166. // loadingTip: "加载中...",
  167. // data: {
  168. // currentUserId: _this.userInfo.id,
  169. // resultId: _this.resultId,
  170. // uid: _this.uid,
  171. // source: _this.source,
  172. // flag: _this.flag,
  173. // },
  174. // }).then(() => {})
  175. uni.hideLoading();
  176. // 答题结束获取支付
  177. _this.getQueryPromotionBySubjectId();
  178. })
  179. .catch((err) => {
  180. _this.isLoading = false;
  181. uni.showToast({
  182. icon: "none",
  183. title: "提交失败",
  184. });
  185. uni.hideLoading();
  186. });
  187. },
  188. // 获取支付金额
  189. async getQueryPromotionBySubjectId() {
  190. let _this = this;
  191. let urls = queryPromotionBySubjectId + "/20210616235331";
  192. await _this.$request
  193. .get({
  194. url: urls,
  195. loadingTip: "加载中...",
  196. data: {},
  197. })
  198. .then((res) => {
  199. console.log('量表支付信息', res.data);
  200. let data = res.data;
  201. if (data.price == 0) {
  202. uni.navigateTo({
  203. url: `/newScale/Mental/testResult?resultId=${_this.resultId}&messageShare=1`
  204. });
  205. } else {
  206. let params = {
  207. productId: '20210616235331',
  208. userId: _this.userInfo?.id,
  209. resultId: _this.resultId,
  210. description: data.name,
  211. total: data.price,
  212. sceneType: uni.getSystemInfoSync().platform == "android" ?
  213. "Android" : "iOS",
  214. };
  215. uni.setStorageSync('orderInfo', params);
  216. uni.navigateTo({
  217. url: "/newScale/paymentPage/index?tName=Mental"
  218. });
  219. }
  220. });
  221. },
  222. checkActive(item) {
  223. return this.userAnswerList[this.currentIndex] && this.userAnswerList[this.currentIndex]
  224. .checkItems ==
  225. item ? 'active' : ''
  226. },
  227. getAnswerItem(arr) {
  228. return arr.split(';')
  229. },
  230. getQuestionParam(str) {
  231. return JSON.parse(str)
  232. }
  233. }
  234. }
  235. </script>
  236. <style scoped>
  237. .bg {
  238. width: 750rpx;
  239. min-height: 100vh;
  240. background: #000000;
  241. overflow: hidden;
  242. }
  243. .tips {
  244. font-family: 'Alibaba PuHuiTi 2.0';
  245. font-weight: normal;
  246. font-size: 24rpx;
  247. color: #666666;
  248. line-height: 60rpx;
  249. text-align: center;
  250. position: absolute;
  251. right: 49rpx;
  252. top: 4rpx;
  253. }
  254. .question_box {
  255. box-sizing: border-box;
  256. width: 702rpx;
  257. height: 1223rpx;
  258. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Mental/question_box_bg.png) no-repeat top;
  259. background-size: cover;
  260. margin: 44rpx auto 0;
  261. position: relative;
  262. }
  263. .question_title {
  264. width: 80%;
  265. margin: 40rpx auto 40rpx;
  266. font-family: 'Alibaba PuHuiTi 2.0';
  267. font-weight: normal;
  268. font-size: 36rpx;
  269. color: #333333;
  270. line-height: 46rpx;
  271. }
  272. .answer_list {
  273. width: 602rpx;
  274. height: 600rpx;
  275. margin-left: 41rpx;
  276. }
  277. .answer {
  278. display: flex;
  279. align-items: center;
  280. width: 498rpx;
  281. line-height: 88rpx;
  282. padding-left: 94rpx;
  283. margin-bottom: 36rpx;
  284. font-family: 'Alibaba PuHuiTi 2.0';
  285. font-weight: normal;
  286. font-size: 36rpx;
  287. color: #333333;
  288. cursor: pointer;
  289. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Mental/answer_bg.png);
  290. background-size: 100% 100%;
  291. transition: background 200ms linear;
  292. }
  293. .answer.active {
  294. background: url(https://test.jue-ming.com:8849/api/show?filePath=./webo/Mental/answer_bg_active.png);
  295. background-size: cover;
  296. color: #FFFFFF;
  297. }
  298. .prev_btn image {
  299. width: 288rpx;
  300. }
  301. .process {
  302. box-sizing: border-box;
  303. width: 521rpx;
  304. height: 20rpx;
  305. padding: 2rpx;
  306. background: #FFFFFF;
  307. box-shadow: 0rpx 0rpx 3rpx 0rpx rgba(133, 14, 45, 0.5);
  308. border-radius: 12rpx;
  309. overflow: hidden;
  310. margin: 20rpx 0 0 57rpx;
  311. }
  312. .process_bar {
  313. height: 14rpx;
  314. background: #FFA800;
  315. border-radius: 10rpx;
  316. transition: width 200ms linear;
  317. }
  318. .question_num {
  319. margin: 30rpx 0 0 28rpx;
  320. position: relative;
  321. }
  322. .num_front {
  323. font-family: 'Alibaba PuHuiTi 2.0';
  324. font-weight: bold;
  325. font-size: 48rpx;
  326. color: #471705;
  327. line-height: 55rpx;
  328. }
  329. .num_behond {
  330. font-family: 'Alibaba PuHuiTi 2.0';
  331. font-weight: normal;
  332. font-size: 32rpx;
  333. color: #471705;
  334. line-height: 55rpx;
  335. }
  336. .contral_box {
  337. display: flex;
  338. justify-content: center;
  339. align-items: center;
  340. margin: 17rpx 0 100rpx 0;
  341. }
  342. .prev_btn {
  343. margin: 0 20rpx;
  344. }
  345. .prev_btn image {
  346. width: 304rpx;
  347. }
  348. .paperclip {
  349. width: 55rpx;
  350. position: absolute;
  351. top: -40rpx;
  352. left: 38rpx;
  353. }
  354. .picker-view {
  355. width: 100%;
  356. height: 400rpx;
  357. }
  358. /deep/ .indicatorClass {
  359. height: 104rpx;
  360. border-top: 1px solid #5269FF;
  361. border-bottom: 1px solid #5269FF;
  362. }
  363. .picker_item {
  364. height: 104rpx;
  365. line-height: 104rpx;
  366. text-align: center;
  367. }
  368. </style>