constitutionDiagnosis.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  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_checkbox.svg",
  11. normalIcon: "/subpages/icons/ic_checkbox.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. { value: '30', remark: '', label: '无' },
  47. ],
  48. bodySynthesis: [],// 一、身体综合
  49. //二、面部五官
  50. facialFeaturesOptions: [
  51. { value: '0', remark: 'B', label: '喉头部有异物感' },
  52. { value: '1', remark: 'C', label: '脸色不好' },
  53. { value: '2', remark: 'D', label: '眼圈发黑' },
  54. { value: '3', remark: 'E', label: '眼睛经常模糊不清' },
  55. { value: '4', remark: 'E', label: '多呈现消极、羸弱的面孔' },
  56. { value: '5', remark: 'F', label: '唾液和痰较多,中发黏' },
  57. { value: '6', remark: 'F', label: '易犯花粉症和鼻炎,容易淌鼻涕' },
  58. { value: '7', remark: '', label: '无' },
  59. ],
  60. facialFeatures: [],// 二、面部五官
  61. //三、皮肤毛发
  62. skinHairOptions: [
  63. { value: '0', remark: 'C', label: '头发脆弱,脱发' },
  64. { value: '1', remark: 'C', label: '皮肤和指甲无光泽' },
  65. { value: '2', remark: 'D', label: '皮肤干燥易皲裂,色斑、雀斑多' },
  66. { value: '3', remark: 'D', label: '皮肤呈青紫色或黑紫色,不光滑' },
  67. { value: '4', remark: 'D', label: '肤色暗淡' },
  68. { value: '5', remark: 'E', label: '洗浴后皮肤很快干燥,易发痒' },
  69. { value: '6', remark: 'E', label: '皮肤纹理粗糙、毛孔张开' },
  70. { value: '7', remark: '', label: '无' },
  71. ],
  72. skinHair: [],// 三、皮肤毛发
  73. //四、情绪方面
  74. emotionOptions: [
  75. { value: '0', remark: 'A', label: '经常情绪低落,容易受伤害' },
  76. { value: '1', remark: 'B', label: '焦虑、易怒' },
  77. { value: '2', remark: 'B', label: '常长吁短叹、嗳气' },
  78. { value: '3', remark: '', label: '无' },
  79. ],
  80. emotion: [],// 四、情绪方面
  81. //五、月经方面
  82. menstruationOptions: [
  83. { value: '0', remark: 'B', label: '月经前身体不适' },
  84. { value: '1', remark: 'C', label: '经血量少或月经周期过长' },
  85. { value: '2', remark: 'D', label: '月经痛加重、经血中有动物肝脏血块' },
  86. { value: '3', remark: '', label: '无' },
  87. ],
  88. menstruation: [],// 五、月经方面
  89. //六、性格方面
  90. characterOptions: [
  91. { value: '0', remark: 'A', label: '过度依赖人际关系' },
  92. { value: '1', remark: 'B', label: '具有攻击性,不善于体谅别人' },
  93. { value: '2', remark: 'C', label: '属冷静、认真型' },
  94. { value: '3', remark: 'C', label: '善于制造一个自我世界并沉溺其中' },
  95. { value: '4', remark: 'D', label: '忍耐性较强的性格,容易积聚压力' },
  96. { value: '5', remark: 'D', label: '接人待物中规中矩,严守礼节' },
  97. { value: '6', remark: 'F', label: '以自我为中心,争强好胜,嫉妒心强,爱慕虚荣' },
  98. { value: '7', remark: 'F', label: '喜欢奢华、热闹的氛围' },
  99. { value: '8', remark: '', label: '无' },
  100. ],
  101. character: [],// 六、性格方面
  102. //七、睡眠
  103. sleepOptions: [
  104. { value: '0', remark: 'B', label: '入睡闲困难' },
  105. { value: '1', remark: 'C', label: '睡眠浅,易做梦' },
  106. { value: '2', remark: '', label: '无' },
  107. ],
  108. sleep: [],// 七、睡眠
  109. //八、舌头状态
  110. tongueStateOptions: [
  111. { value: '0', remark: 'A', label: '整体色淡;厚、肿大;边缘呈齿状' },
  112. { value: '1', remark: 'B', label: '两侧赤红;中间色淡或偏白;薄薄的黄色舌苔' },
  113. { value: '2', remark: 'C', label: '舌体偏小;色淡、偏白,舌苔整体偏薄' },
  114. { value: '3', remark: 'D', label: '舌色暗、偏紫色;有黑色斑点;舌下两根静脉粗粗地浮现出来' },
  115. { value: '4', remark: 'E', label: '舌色整体发红;舌苔少、甚至没有;舌面有齿痕' },
  116. { value: '5', remark: 'F', label: '舌苔厚、黏黏糊糊;舌苔色黄或白;舌体肿胀' },
  117. { value: '6', remark: '', label: '无' },
  118. ],
  119. tongueState: [],// 八、舌头状态
  120. comScore: 0,
  121. comScoreStatus: '',
  122. comScoreIndex: 0,
  123. comScoreDesc: "",
  124. ratingResultsList: [{
  125. index: 0,
  126. title: "气虚型",
  127. icon: "/subpages/icons/ic_triangle_down_1.svg",
  128. color: "#70B3FE",
  129. opacity: "0"
  130. }, {
  131. index: 1,
  132. title: "气滞型",
  133. icon: "/subpages/icons/ic_triangle_down_2.svg",
  134. color: "#68D89E",
  135. opacity: "0"
  136. }, {
  137. index: 2,
  138. title: "血虚型",
  139. icon: "/subpages/icons/ic_triangle_down_3.svg",
  140. color: "#FFA95A",
  141. opacity: "0"
  142. }, {
  143. index: 3,
  144. title: "淤血型",
  145. icon: "/subpages/icons/ic_triangle_down_4.svg",
  146. color: "#cffc6d",
  147. opacity: "0"
  148. }, {
  149. index: 4,
  150. title: "水虚型",
  151. icon: "/subpages/icons/ic_triangle_down_1.svg",
  152. color: "#80f5ff",
  153. opacity: "0"
  154. }, {
  155. index: 5,
  156. title: "痰湿型",
  157. icon: "/subpages/icons/ic_triangle_down_2.svg",
  158. color: "#ef00b3",
  159. opacity: "0"
  160. }],
  161. hotel: '',//酒店
  162. room: '',//房间
  163. mInputId: '',//自动滚动用的
  164. intervalId1: null,//保存数据
  165. intervalId2: null,//授权解除定时任务
  166. intervalId3: null,//导出excel
  167. },
  168. // 一、身体综合
  169. bindBodySynthesis: function (e) {
  170. console.log(e)
  171. this.setData({
  172. bodySynthesis: e.detail
  173. });
  174. },
  175. // 二、面部五官
  176. bindFacialFeatures: function (e) {
  177. console.log(e)
  178. this.setData({
  179. facialFeatures: e.detail
  180. });
  181. },
  182. // 三、皮肤毛发
  183. bindSkinHair: function (e) {
  184. console.log(e)
  185. this.setData({
  186. skinHair: e.detail
  187. });
  188. },
  189. // 四、情绪方面
  190. bindEmotion: function (e) {
  191. console.log(e)
  192. this.setData({
  193. emotion: e.detail
  194. });
  195. },
  196. // 五、月经方面
  197. bindMenstruation: function (e) {
  198. console.log(e)
  199. this.setData({
  200. menstruation: e.detail
  201. });
  202. },
  203. // 六、性格方面
  204. bindCharacter: function (e) {
  205. console.log(e)
  206. this.setData({
  207. character: e.detail
  208. });
  209. },
  210. // 七、睡眠
  211. bindSleep: function (e) {
  212. console.log(e)
  213. this.setData({
  214. sleep: e.detail
  215. });
  216. },
  217. // 八、舌头状态
  218. bindTongueState: function (e) {
  219. console.log(e)
  220. this.setData({
  221. tongueState: e.detail
  222. });
  223. },
  224. //统计这8个数组,总共包含A,B,C,D,E,F的个数,返回最多的一项(也可能多项):
  225. //如果有多个 最多 的情况,返回最多的几个,如果都是0或者空,返回空
  226. findMostFrequentLetters: function (arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8) {
  227. console.log('arr1=' + arr1);
  228. console.log('arr2=' + arr2);
  229. console.log('arr3=' + arr3);
  230. console.log('arr4=' + arr4);
  231. console.log('arr5=' + arr5);
  232. console.log('arr6=' + arr6);
  233. console.log('arr7=' + arr7);
  234. console.log('arr8=' + arr8);
  235. //判断6个数组是否都为空
  236. if (this.areAllArraysEmpty(arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8))
  237. return '';
  238. // 初始化一个对象来存储每个字母的计数
  239. const letterCounts = {
  240. A: 0,
  241. B: 0,
  242. C: 0,
  243. D: 0,
  244. E: 0,
  245. F: 0
  246. };
  247. // 定义一个辅助函数来更新计数
  248. function updateCounts(arr) {
  249. if (Array.isArray(arr)) {
  250. arr.forEach(item => {
  251. if (typeof item === 'string' && ['A', 'B', 'C', 'D', 'E', 'F'].includes(item)) {
  252. letterCounts[item]++;
  253. }
  254. });
  255. }
  256. }
  257. // 对每个数组调用辅助函数
  258. updateCounts(arr1);
  259. updateCounts(arr2);
  260. updateCounts(arr3);
  261. updateCounts(arr4);
  262. updateCounts(arr5);
  263. updateCounts(arr6);
  264. updateCounts(arr7);
  265. updateCounts(arr8);
  266. console.log('arr1=' + arr1);
  267. console.log('arr2=' + arr2);
  268. console.log('arr3=' + arr3);
  269. console.log('arr4=' + arr4);
  270. console.log('arr5=' + arr5);
  271. console.log('arr6=' + arr6);
  272. console.log('arr7=' + arr7);
  273. console.log('arr8=' + arr8);
  274. countABCDEF = letterCounts;
  275. // 找出出现次数最多的字母及其计数
  276. let maxCount = 0;
  277. let mostFrequentLetters = [];
  278. for (let letter in letterCounts) {
  279. if (letterCounts[letter] == 0) {
  280. continue;
  281. }
  282. if (letterCounts[letter] > maxCount) {
  283. maxCount = letterCounts[letter];
  284. mostFrequentLetters = [letter]; // 重置为当前最多的字母
  285. } else if (letterCounts[letter] === maxCount) {
  286. mostFrequentLetters.push(letter); // 如果计数相同,则添加到列表中
  287. }
  288. }
  289. console.log('letterCounts=' + JSON.stringify(letterCounts) );
  290. // 如果所有字母的计数都是0或数组为空,则返回空
  291. if (mostFrequentLetters.length === 0) {
  292. return '';
  293. }
  294. // 返回出现次数最多的字母或字母集合
  295. return mostFrequentLetters;
  296. },
  297. // 提交问卷的函数
  298. submitSurvey: function () {
  299. var that = this;
  300. // 清空表单:
  301. this.setData({
  302. ratingResultsList: [{
  303. index: 0,
  304. title: "气虚型",
  305. icon: "/subpages/icons/ic_triangle_down_1.svg",
  306. color: "#70B3FE",
  307. opacity: "0"
  308. }, {
  309. index: 1,
  310. title: "气滞型",
  311. icon: "/subpages/icons/ic_triangle_down_2.svg",
  312. color: "#68D89E",
  313. opacity: "0"
  314. }, {
  315. index: 2,
  316. title: "血虚型",
  317. icon: "/subpages/icons/ic_triangle_down_3.svg",
  318. color: "#FFA95A",
  319. opacity: "0"
  320. }, {
  321. index: 3,
  322. title: "淤血型",
  323. icon: "/subpages/icons/ic_triangle_down_4.svg",
  324. color: "#cffc6d",
  325. opacity: "0"
  326. }, {
  327. index: 4,
  328. title: "水虚型",
  329. icon: "/subpages/icons/ic_triangle_down_1.svg",
  330. color: "#80f5ff",
  331. opacity: "0"
  332. }, {
  333. index: 5,
  334. title: "痰湿型",
  335. icon: "/subpages/icons/ic_triangle_down_2.svg",
  336. color: "#ef00b3",
  337. opacity: "0"
  338. }],
  339. });
  340. const { nickName } = wx.getStorageSync('userInfo');
  341. const unionid = wx.getStorageSync('unionid');
  342. console.log('nickName==' + nickName);
  343. console.log('unionid==' + unionid);
  344. let resultMostFrequentLetters = this.findMostFrequentLetters(
  345. this.getRemarkValues(this.data.bodySynthesisOptions, this.data.bodySynthesis),
  346. this.getRemarkValues(this.data.facialFeaturesOptions, this.data.facialFeatures),
  347. this.getRemarkValues(this.data.skinHairOptions, this.data.skinHair),
  348. this.getRemarkValues(this.data.emotionOptions, this.data.emotion),
  349. this.getRemarkValues(this.data.menstruationOptions, this.data.menstruation),
  350. this.getRemarkValues(this.data.characterOptions, this.data.character),
  351. this.getRemarkValues(this.data.sleepOptions, this.data.sleep),
  352. this.getRemarkValues(this.data.tongueStateOptions, this.data.tongueState)
  353. );
  354. console.log('resultMostFrequentLetters==' + resultMostFrequentLetters);
  355. let comScoreIndex = [];
  356. let _comScoreStatus = "";
  357. let _comScoreDesc = ""
  358. if (!resultMostFrequentLetters || !Array.isArray(resultMostFrequentLetters) || !resultMostFrequentLetters.length) {
  359. comScoreIndex = [];
  360. _comScoreStatus = "";
  361. _comScoreDesc = ""
  362. } else {
  363. comScoreIndex = [];
  364. // 遍历输入数组
  365. resultMostFrequentLetters.forEach(item => {
  366. console.log('item=' + item);
  367. if (item == 'A') {
  368. if (_comScoreStatus) {
  369. _comScoreStatus += "\n气虚型";
  370. } else {
  371. _comScoreStatus += "气虚型";
  372. }
  373. if (_comScoreDesc) {
  374. _comScoreDesc += "\n气虚型:填写内容";
  375. } else {
  376. _comScoreDesc += "气虚型:填写内容";
  377. }
  378. comScoreIndex.push(0);
  379. } else if (item == 'B') {
  380. if (_comScoreStatus) {
  381. _comScoreStatus += "\n气滞型";
  382. } else {
  383. _comScoreStatus += "气滞型";
  384. }
  385. if (_comScoreDesc) {
  386. _comScoreDesc += "\n气滞型:填写内容";
  387. } else {
  388. _comScoreDesc += "气滞型:填写内容";
  389. }
  390. comScoreIndex.push(1);
  391. } else if (item == 'C') {
  392. if (_comScoreStatus) {
  393. _comScoreStatus += "\n血虚型";
  394. } else {
  395. _comScoreStatus += "血虚型";
  396. }
  397. if (_comScoreDesc) {
  398. _comScoreDesc += "\n血虚型:填写内容";
  399. } else {
  400. _comScoreDesc += "血虚型:填写内容";
  401. }
  402. comScoreIndex.push(2);
  403. } else if (item == 'D') {
  404. if (_comScoreStatus) {
  405. _comScoreStatus += "\n淤血型";
  406. } else {
  407. _comScoreStatus += "淤血型";
  408. }
  409. if (_comScoreDesc) {
  410. _comScoreDesc += "\n淤血型:填写内容";
  411. } else {
  412. _comScoreDesc += "淤血型:填写内容";
  413. }
  414. comScoreIndex.push(3);
  415. } else if (item == 'E') {
  416. if (_comScoreStatus) {
  417. _comScoreStatus += "\n水虚型";
  418. } else {
  419. _comScoreStatus += "水虚型";
  420. }
  421. if (_comScoreDesc) {
  422. _comScoreDesc += "\n水虚型:填写内容";
  423. } else {
  424. _comScoreDesc += "水虚型:填写内容";
  425. }
  426. comScoreIndex.push(4);
  427. } else if (item == 'F') {
  428. if (_comScoreStatus) {
  429. _comScoreStatus += "\n痰湿型";
  430. } else {
  431. _comScoreStatus += "痰湿型";
  432. }
  433. if (_comScoreDesc) {
  434. _comScoreDesc += "\n痰湿型:填写内容";
  435. } else {
  436. _comScoreDesc += "痰湿型:填写内容";
  437. }
  438. comScoreIndex.push(5);
  439. }
  440. });
  441. }
  442. console.log('comScoreIndex=' + comScoreIndex.join());
  443. console.log('_comScoreStatus=' + _comScoreStatus);
  444. console.log('_comScoreDesc=' + _comScoreDesc);
  445. this.setData({
  446. comScoreStatus: _comScoreStatus,
  447. comScoreIndex: comScoreIndex.join(),
  448. comScoreDesc: _comScoreDesc,
  449. promptTextMessageFlag: true,
  450. ratingResultsList: this.updateOpacity(this.data.ratingResultsList, comScoreIndex),
  451. })
  452. console.log('ratingResultsList=' + JSON.stringify(this.data.ratingResultsList));
  453. let surveyData = {
  454. hotel: this.data.hotel,
  455. room: this.data.room,
  456. userId: nickName,
  457. id2: unionid,
  458. bodySynthesis: this.getFormattedString(this.data.bodySynthesis, this.data.bodySynthesisOptions),
  459. facialFeatures: this.getFormattedString(this.data.facialFeatures, this.data.facialFeaturesOptions),
  460. skinHair: this.getFormattedString(this.data.skinHair, this.data.skinHairOptions),
  461. emotion: this.getFormattedString(this.data.emotion, this.data.emotionOptions),
  462. menstruation: this.getFormattedString(this.data.menstruation, this.data.menstruationOptions),
  463. character: this.getFormattedString(this.data.character, this.data.characterOptions),
  464. sleep: this.getFormattedString(this.data.sleep, this.data.sleepOptions),
  465. //舌头状态是新增加项,赋给value1了,数据库里有value1...value8,以备增加项用
  466. value1: this.getFormattedString(this.data.tongueState, this.data.tongueStateOptions),
  467. //value2 保存A、B、C、D、E、F 每个的个数
  468. value2: JSON.stringify(countABCDEF),
  469. comScoreStatus: _comScoreStatus ? _comScoreStatus : '健康型',
  470. comScoreIndex: comScoreIndex,
  471. comScoreDesc: _comScoreDesc,
  472. };
  473. console.log('surveyData=' + JSON.stringify(surveyData));
  474. var isFinish = true;
  475. var emptyKey = "";
  476. let checkList = {
  477. bodySynthesis: this.data.bodySynthesis,
  478. facialFeatures: this.data.facialFeatures,
  479. skinHair: this.data.skinHair,
  480. emotion: this.data.emotion,
  481. // menstruation: this.data.menstruation,
  482. character: this.data.character,
  483. sleep: this.data.sleep,
  484. tongueState: this.data.tongueState
  485. }
  486. for (const key in checkList) {
  487. if (checkList.hasOwnProperty(key)) {
  488. const element = checkList[key];
  489. if (!element || (Array.isArray(element) && element.length <= 0)) { // 检查属性值是否为空
  490. // 这里可以添加更复杂的判断,比如仅针对字符串检查是否为空字符串
  491. // if (typeof obj[key] === 'string' && obj[key].trim() === '') {
  492. isFinish = false;
  493. emptyKey = key;
  494. wx.showModal({
  495. title: '无法提交',
  496. content: '您还有部分题目未完成,请检查后重新提交',
  497. showCancel: false,
  498. confirmColor: '#0BC3AA',
  499. confirmText: "好的",
  500. success(res) {
  501. console.log(emptyKey.toString());
  502. that.setData({
  503. mInputId: emptyKey.toString()
  504. })
  505. }
  506. })
  507. return; // 停止循环
  508. }
  509. }
  510. }
  511. if (!isFinish) {
  512. wx.showModal({
  513. title: '无法提交',
  514. content: '您还有部分题目未完成,请检查后重新提交',
  515. showCancel: false,
  516. confirmColor: '#0BC3AA',
  517. confirmText: "好的",
  518. success(res) {
  519. console.log(emptyKey.toString());
  520. that.setData({
  521. mInputId: emptyKey.toString()
  522. })
  523. }
  524. })
  525. return;
  526. }
  527. // 将surveyData发送到服务器
  528. console.log('提交的问卷数据:', surveyData);
  529. if (!that.data.intervalId1) {
  530. that.data.intervalId1 = setInterval(() => {
  531. //提交到数据库
  532. wx.request({
  533. url: `${homeApi}/system/constitutionDiagnosis`, //
  534. method: 'POST',
  535. header: {
  536. 'content-type': 'application/json', // 默认值
  537. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  538. },
  539. data: surveyData,
  540. success(res) {
  541. console.log('res===' + JSON.stringify(res));
  542. console.log('res.code===' + res.code);
  543. if (res && res.data && res.data.code == 200) {
  544. if (that.data.intervalId1) {
  545. clearInterval(that.data.intervalId1);
  546. that.data.intervalId1 = null;
  547. }
  548. wx.showToast({
  549. title: '问卷提交成功',
  550. icon: 'success',
  551. duration: 2000,
  552. success() {
  553. setTimeout(() => {
  554. wx.navigateTo({
  555. url: `/subpages/detectionResult/detectionResult?comScoreIndex=${comScoreIndex.slice(0, 1)}`,
  556. })
  557. }, 1000);
  558. }
  559. });
  560. }
  561. },
  562. fail: function (error) {
  563. console.error('error', error);
  564. },
  565. complete: function (e) {
  566. }
  567. });
  568. }, 1000);
  569. }
  570. // wx.showToast({
  571. // title: '问卷提交成功',
  572. // icon: 'success',
  573. // duration: 2000
  574. // });
  575. },
  576. // 取出最大值的obj
  577. findMaxValueKeyAndIndex(obj) {
  578. let maxValue = -Infinity;
  579. let maxKey = '';
  580. let maxIndex = -1;
  581. const keys = Object.keys(obj);
  582. keys.forEach((key, index) => {
  583. const value = obj[key];
  584. if (value > maxValue) {
  585. maxValue = value;
  586. maxKey = key;
  587. maxIndex = index;
  588. }
  589. });
  590. return {
  591. key: maxKey,
  592. value: maxValue,
  593. index: maxIndex
  594. };
  595. },
  596. export() {
  597. var that = this;
  598. const { nickName } = wx.getStorageSync('userInfo');
  599. const unionid = wx.getStorageSync('unionid');
  600. let exportData = {
  601. hotel: this.data.hotel,
  602. room: this.data.room,
  603. userId: nickName,
  604. id2: unionid,
  605. }
  606. if (!that.data.intervalId1) {
  607. that.data.intervalId1 = setInterval(() => {
  608. wx.request({
  609. url: `${homeApi}/system/constitutionDiagnosis/export`,
  610. method: 'POST',
  611. header: {
  612. 'content-type': 'application/json', // 默认值
  613. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  614. },
  615. // 参数
  616. data: exportData,
  617. responseType: "arraybuffer", // 该属性处理二进制数据
  618. success: res => {
  619. console.log('res==' + JSON.stringify(res));
  620. if (res.statusCode == 200) {
  621. if (that.data.intervalId3) {
  622. clearInterval(that.data.intervalId3);
  623. that.data.intervalId3 = null;
  624. }
  625. const fs = wx.getFileSystemManager(); // 获取全局唯一的文件管理器
  626. fs.writeFile({ //写文件
  627. // wx.env.USER_DATA_PATH是小程序提供的访问用户文件路劲的变量
  628. filePath: wx.env.USER_DATA_PATH + '/' + '体质问卷调查.xlsx', // 一般后端回返回文件名
  629. data: res.data, // res.data就是获取到的二进制文件流
  630. encoding: "binary", //二进制流文件必须是 binary
  631. success(e) {
  632. wx.openDocument({ // 打开文档
  633. filePath: wx.env.USER_DATA_PATH + '/' + '体质问卷调查.xlsx',
  634. showMenu: true, // 显示右上角菜单
  635. success: function (res) {
  636. console.log("打开文件", res);
  637. },
  638. })
  639. }
  640. })
  641. }
  642. },
  643. error(err) {
  644. console.log('export-err==' + err)
  645. }
  646. })
  647. }, 2000);
  648. }
  649. },
  650. onCloseResultsDialog() {
  651. this.setData({ promptTextMessageFlag: false });
  652. },
  653. onLoad(option) {
  654. var that = this;
  655. console.log("constitutionDiagnosis页面");
  656. // wx.clearStorage();
  657. // console.log('option.res=' + JSON.stringify(wx.getStorageSync('res')));
  658. // if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
  659. // wx.showModal({
  660. // title: '提示',
  661. // content: '请先扫描房间二维码',
  662. // showCancel: false
  663. // });
  664. // setTimeout(function () {
  665. // wx.reLaunch({
  666. // url: '/subpages/scan/scan',
  667. // })
  668. // }, 2000) // 设置延时时间,单位为毫秒
  669. // } else if (wx.getStorageSync('res').result.split('|').length != 2) {
  670. // wx.showModal({
  671. // title: '提示',
  672. // content: '房间二维码不正确,请重新扫码',
  673. // showCancel: false
  674. // });
  675. // setTimeout(function () {
  676. // wx.reLaunch({
  677. // url: '/subpages/scan/scan',
  678. // })
  679. // }, 2000) // 设置延时时间,单位为毫秒
  680. // } else {
  681. // const expiresAt = wx.getStorageSync('scanResultExpiresAt');
  682. // const now = Date.now()
  683. // if (expiresAt || expiresAt < now) {
  684. // // 扫码结果已过期
  685. // wx.showToast({
  686. // title: '扫码结果失效或已过期,请重新扫码',
  687. // icon: 'none'
  688. // });
  689. // // 清除过期的扫码结果
  690. // wx.removeStorageSync('scanResultExpiresAt');
  691. // setTimeout(function() {
  692. // wx.reLaunch({
  693. // url: '/pages/scan/scan',
  694. // })
  695. // }, 2000) // 设置延时时间,单位为毫秒
  696. // }else{
  697. // //续期
  698. // wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000)
  699. // }
  700. let hotelTemp = '';
  701. let roomTemp = '';
  702. hotelTemp = wx.getStorageSync('hotelEmpower');
  703. roomTemp = wx.getStorageSync('roomEmpower');
  704. // hotelTemp = wx.getStorageSync('res').result.split('|')[0];
  705. // roomTemp = wx.getStorageSync('res').result.split('|')[1];
  706. this.setData({
  707. hotel: hotelTemp,
  708. room: roomTemp,
  709. });
  710. // }
  711. },
  712. areAllArraysEmpty: function (arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8) {
  713. // 定义一个数组来包含所有传入的数组
  714. const arrays = [arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8];
  715. // 遍历这个数组,检查每一项(即传入的数组)是否为空
  716. for (let i = 0; i < arrays.length; i++) {
  717. // 检查当前数组是否为空(即长度为0)
  718. if (arrays[i] && arrays[i].length > 0) {
  719. // 如果发现任何一个数组不为空,则返回false
  720. return false;
  721. }
  722. }
  723. // 如果所有数组都检查过了,且都是空的,则返回true
  724. return true;
  725. },
  726. //根据第二个数组对应第一个数组的value列,取第一个数组的remark的值,组成新的数组
  727. getRemarkValues: function (options, values) {
  728. if (!options || options.length === 0 || !values || values.length === 0) {
  729. return [];
  730. }
  731. // 初始化一个空数组来存储结果
  732. let remarkValues = [];
  733. // 遍历values数组
  734. values.forEach(value => {
  735. // 遍历options数组
  736. options.forEach(option => {
  737. // 如果找到了对应的value,则将该option的remark添加到result数组中
  738. if (option.value == value) {
  739. remarkValues.push(option.remark);
  740. }
  741. });
  742. });
  743. console.log('remarkValues=' + remarkValues);
  744. // 返回包含所有remark值的数组
  745. return remarkValues;
  746. },
  747. // ratingResultsList里的index和list字段相对应,如果两个值相等,将opacity的值改为'1'
  748. updateOpacity: function (ratingResultsList, list) {
  749. // 如果ratingResultsList为空,则直接返回
  750. if (!ratingResultsList || ratingResultsList.length === 0) {
  751. return ratingResultsList;
  752. }
  753. // 如果list为空,则直接返回原ratingResultsList
  754. if (!list || list.length === 0) {
  755. return ratingResultsList;
  756. }
  757. // 否则,进行更新操作
  758. return ratingResultsList.map(item => {
  759. // 如果item的index在list中,则修改opacity为'1',否则保持原样
  760. if (list.includes(item.index)) {
  761. return {
  762. ...item,
  763. opacity: '1'
  764. };
  765. }
  766. return item;
  767. });
  768. },
  769. submitDB: function () {
  770. var that = this;
  771. if (!that.data.intervalId1) {
  772. that.data.intervalId1 = setInterval(() => {
  773. that.submitSurvey();
  774. }, 1000);
  775. }
  776. },
  777. onShow: function (options) {
  778. // var that = this;
  779. // if (!that.data.intervalId2) {
  780. // that.data.intervalId2 = setInterval(() => {
  781. // // 这里执行你的代码
  782. // console.log('sleepEvaluation页面:'+Date.now());
  783. // }, 10000);
  784. // }
  785. },
  786. // startInterval: function () {
  787. // var that = this;
  788. // if (!that.data.intervalId) {
  789. // that.data.intervalId = setInterval(() => {
  790. // that.submitSurvey();
  791. // }, 1000);
  792. // }
  793. // },
  794. // clearInterval: function () {
  795. // var that = this;
  796. // if (that.data.intervalId) {
  797. // clearInterval(that.data.intervalId);
  798. // that.data.intervalId = null;
  799. // }
  800. // },
  801. /**
  802. * 生命周期函数--监听页面隐藏
  803. */
  804. onHide: function () {
  805. var that = this;
  806. if (that.data.intervalId1) {
  807. clearInterval(that.data.intervalId1);
  808. that.data.intervalId1 = null;
  809. }
  810. // if (this.data.intervalId2) {
  811. // clearInterval(this.data.intervalId2);
  812. // this.data.intervalId2 = null; // 可选,但建议清除以避免潜在的错误
  813. // }
  814. if (that.data.intervalId3) {
  815. clearInterval(that.data.intervalId3);
  816. that.data.intervalId3 = null;
  817. }
  818. },
  819. /**
  820. * 生命周期函数--监听页面卸载
  821. */
  822. onUnload: function () {
  823. var that = this;
  824. if (that.data.intervalId1) {
  825. clearInterval(that.data.intervalId1);
  826. that.data.intervalId1 = null;
  827. }
  828. // if (this.data.intervalId2) {
  829. // clearInterval(this.data.intervalId2);
  830. // this.data.intervalId2 = null; // 可选,但建议清除以避免潜在的错误
  831. // }
  832. if (that.data.intervalId3) {
  833. clearInterval(that.data.intervalId3);
  834. that.data.intervalId3 = null;
  835. }
  836. },
  837. //取出arr2的value和arr1对应的remark和label项,取出的数据组装成一个字符串,加上'char10'
  838. getFormattedString: function (arr1, arr2) {
  839. // 检查 arr1 和 arr2 是否为非空数组
  840. if (!arr1 || !arr2 || !Array.isArray(arr1) || arr1.length === 0 || !Array.isArray(arr2) || arr2.length === 0) {
  841. return '';
  842. }
  843. let result = '';
  844. arr1.forEach(value => {
  845. const valueStr = value ? value.toString() : '';
  846. const item = arr2.find(obj => obj.value == valueStr);
  847. if (item) {
  848. result += ` ${item.remark}、${item.label} char10`;
  849. }
  850. });
  851. return result;
  852. }
  853. });