testPage.vue 9.2 KB

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