constitutionDiagnosis.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. const baseUrl = "https://fare.somnisix.top/";
  2. const authorization = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6Ijk5YzI3MjI2LTdkOWQtNDhiOC1hYjlhLWM4YjVjYWZiZGNkNyIsInVzZXJuYW1lIjoiYWRtaW4ifQ.zITQOINFkHs19_1RAgHS4I9YMaVxVq0Dsn3t6r_K7rv3rXvJy0sMtodejIMi_PNa_m4uQYxnU-6k3wC2LZht_Q";
  3. const api = "system/sleepEvaluation";
  4. const homeApi = "https://fare.somnisix.top";
  5. const homeApiTest = "http://localhost:8080";
  6. const token = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6Ijk5YzI3MjI2LTdkOWQtNDhiOC1hYjlhLWM4YjVjYWZiZGNkNyIsInVzZXJuYW1lIjoiYWRtaW4ifQ.zITQOINFkHs19_1RAgHS4I9YMaVxVq0Dsn3t6r_K7rv3rXvJy0sMtodejIMi_PNa_m4uQYxnU-6k3wC2LZht_Q";
  7. Page({
  8. data: {
  9. activeIcon: "/subpages/icons/ic_selected_radio.svg",
  10. normalIcon: "/subpages/icons/ic_radio.svg",
  11. activeColor: "color:#0BC3AA;",
  12. normalColor: "color:#666666;",
  13. //一、身体综合
  14. bodySynthesisOptions: [
  15. { value: '0',remark: 'A', label: '易疲劳,总感到疲倦' },
  16. { value: '1',remark: 'A', label: '好出汗,一活动就冒汗' },
  17. { value: '2',remark: 'A', label: '易感冒,恢复慢' },
  18. { value: '3',remark: 'A', label: '稍一活动就气喘' },
  19. { value: '4',remark: 'A', label: '疲劳后身体就不舒服' },
  20. { value: '5',remark: 'A', label: '无食欲' },
  21. { value: '6',remark: 'A', label: '手脚发凉' },
  22. { value: '7',remark: 'A', label: '肌肉无力' },
  23. { value: '8',remark: 'B', label: '腹部易滞气' },
  24. { value: '9',remark: 'B', label: '头痛、肩凝、关节痛、胃疼、手脚麻痹' },
  25. { value: '10',remark: 'B', label: '紧张、发怒后身体不舒服' },
  26. { value: '11',remark: 'B', label: '身体有痛感后,疼痛部位游走不定' },
  27. { value: '12',remark: 'C', label: '易眩晕和站起时头晕' },
  28. { value: '13',remark: 'C', label: '常感到心慌' },
  29. { value: '14',remark: 'C', label: '易头晕眼花' },
  30. { value: '15',remark: 'D', label: '有受伤和手术后的旧伤痛' },
  31. { value: '16',remark: 'D', label: '感到肩和腰、头有针扎样痛' },
  32. { value: '17',remark: 'D', label: '入夜后容易出现肩、腰、头疼痛' },
  33. { value: '18',remark: 'E', label: '喉咙易渴,常想喝水' },
  34. { value: '19',remark: 'E', label: '感冒愈后常干咳' },
  35. { value: '20',remark: 'E', label: '易便秘,大便呈球状' },
  36. { value: '21',remark: 'E', label: '尿量少、色浓' },
  37. { value: '22',remark: 'E', label: '身体总是发热' },
  38. { value: '23',remark: 'E', label: '持续低烧' },
  39. { value: '24',remark: 'F', label: '常感到身体和手脚沉重,易浮肿' },
  40. { value: '25',remark: 'F', label: '胃部不适、恶心' },
  41. { value: '26',remark: 'F', label: '雨天和湿度高时身体状况就很糟糕' },
  42. { value: '27',remark: 'F', label: '有时眩晕' },
  43. { value: '28',remark: 'F', label: '大便偏软' },
  44. { value: '29',remark: 'F', label: '易恶心、呕吐、晕车' },
  45. ],
  46. bodySynthesis: [],// 一、身体综合
  47. //二、面部五官
  48. facialFeaturesOptions: [
  49. { value: '0',remark: 'B', label: '喉头部有异物感' },
  50. { value: '1',remark: 'C', label: '脸色不好' },
  51. { value: '2',remark: 'D', label: '眼圈发黑' },
  52. { value: '3',remark: 'E', label: '眼睛经常模糊不清' },
  53. { value: '4',remark: 'E', label: '多呈现消极、羸弱的面孔' },
  54. { value: '5',remark: 'F', label: '唾液和痰较多,中发黏' },
  55. { value: '6',remark: 'F', label: '易犯花粉症和鼻炎,容易淌鼻涕' },
  56. ],
  57. facialFeatures: [],// 二、面部五官
  58. //三、皮肤毛发
  59. skinHairOptions: [
  60. { value: '0',remark: 'C', label: '头发脆弱,脱发' },
  61. { value: '1',remark: 'C', label: '皮肤和指甲无光泽' },
  62. { value: '2',remark: 'D', label: '皮肤干燥易皲裂,色斑、雀斑多' },
  63. { value: '3',remark: 'D', label: '皮肤呈青紫色或黑紫色,不光滑' },
  64. { value: '4',remark: 'D', label: '肤色暗淡' },
  65. { value: '5',remark: 'E', label: '洗浴后皮肤很快干燥,易发痒' },
  66. { value: '6',remark: 'E', label: '皮肤纹理粗糙、毛孔张开' },
  67. ],
  68. skinHair: [],// 三、皮肤毛发
  69. //四、情绪方面
  70. emotionOptions: [
  71. { value: '0',remark: 'A', label: '经常情绪低落,容易受伤害' },
  72. { value: '1',remark: 'B', label: '焦虑、易怒' },
  73. { value: '2',remark: 'B', label: '常长吁短叹、嗳气' },
  74. ],
  75. emotion: [],// 四、情绪方面
  76. //五、月经方面
  77. menstruationOptions: [
  78. { value: '0',remark: 'B', label: '月经前身体不适' },
  79. { value: '1',remark: 'C', label: '经血量少或月经周期过长' },
  80. { value: '2',remark: 'D', label: '月经痛加重、经血中有动物肝脏血块' },
  81. ],
  82. menstruation: [],// 五、月经方面
  83. //六、性格方面
  84. characterOptions: [
  85. { value: '0',remark: 'A', label: '过度依赖人际关系' },
  86. { value: '1',remark: 'B', label: '具有攻击性,不善于体谅别人' },
  87. { value: '2',remark: 'C', label: '属冷静、认真型' },
  88. { value: '3',remark: 'C', label: '善于制造一个自我世界并沉溺其中' },
  89. { value: '4',remark: 'D', label: '忍耐性较强的性格,容易积聚压力' },
  90. { value: '5',remark: 'D', label: '接人待物中规中矩,严守礼节' },
  91. { value: '6',remark: 'F', label: '以自我为中心,争强好胜,嫉妒心强,爱慕虚荣' },
  92. { value: '7',remark: 'F', label: '喜欢奢华、热闹的氛围' },
  93. ],
  94. character: [],// 六、性格方面
  95. //七、睡眠
  96. sleepOptions: [
  97. { value: '0',remark: 'A', label: '过度依赖人际关系' },
  98. { value: '1',remark: 'B', label: '具有攻击性,不善于体谅别人' },
  99. { value: '2',remark: 'C', label: '属冷静、认真型' },
  100. { value: '3',remark: 'C', label: '善于制造一个自我世界并沉溺其中' },
  101. { value: '4',remark: 'D', label: '忍耐性较强的性格,容易积聚压力' },
  102. { value: '5',remark: 'D', label: '接人待物中规中矩,严守礼节' },
  103. { value: '6',remark: 'F', label: '以自我为中心,争强好胜,嫉妒心强,爱慕虚荣' },
  104. { value: '7',remark: 'F', label: '喜欢奢华、热闹的氛围' },
  105. ],
  106. sleep: [],// 七、睡眠
  107. comScore: 0,
  108. comScoreStatus: '',
  109. comScoreIndex: 0,
  110. comScoreDesc: "",
  111. ratingResultsList: [{
  112. index: 0,
  113. title: "气虚型",
  114. icon: "/subpages/icons/ic_triangle_down_1.svg",
  115. color: "#70B3FE",
  116. opacity: "0"
  117. }, {
  118. index: 1,
  119. title: "气滞型",
  120. icon: "/subpages/icons/ic_triangle_down_2.svg",
  121. color: "#68D89E",
  122. opacity: "0"
  123. }, {
  124. index: 2,
  125. title: "血虚型",
  126. icon: "/subpages/icons/ic_triangle_down_3.svg",
  127. color: "#FFA95A",
  128. opacity: "0"
  129. }, {
  130. index: 3,
  131. title: "淤血型",
  132. icon: "/subpages/icons/ic_triangle_down_4.svg",
  133. color: "#cffc6d",
  134. opacity: "0"
  135. }, {
  136. index: 4,
  137. title: "水虚型",
  138. icon: "/subpages/icons/ic_triangle_down_1.svg",
  139. color: "#80f5ff",
  140. opacity: "0"
  141. }, {
  142. index: 5,
  143. title: "痰湿型",
  144. icon: "/subpages/icons/ic_triangle_down_2.svg",
  145. color: "#ef00b3",
  146. opacity: "0"
  147. }],
  148. hotel: '',//酒店
  149. room: '',//房间
  150. mInputId: '',//自动滚动用的
  151. intervalId1: null,
  152. intervalId2: null,//授权解除定时任务
  153. },
  154. // 一、身体综合
  155. bindBodySynthesis: function (e) {
  156. console.log(e)
  157. this.setData({
  158. bodySynthesis: e.detail
  159. });
  160. },
  161. // 二、面部五官
  162. bindFacialFeatures: function (e) {
  163. console.log(e)
  164. this.setData({
  165. facialFeatures: e.detail
  166. });
  167. },
  168. // 三、皮肤毛发
  169. bindSkinHair: function (e) {
  170. console.log(e)
  171. this.setData({
  172. skinHair: e.detail
  173. });
  174. },
  175. // 四、情绪方面
  176. bindEmotion: function (e) {
  177. console.log(e)
  178. this.setData({
  179. emotion: e.detail
  180. });
  181. },
  182. // 五、月经方面
  183. bindMenstruation: function (e) {
  184. console.log(e)
  185. this.setData({
  186. menstruation: e.detail
  187. });
  188. },
  189. // 六、性格方面
  190. bindCharacter: function (e) {
  191. console.log(e)
  192. this.setData({
  193. character: e.detail
  194. });
  195. },
  196. // 七、睡眠
  197. bindSleep: function (e) {
  198. console.log(e)
  199. this.setData({
  200. sleep: e.detail
  201. });
  202. },
  203. //统计这6个数组,总共包含A,B,C,D,E,F的个数,返回最多的一项:
  204. //如果一样多,返回最多的几个,如果都是0或者空,返回空
  205. findMostFrequentLetters: function(arr1, arr2, arr3, arr4, arr5, arr6, arr7) {
  206. console.log('arr1='+arr1);
  207. console.log('arr2='+arr2);
  208. console.log('arr3='+arr3);
  209. console.log('arr4='+arr4);
  210. console.log('arr5='+arr5);
  211. console.log('arr6='+arr6);
  212. console.log('arr7='+arr7);
  213. //判断6个数组是否都为空
  214. if(this.areAllArraysEmpty(arr1, arr2, arr3, arr4, arr5, arr6, arr7))
  215. return '';
  216. // 初始化一个对象来存储每个字母的计数
  217. const letterCounts = {
  218. A: 0,
  219. B: 0,
  220. C: 0,
  221. D: 0,
  222. E: 0,
  223. F: 0
  224. };
  225. // 定义一个辅助函数来更新计数
  226. function updateCounts(arr) {
  227. if (Array.isArray(arr)) {
  228. arr.forEach(item => {
  229. if (typeof item === 'string' && ['A', 'B', 'C', 'D', 'E', 'F'].includes(item)) {
  230. letterCounts[item]++;
  231. }
  232. });
  233. }
  234. }
  235. // 对每个数组调用辅助函数
  236. updateCounts(arr1);
  237. updateCounts(arr2);
  238. updateCounts(arr3);
  239. updateCounts(arr4);
  240. updateCounts(arr5);
  241. updateCounts(arr6);
  242. updateCounts(arr7);
  243. // 找出出现次数最多的字母及其计数
  244. let maxCount = 0;
  245. let mostFrequentLetters = [];
  246. for (let letter in letterCounts) {
  247. if (letterCounts[letter] > maxCount) {
  248. maxCount = letterCounts[letter];
  249. mostFrequentLetters = [letter]; // 重置为当前最多的字母
  250. } else if (letterCounts[letter] === maxCount) {
  251. mostFrequentLetters.push(letter); // 如果计数相同,则添加到列表中
  252. }
  253. }
  254. // 如果所有字母的计数都是0或数组为空,则返回空
  255. if (mostFrequentLetters.length === 0) {
  256. return '';
  257. }
  258. // 返回出现次数最多的字母或字母集合
  259. return mostFrequentLetters;
  260. },
  261. // 提交问卷的函数
  262. submitSurvey: function () {
  263. var that = this;
  264. // 清空表单:
  265. this.setData({
  266. ratingResultsList: [{
  267. index: 0,
  268. title: "气虚型",
  269. icon: "/subpages/icons/ic_triangle_down_1.svg",
  270. color: "#70B3FE",
  271. opacity: "0"
  272. }, {
  273. index: 1,
  274. title: "气滞型",
  275. icon: "/subpages/icons/ic_triangle_down_2.svg",
  276. color: "#68D89E",
  277. opacity: "0"
  278. }, {
  279. index: 2,
  280. title: "血虚型",
  281. icon: "/subpages/icons/ic_triangle_down_3.svg",
  282. color: "#FFA95A",
  283. opacity: "0"
  284. }, {
  285. index: 3,
  286. title: "淤血型",
  287. icon: "/subpages/icons/ic_triangle_down_4.svg",
  288. color: "#cffc6d",
  289. opacity: "0"
  290. }, {
  291. index: 4,
  292. title: "水虚型",
  293. icon: "/subpages/icons/ic_triangle_down_1.svg",
  294. color: "#80f5ff",
  295. opacity: "0"
  296. }, {
  297. index: 5,
  298. title: "痰湿型",
  299. icon: "/subpages/icons/ic_triangle_down_2.svg",
  300. color: "#ef00b3",
  301. opacity: "0"
  302. }],
  303. });
  304. const { nickName } = wx.getStorageSync('userInfo');
  305. const unionid = wx.getStorageSync('unionid');
  306. console.log('nickName==' + nickName);
  307. console.log('unionid==' + unionid);
  308. let resultMostFrequentLetters = this.findMostFrequentLetters(
  309. this.getRemarkValues(this.data.bodySynthesisOptions,this.data.bodySynthesis),
  310. this.getRemarkValues(this.data.facialFeaturesOptions,this.data.facialFeatures),
  311. this.getRemarkValues(this.data.skinHairOptions,this.data.skinHair),
  312. this.getRemarkValues(this.data.emotionOptions,this.data.emotion),
  313. this.getRemarkValues(this.data.menstruationOptions,this.data.menstruation),
  314. this.getRemarkValues(this.data.characterOptions,this.data.character),
  315. this.getRemarkValues(this.data.sleepOptions,this.data.sleep)
  316. );
  317. let comScoreIndex = [];
  318. let _comScoreStatus = "";
  319. let _comScoreDesc = ""
  320. if (!resultMostFrequentLetters || !Array.isArray(resultMostFrequentLetters)) {
  321. comScoreIndex = [];
  322. _comScoreStatus = "";
  323. _comScoreDesc = ""
  324. }else{
  325. // 遍历输入数组
  326. resultMostFrequentLetters.forEach(item => {
  327. if (item == 'A') {
  328. if(_comScoreStatus){
  329. _comScoreStatus += ",气虚型";
  330. }else{
  331. _comScoreStatus += "气虚型";
  332. }
  333. if(_comScoreDesc){
  334. _comScoreDesc += ",气虚型:填写内容";
  335. }else{
  336. _comScoreDesc += "气虚型:填写内容";
  337. }
  338. comScoreIndex.push(0);
  339. } else if (item == 'B') {
  340. if(_comScoreStatus){
  341. _comScoreStatus += ",气滞型";
  342. }else{
  343. _comScoreStatus += "气滞型";
  344. }
  345. if(_comScoreDesc){
  346. _comScoreDesc += ",气滞型:填写内容";
  347. }else{
  348. _comScoreDesc += "气滞型:填写内容";
  349. }
  350. comScoreIndex.push(1);
  351. } else if (item == 'C') {
  352. if(_comScoreStatus){
  353. _comScoreStatus += ",血虚型";
  354. }else{
  355. _comScoreStatus += "血虚型";
  356. }
  357. if(_comScoreDesc){
  358. _comScoreDesc += ",血虚型:填写内容";
  359. }else{
  360. _comScoreDesc += "血虚型:填写内容";
  361. }
  362. comScoreIndex.push(2);
  363. } else if (item == 'D') {
  364. if(_comScoreStatus){
  365. _comScoreStatus += ",淤血型";
  366. }else{
  367. _comScoreStatus += "淤血型";
  368. }
  369. if(_comScoreDesc){
  370. _comScoreDesc += ",淤血型:填写内容";
  371. }else{
  372. _comScoreDesc += "淤血型:填写内容";
  373. }
  374. comScoreIndex.push(3);
  375. } else if (item == 'E') {
  376. if(_comScoreStatus){
  377. _comScoreStatus += ",水虚型";
  378. }else{
  379. _comScoreStatus += "水虚型";
  380. }
  381. if(_comScoreDesc){
  382. _comScoreDesc += ",水虚型:填写内容";
  383. }else{
  384. _comScoreDesc += "水虚型:填写内容";
  385. }
  386. comScoreIndex.push(4);
  387. } else if (item == 'F') {
  388. if(_comScoreStatus){
  389. _comScoreStatus += ",痰湿型";
  390. }else{
  391. _comScoreStatus += "痰湿型";
  392. }
  393. if(_comScoreDesc){
  394. _comScoreDesc += ",痰湿型:填写内容";
  395. }else{
  396. _comScoreDesc += "痰湿型:填写内容";
  397. }
  398. comScoreIndex.push(5);
  399. }
  400. });
  401. }
  402. console.log('comScoreIndex='+comScoreIndex.join());
  403. console.log('_comScoreStatus='+_comScoreStatus);
  404. console.log('_comScoreDesc='+_comScoreDesc);
  405. this.setData({
  406. comScoreStatus: _comScoreStatus,
  407. comScoreIndex: comScoreIndex.join(),
  408. comScoreDesc: _comScoreDesc,
  409. promptTextMessageFlag: true,
  410. ratingResultsList:this.updateOpacity(this.data.ratingResultsList,comScoreIndex),
  411. })
  412. console.log('ratingResultsList='+JSON.stringify(this.data.ratingResultsList));
  413. let surveyData = {
  414. hotel: this.data.hotel,
  415. room: this.data.room,
  416. userId: nickName,
  417. id2: unionid,
  418. bodySynthesis: (!this.data.bodySynthesis || this.data.bodySynthesis.length === 0) ? '' : (Array.isArray(this.data.bodySynthesis) ? this.data.bodySynthesis.map(item => String(item)).join(',') : this.data.bodySynthesis),
  419. facialFeatures: (!this.data.facialFeatures || this.data.facialFeatures.length === 0) ? '' : (Array.isArray(this.data.facialFeatures) ? this.data.facialFeatures.map(item => String(item)).join(',') : this.data.facialFeatures),
  420. skinHair: (!this.data.skinHair || this.data.skinHair.length === 0) ? '' : (Array.isArray(this.data.skinHair) ? this.data.skinHair.map(item => String(item)).join(',') : this.data.skinHair),
  421. emotion: (!this.data.emotion || this.data.emotion.length === 0) ? '' : (Array.isArray(this.data.emotion) ? this.data.emotion.map(item => String(item)).join(',') : this.data.emotion),
  422. menstruation: (!this.data.menstruation || this.data.menstruation.length === 0) ? '' : (Array.isArray(this.data.menstruation) ? this.data.menstruation.map(item => String(item)).join(',') : this.data.menstruation),
  423. character: (!this.data.character || this.data.character.length === 0) ? '' : (Array.isArray(this.data.character) ? this.data.character.map(item => String(item)).join(',') : this.data.character),
  424. sleep: (!this.data.sleep || this.data.sleep.length === 0) ? '' : (Array.isArray(this.data.sleep) ? this.data.sleep.map(item => String(item)).join(',') : this.data.sleep),
  425. comScoreStatus: _comScoreStatus,
  426. comScoreIndex: comScoreIndex,
  427. comScoreDesc: _comScoreDesc,
  428. };
  429. var isFinish = true;
  430. var emptyKey = "";
  431. // if (!isFinish) {
  432. // wx.showModal({
  433. // title: '无法提交',
  434. // content: '您还有部分题目未完成,请检查后重新提交',
  435. // showCancel: false,
  436. // confirmColor: '#0BC3AA',
  437. // confirmText: "好的",
  438. // success(res) {
  439. // console.log(emptyKey.toString());
  440. // that.setData({
  441. // mInputId: emptyKey.toString()
  442. // })
  443. // }
  444. // })
  445. // return;
  446. // }
  447. // 将surveyData发送到服务器
  448. console.log('提交的问卷数据:', surveyData);
  449. if (!that.data.intervalId1) {
  450. that.data.intervalId1 = setInterval(() => {
  451. //提交到数据库
  452. wx.request({
  453. url: `${homeApi}/system/constitutionDiagnosis`, //
  454. method: 'POST',
  455. header: {
  456. 'content-type': 'application/json', // 默认值
  457. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  458. },
  459. data: surveyData,
  460. success(res) {
  461. console.log('res===' + JSON.stringify(res));
  462. console.log('res.code===' + res.code);
  463. if (res && res.data && res.data.code == 200) {
  464. if (that.data.intervalId1) {
  465. clearInterval(that.data.intervalId1);
  466. that.data.intervalId1 = null;
  467. }
  468. wx.showToast({
  469. title: '问卷提交成功',
  470. icon: 'success',
  471. duration: 2000,
  472. // success() {
  473. // setTimeout(() => {
  474. // wx.navigateBack()
  475. // }, 1500);
  476. // }
  477. });
  478. }
  479. },
  480. fail: function (error) {
  481. console.error('error', error);
  482. },
  483. complete: function (e) {
  484. }
  485. });
  486. }, 1000);
  487. }
  488. // wx.showToast({
  489. // title: '问卷提交成功',
  490. // icon: 'success',
  491. // duration: 2000
  492. // });
  493. },
  494. onCloseResultsDialog() {
  495. this.setData({ promptTextMessageFlag: false });
  496. },
  497. onLoad(option) {
  498. var that = this;
  499. console.log("sleepEvaluation页面");
  500. // wx.clearStorage();
  501. /* console.log('option.res=' + JSON.stringify(wx.getStorageSync('res')));
  502. if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
  503. wx.showModal({
  504. title: '提示',
  505. content: '请先扫描房间二维码',
  506. showCancel: false
  507. });
  508. setTimeout(function () {
  509. wx.reLaunch({
  510. url: '/subpages/scan/scan',
  511. })
  512. }, 2000) // 设置延时时间,单位为毫秒
  513. } else if (wx.getStorageSync('res').result.split('|').length != 2) {
  514. wx.showModal({
  515. title: '提示',
  516. content: '房间二维码不正确,请重新扫码',
  517. showCancel: false
  518. });
  519. setTimeout(function () {
  520. wx.reLaunch({
  521. url: '/subpages/scan/scan',
  522. })
  523. }, 2000) // 设置延时时间,单位为毫秒
  524. } else {
  525. // const expiresAt = wx.getStorageSync('scanResultExpiresAt');
  526. // const now = Date.now()
  527. // if (expiresAt || expiresAt < now) {
  528. // // 扫码结果已过期
  529. // wx.showToast({
  530. // title: '扫码结果失效或已过期,请重新扫码',
  531. // icon: 'none'
  532. // });
  533. // // 清除过期的扫码结果
  534. // wx.removeStorageSync('scanResultExpiresAt');
  535. // setTimeout(function() {
  536. // wx.reLaunch({
  537. // url: '/pages/scan/scan',
  538. // })
  539. // }, 2000) // 设置延时时间,单位为毫秒
  540. // }else{
  541. // //续期
  542. // wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000)
  543. // }
  544. let hotelTemp = '';
  545. let roomTemp = '';
  546. hotelTemp = wx.getStorageSync('res').result.split('|')[0];
  547. roomTemp = wx.getStorageSync('res').result.split('|')[1];
  548. this.setData({
  549. hotel: hotelTemp,
  550. room: roomTemp,
  551. });
  552. } */
  553. },
  554. areAllArraysEmpty: function (arr1, arr2, arr3, arr4, arr5, arr6, arr7) {
  555. // 定义一个数组来包含所有传入的数组
  556. const arrays = [arr1, arr2, arr3, arr4, arr5, arr6, arr7];
  557. // 遍历这个数组,检查每一项(即传入的数组)是否为空
  558. for (let i = 0; i < arrays.length; i++) {
  559. // 检查当前数组是否为空(即长度为0)
  560. if (arrays[i] && arrays[i].length > 0) {
  561. // 如果发现任何一个数组不为空,则返回false
  562. return false;
  563. }
  564. }
  565. // 如果所有数组都检查过了,且都是空的,则返回true
  566. return true;
  567. },
  568. //根据第二个数组对应第一个数组的value列,取第一个数组的remark的值,组成新的数组
  569. getRemarkValues: function(options, values) {
  570. if (!options || options.length === 0 || !values || values.length === 0) {
  571. return [];
  572. }
  573. // 初始化一个空数组来存储结果
  574. let remarkValues = [];
  575. // 遍历values数组
  576. values.forEach(value => {
  577. // 遍历options数组
  578. options.forEach(option => {
  579. // 如果找到了对应的value,则将该option的remark添加到result数组中
  580. if (option.value == value) {
  581. remarkValues.push(option.remark);
  582. }
  583. });
  584. });
  585. console.log('remarkValues='+remarkValues);
  586. // 返回包含所有remark值的数组
  587. return remarkValues;
  588. },
  589. // ratingResultsList里的index和list字段相对应,如果两个值相等,将opacity的值改为'1'
  590. updateOpacity: function(ratingResultsList, list) {
  591. // 如果ratingResultsList为空,则直接返回
  592. if (!ratingResultsList || ratingResultsList.length === 0) {
  593. return ratingResultsList;
  594. }
  595. // 如果list为空,则直接返回原ratingResultsList
  596. if (!list || list.length === 0) {
  597. return ratingResultsList;
  598. }
  599. // 否则,进行更新操作
  600. return ratingResultsList.map(item => {
  601. // 如果item的index在list中,则修改opacity为'1',否则保持原样
  602. if (list.includes(item.index)) {
  603. return {
  604. ...item,
  605. opacity: '1'
  606. };
  607. }
  608. return item;
  609. });
  610. },
  611. submitDB: function () {
  612. var that = this;
  613. if (!that.data.intervalId1) {
  614. that.data.intervalId1 = setInterval(() => {
  615. that.submitSurvey();
  616. }, 1000);
  617. }
  618. },
  619. onShow: function (options) {
  620. // var that = this;
  621. // if (!that.data.intervalId2) {
  622. // that.data.intervalId2 = setInterval(() => {
  623. // // 这里执行你的代码
  624. // console.log('sleepEvaluation页面:'+Date.now());
  625. // }, 10000);
  626. // }
  627. },
  628. // startInterval: function () {
  629. // var that = this;
  630. // if (!that.data.intervalId) {
  631. // that.data.intervalId = setInterval(() => {
  632. // that.submitSurvey();
  633. // }, 1000);
  634. // }
  635. // },
  636. // clearInterval: function () {
  637. // var that = this;
  638. // if (that.data.intervalId) {
  639. // clearInterval(that.data.intervalId);
  640. // that.data.intervalId = null;
  641. // }
  642. // },
  643. /**
  644. * 生命周期函数--监听页面隐藏
  645. */
  646. onHide: function () {
  647. var that = this;
  648. if (that.data.intervalId1) {
  649. clearInterval(that.data.intervalId1);
  650. that.data.intervalId1 = null;
  651. }
  652. // if (this.data.intervalId2) {
  653. // clearInterval(this.data.intervalId2);
  654. // this.data.intervalId2 = null; // 可选,但建议清除以避免潜在的错误
  655. // }
  656. },
  657. /**
  658. * 生命周期函数--监听页面卸载
  659. */
  660. onUnload: function () {
  661. var that = this;
  662. if (that.data.intervalId1) {
  663. clearInterval(that.data.intervalId1);
  664. that.data.intervalId1 = null;
  665. }
  666. // if (this.data.intervalId2) {
  667. // clearInterval(this.data.intervalId2);
  668. // this.data.intervalId2 = null; // 可选,但建议清除以避免潜在的错误
  669. // }
  670. },
  671. });