constitutionDiagnosis.js 25 KB

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