testPage.vue 9.0 KB

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