zhi_xing_gong_neng.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. // pages/zhi_xing_gong_neng/zhi_xing_gong_neng.js
  2. const { throttle } = require('../../utils/util.js')
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. isZxgn:true,
  10. isAnswer:false,
  11. statusBar: app.globalData.statusBar,
  12. remainTime:0,
  13. mentalRotation:0,
  14. graphicReasoning:0,
  15. spaceImagination:0,
  16. executionFunctionality:0,
  17. visualSearch:0,
  18. workingMemory:0,
  19. times:0,
  20. isWay:0,
  21. level:0,
  22. isCorrect:false,
  23. isMistake:false,
  24. // ageGroup:16,
  25. smallList: ['一', '二', '三', '四','五'],
  26. bigList: ['六','七','八','九','十'],
  27. randomList: ['一','四','六','七','九'],
  28. zxgnList:[
  29. {
  30. score:0
  31. },
  32. {
  33. score: 0
  34. },
  35. {
  36. score: 0
  37. },
  38. {
  39. score: 0
  40. },
  41. {
  42. score: 0
  43. },
  44. {
  45. score: 0
  46. },
  47. {
  48. score: 0
  49. },
  50. {
  51. score: 0
  52. },
  53. {
  54. score: 0
  55. },
  56. {
  57. score: 0
  58. }
  59. ],
  60. exerciseList:[
  61. {
  62. idx: 1,
  63. title: '谁最大?',
  64. score:0,
  65. answerList: [
  66. {
  67. text: 'A',
  68. num:Math.floor(Math.random() * (0 - 5) + 5),
  69. isAnswer: 0,
  70. status: ''
  71. },
  72. {
  73. text: 'B',
  74. num: Math.floor(Math.random() * (5 - 10) + 10),
  75. isAnswer: 1,
  76. status: ''
  77. }
  78. ]
  79. }
  80. ],
  81. oneList:[
  82. {
  83. idx: 0,
  84. title: '谁最大?',
  85. score:0,
  86. answerList: [
  87. {
  88. text: 'A',
  89. num:Math.floor(Math.random() * (0 - 5) + 5),
  90. isAnswer: 0,
  91. status: ''
  92. },
  93. {
  94. text: 'B',
  95. num: Math.floor(Math.random() * (5 - 10) + 10),
  96. isAnswer: 1,
  97. status: ''
  98. }
  99. ]
  100. },
  101. {
  102. idx: 1,
  103. title: '谁最小?',
  104. score: 0,
  105. answerList: [
  106. {
  107. text: 'A',
  108. num:Math.floor(Math.random() * (0 - 5) + 5),
  109. isAnswer: 1,
  110. status: ''
  111. },
  112. {
  113. text: 'B',
  114. num:Math.floor(Math.random() * (0 - 5) + 5),
  115. isAnswer: 0,
  116. status: ''
  117. }
  118. ]
  119. },
  120. {
  121. idx: 2,
  122. title: '谁最小?',
  123. score: 0,
  124. answerList: [
  125. {
  126. text: 'A',
  127. num:Math.floor(Math.random() * (0 - 5) + 5),
  128. isAnswer: 1,
  129. status: ''
  130. },
  131. {
  132. text: 'B',
  133. num:'十',
  134. isAnswer: 0,
  135. status: ''
  136. }
  137. ]
  138. },
  139. {
  140. idx:3,
  141. title: '谁最大?',
  142. score: 0,
  143. answerList: [
  144. {
  145. text: 'A',
  146. num:Math.floor(Math.random() * (3 - 7) + 7),
  147. isAnswer: 0,
  148. status: ''
  149. },
  150. {
  151. text: 'B',
  152. num:Math.floor(Math.random() * (9 - 10) + 10),
  153. isAnswer: 1,
  154. status: ''
  155. }
  156. ]
  157. },
  158. {
  159. idx: 4,
  160. title: '谁最小?',
  161. score: 0,
  162. answerList: [
  163. {
  164. text: 'A',
  165. num:Math.floor(Math.random() * (0 - 5) + 5),
  166. isAnswer: 0,
  167. status: ''
  168. },
  169. {
  170. text: 'B',
  171. num:Math.floor(Math.random() * (0 - 5) + 5),
  172. isAnswer: 1,
  173. status: ''
  174. }
  175. ]
  176. },
  177. {
  178. idx:5,
  179. title: '谁最大?',
  180. score: 0,
  181. answerList: [
  182. {
  183. text: 'A',
  184. num:Math.floor(Math.random() * (6 - 10) + 10),
  185. isAnswer: 1,
  186. status: ''
  187. },
  188. {
  189. text: 'B',
  190. num:Math.floor(Math.random() * (2 - 5) + 5),
  191. isAnswer: 0,
  192. status: ''
  193. }
  194. ]
  195. },
  196. {
  197. idx: 6,
  198. title: '谁最小?',
  199. score: 0,
  200. answerList: [
  201. {
  202. text: 'A',
  203. num:Math.floor(Math.random() * (4 - 8) + 8),
  204. isAnswer: 0,
  205. status: ''
  206. },
  207. {
  208. text: 'B',
  209. num:Math.floor(Math.random() * (9 - 10) + 10),
  210. isAnswer: 1,
  211. status: ''
  212. }
  213. ]
  214. },
  215. {
  216. idx: 7,
  217. title: '谁最大?',
  218. score: 0,
  219. answerList: [
  220. {
  221. text: 'A',
  222. num:Math.floor(Math.random() * (0 - 3) + 3),
  223. isAnswer: 1,
  224. status: ''
  225. },
  226. {
  227. text: 'B',
  228. num:'九',
  229. isAnswer: 0,
  230. status: ''
  231. }
  232. ]
  233. },
  234. {
  235. idx: 8,
  236. title: '谁最大?',
  237. score: 0,
  238. answerList: [
  239. {
  240. text: 'A',
  241. num:Math.floor(Math.random() * (4 - 6) + 6),
  242. isAnswer: 1,
  243. status: ''
  244. },
  245. {
  246. text: 'B',
  247. num:Math.floor(Math.random() * (0 - 3) + 3),
  248. isAnswer: 0,
  249. status: ''
  250. }
  251. ]
  252. },
  253. {
  254. idx: 9,
  255. title: '谁最小?',
  256. score: 0,
  257. answerList: [
  258. {
  259. text: 'A',
  260. num:Math.floor(Math.random() * (0 - 5) + 5),
  261. isAnswer: 0,
  262. status: ''
  263. },
  264. {
  265. text: 'B',
  266. num:Math.floor(Math.random() * (0 - 5) + 5),
  267. isAnswer: 1,
  268. status: ''
  269. }
  270. ]
  271. },
  272. ]
  273. },
  274. /**
  275. * 生命周期函数--监听页面加载
  276. */
  277. onLoad: function (options) {
  278. this.setData(options)
  279. // console.log(options)
  280. this.setData({
  281. isOne: Math.round(Math.random()),
  282. small2: Math.floor(Math.random() * (0 - 5) + 5),
  283. small: Math.floor(Math.random() * (1 - 5) + 5),
  284. big: Math.floor(Math.random() * (6 - 10) + 10),
  285. })
  286. },
  287. /**
  288. * 生命周期函数--监听页面初次渲染完成
  289. */
  290. onReady: function () {
  291. },
  292. /**
  293. * 生命周期函数--监听页面显示
  294. */
  295. onShow: function () {
  296. },
  297. /**
  298. * 生命周期函数--监听页面隐藏
  299. */
  300. onHide: function () {
  301. },
  302. /**
  303. * 生命周期函数--监听页面卸载
  304. */
  305. onUnload: function () {
  306. },
  307. /**
  308. * 页面相关事件处理函数--监听用户下拉动作
  309. */
  310. onPullDownRefresh: function () {
  311. },
  312. /**
  313. * 页面上拉触底事件的处理函数
  314. */
  315. onReachBottom: function () {
  316. },
  317. /**
  318. * 用户点击右上角分享
  319. */
  320. onShareAppMessage: function () {
  321. },
  322. /**
  323. * 返回上一级页面
  324. */
  325. blockCtl: function () {
  326. this.redirectCtl({ url: 'me', method: {} }, true)
  327. this.endSetInter();
  328. },
  329. /**
  330. * 开始答题
  331. */
  332. actionAnswer: function () {
  333. const { isZxgn } = this.data;
  334. this.setData({ isZxgn: false })
  335. },
  336. /**
  337. * 底部导航跳转
  338. */
  339. redirectCtl: app.redirectCtl,
  340. /**
  341. * 练习关选择答案
  342. */
  343. exerciseSelectItems:throttle(function(e){
  344. const {lindex, mindex} = e.currentTarget.dataset;
  345. const { exerciseList, times,level} = this.data;
  346. var that = this;
  347. var temp = {};
  348. for (var i in exerciseList[lindex].answerList) {
  349. temp[`exerciseList[${lindex}].answerList[${i}].status`] = '';
  350. }
  351. if (exerciseList[lindex].answerList[mindex].isAnswer == 1) {
  352. that.setData({ isYes: true })
  353. } else {
  354. that.setData({ isYes: false })
  355. }
  356. temp[`exerciseList[${lindex}].answerList[${mindex}].status`] = exerciseList[lindex].answerList[mindex].status == '' ? 'active' : ''
  357. this.setData(temp);
  358. this.setData({ isAnswer: true})
  359. setTimeout(
  360. function () {
  361. that.setData({ level:1,isWhite:true,isAnswer:false,times: 0})
  362. that.hiddenShow()
  363. }, 500)
  364. },1000),
  365. /**
  366. * 选择答案
  367. */
  368. selectItems:throttle(function(e){
  369. const {lindex, mindex} = e.currentTarget.dataset;
  370. const { oneList, times,level} = this.data;
  371. // console.log(lindex, mindex)
  372. var that = this;
  373. var temp = {};
  374. for (var i in oneList[lindex].answerList) {
  375. temp[`oneList[${lindex}].answerList[${i}].status`] = '';
  376. }
  377. temp[`oneList[${lindex}].answerList[${mindex}].status`]='active';
  378. this.setData(temp);
  379. if (oneList[lindex].answerList[mindex].isAnswer == 1) {
  380. that.setData({ isYes: true,isAnswer: true })
  381. that.integraeRule(lindex, 1)
  382. that.endSetInter();
  383. } else {
  384. that.setData({ isYes: false,isAnswer: true })
  385. that.integraeRule(lindex, 0)
  386. that.endSetInter();
  387. }
  388. setTimeout(
  389. function () {
  390. if(lindex+1==10){
  391. that.endSetInter();
  392. that.tenEndTimes()
  393. }else{
  394. that.setData({ level:1,isWhite:true,isOneImgShow:false,isWay: lindex +1,isAnswer:false,times: 0})
  395. that.hiddenShow()
  396. }
  397. }, 300)
  398. },800),
  399. /**
  400. * 过渡页显示
  401. */
  402. hiddenShow:function(){
  403. const {isWhite} = this.data;
  404. var that = this;
  405. setTimeout(function () {
  406. that.setData({ isWhite:false})
  407. that.startSetInter()
  408. }, 500)
  409. },
  410. /**
  411. * 积分规则处理
  412. */
  413. integraeRule: function (bindex,tindex) {
  414. const { zxgnList, times, isWay,ageGroup} = this.data;
  415. var that = this;
  416. var temp = {};
  417. // console.log(ageGroup,bindex)
  418. that.saveCase(tindex)
  419. if (tindex==1){
  420. if (0<ageGroup&&ageGroup <= 8) {
  421. if(0<times&&times<1.4){
  422. temp[`zxgnList[${bindex}].score`] = 10;
  423. }else if(1.4<=times&&times<=1.7){
  424. temp[`zxgnList[${bindex}].score`] = 8;
  425. }else if(times>1.7){
  426. temp[`zxgnList[${bindex}].score`] = 5;
  427. }
  428. }else if (9<=ageGroup&&ageGroup <= 12) {
  429. if(0<times&&times<1.2){
  430. temp[`zxgnList[${bindex}].score`] = 10;
  431. }else if(1.2<=times&&times<=1.5){
  432. temp[`zxgnList[${bindex}].score`] = 8;
  433. }else if(times>1.5){
  434. temp[`zxgnList[${bindex}].score`] = 5;
  435. }
  436. }else if (13<=ageGroup&&ageGroup <= 15) {
  437. if(0<times&&times<1){
  438. temp[`zxgnList[${bindex}].score`] = 10;
  439. }else if(1<=times&&times<=1.2){
  440. temp[`zxgnList[${bindex}].score`] = 8;
  441. }else if(times>1.2){
  442. temp[`zxgnList[${bindex}].score`] = 5;
  443. }
  444. }else if (16<=ageGroup&&ageGroup <= 35) {
  445. if(0<times&&times<0.8){
  446. temp[`zxgnList[${bindex}].score`] = 10;
  447. }else if(0.8<=times&&times<=1.1){
  448. temp[`zxgnList[${bindex}].score`] = 8;
  449. }else if(times>1.1){
  450. temp[`zxgnList[${bindex}].score`] = 5;
  451. }
  452. }else if (36<=ageGroup&&ageGroup <= 49) {
  453. if(0<times&&times<1){
  454. temp[`zxgnList[${bindex}].score`] = 10;
  455. }else if(1<=times&&times<=1.2){
  456. temp[`zxgnList[${bindex}].score`] = 8;
  457. }else if(times>1.2){
  458. temp[`zxgnList[${bindex}].score`] = 5;
  459. }
  460. }else if (50<=ageGroup&&ageGroup <= 60) {
  461. if(0<times&&times<1.2){
  462. temp[`zxgnList[${bindex}].score`] = 10;
  463. }else if(1.2<=times&&times<=1.5){
  464. temp[`zxgnList[${bindex}].score`] = 8;
  465. }else if(times>1.5){
  466. temp[`zxgnList[${bindex}].score`] = 5;
  467. }
  468. }else if (ageGroup>60) {
  469. if(0<times&&times<1.4){
  470. temp[`zxgnList[${bindex}].score`] = 10;
  471. }else if(1.4<=times&&times<=1.7){
  472. temp[`zxgnList[${bindex}].score`] = 8;
  473. }else if(times>1.7){
  474. temp[`zxgnList[${bindex}].score`] = 5;
  475. }
  476. }
  477. }else{
  478. temp[`zxgnList[${bindex}].score`] = 0;
  479. }
  480. // console.log(temp)
  481. that.setData(temp);
  482. if (isWay == 10){
  483. clearTimeout(that.data.timer)
  484. that.tenEndTimes();
  485. }
  486. },
  487. /**
  488. * 结束计时
  489. */
  490. endSetInter: function () {
  491. var that = this;
  492. clearTimeout(that.data.setInter)
  493. },
  494. /**
  495. * 开始计时
  496. */
  497. startSetInter: function () {
  498. let time = 100;
  499. var that = this;
  500. let { times, isWay } = this.data;
  501. // console.log(isWay)
  502. var setTime = this.data.times + 0.1
  503. that.setData({ times: setTime })
  504. // console.log(setTime)
  505. that.data.setInter = setTimeout(this.startSetInter, time);
  506. if (setTime > 2) {
  507. if (isWay == 10) {
  508. that.endSetInter();
  509. that.tenEndTimes()
  510. } else {
  511. that.endSetInter();
  512. that.setData({ isWay: isWay + 1, times: 0,isWhite:true })
  513. that.hiddenShow()
  514. }
  515. }
  516. },
  517. /**
  518. * 页面跳转定时器
  519. */
  520. tenEndTimes: function () {
  521. var that = this;
  522. const { graphicReasoning, level, ageGroup,spaceImagination,executionFunctionality,visualSearch,workingMemory,mentalRotation,zxgnList,gameRespondentId} = that.data;
  523. var allScore=0
  524. for (var i in zxgnList){
  525. allScore+=zxgnList[i].score
  526. }
  527. console.log(zxgnList,allScore)
  528. setTimeout(
  529. function () {
  530. that.redirectCtl({ url: 'result', method: { graphicReasoning, level:1, ageGroup,spaceImagination,executionFunctionality:(Number(executionFunctionality)+allScore),visualSearch,workingMemory,mentalRotation,isRefer:1,gameRespondentId} }, true)
  531. }, 100)
  532. },
  533. /**
  534. * 答题情况保存
  535. */
  536. saveCase:function(str){
  537. const postData = { fn: this.getPersonInfo, param: { ...arguments } }
  538. const {isWay,times,gameRespondentId}=this.data
  539. app.post('/api/game/v2/answerInfoSave', {gameRespondentId,moduleCode:6,questionCode:isWay+1,usedTime:Math.round(times*1000),answerResult:str+1}, 0, postData).then(res => {
  540. })
  541. },
  542. })