testPage.vue 9.8 KB

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