constitutionDiagnosis.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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. verifyAll: function (dataset, detail) {
  169. let flag = false
  170. if (dataset ) {
  171. detail.forEach((item, index) => {
  172. if (dataset[item].label == "以上都没有"){
  173. flag = item
  174. }
  175. return flag
  176. })
  177. }
  178. return flag
  179. },
  180. // 一、身体综合
  181. bindBodySynthesis: function (e) {
  182. var detail = e.detail;
  183. var dataset = e.currentTarget.dataset.item;
  184. var b = this.verifyAll(dataset, detail);
  185. if (b) {
  186. detail = detail[detail.length-1]==b ?[b]:[detail[detail.length-1]]
  187. }
  188. this.setData({
  189. bodySynthesis: detail
  190. });
  191. },
  192. // 二、面部五官
  193. bindFacialFeatures: function (e) {
  194. var detail = e.detail;
  195. var dataset = e.currentTarget.dataset.item;
  196. var b = this.verifyAll(dataset, detail);
  197. if (b) {
  198. detail = detail[detail.length-1]==b ?[b]:[detail[detail.length-1]]
  199. }
  200. this.setData({
  201. facialFeatures: detail
  202. });
  203. },
  204. // 三、皮肤毛发
  205. bindSkinHair: function (e) {
  206. var detail = e.detail;
  207. var dataset = e.currentTarget.dataset.item;
  208. var b = this.verifyAll(dataset, detail);
  209. if (b) {
  210. detail = detail[detail.length-1]==b ?[b]:[detail[detail.length-1]]
  211. }
  212. this.setData({
  213. skinHair: detail
  214. });
  215. },
  216. // 四、情绪方面
  217. bindEmotion: function (e) {
  218. var detail = e.detail;
  219. var dataset = e.currentTarget.dataset.item;
  220. var b = this.verifyAll(dataset, detail);
  221. if (b) {
  222. detail = detail[detail.length-1]==b ?[b]:[detail[detail.length-1]]
  223. }
  224. this.setData({
  225. emotion: detail
  226. });
  227. },
  228. // 五、月经方面
  229. bindMenstruation: function (e) {
  230. var detail = e.detail;
  231. var dataset = e.currentTarget.dataset.item;
  232. var b = this.verifyAll(dataset, detail);
  233. if (b) {
  234. detail = detail[detail.length-1]==b ?[b]:[detail[detail.length-1]]
  235. }
  236. this.setData({
  237. menstruation:detail
  238. });
  239. },
  240. // 六、性格方面
  241. bindCharacter: function (e) {
  242. var detail = e.detail;
  243. var dataset = e.currentTarget.dataset.item;
  244. var b = this.verifyAll(dataset, detail);
  245. if (b) {
  246. detail = detail[detail.length-1]==b ?[b]:[detail[detail.length-1]]
  247. }
  248. this.setData({
  249. character: detail
  250. });
  251. },
  252. // 七、睡眠
  253. bindSleep: function (e) {
  254. var detail = e.detail;
  255. var dataset = e.currentTarget.dataset.item;
  256. var b = this.verifyAll(dataset, detail);
  257. if (b) {
  258. detail = detail[detail.length-1]==b ?[b]:[detail[detail.length-1]]
  259. }
  260. this.setData({
  261. sleep:detail
  262. });
  263. },
  264. // 八、舌头状态
  265. bindTongueState: function (e) {
  266. var detail = e.detail;
  267. var dataset = e.currentTarget.dataset.item;
  268. var b = this.verifyAll(dataset, detail);
  269. if (b) {
  270. detail = detail[detail.length-1]==b ?[b]:[detail[detail.length-1]]
  271. }
  272. this.setData({
  273. tongueState: detail
  274. });
  275. },
  276. //统计这8个数组,总共包含A,B,C,D,E,F的个数,返回最多的一项(也可能多项):
  277. //如果有多个 最多 的情况,返回最多的几个,如果都是0或者空,返回空
  278. findMostFrequentLetters: function (arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8) {
  279. console.log('arr1=' + arr1);
  280. console.log('arr2=' + arr2);
  281. console.log('arr3=' + arr3);
  282. console.log('arr4=' + arr4);
  283. console.log('arr5=' + arr5);
  284. console.log('arr6=' + arr6);
  285. console.log('arr7=' + arr7);
  286. console.log('arr8=' + arr8);
  287. //判断6个数组是否都为空
  288. if (this.areAllArraysEmpty(arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8))
  289. return '';
  290. // 初始化一个对象来存储每个字母的计数
  291. const letterCounts = {
  292. A: 0,
  293. B: 0,
  294. C: 0,
  295. D: 0,
  296. E: 0,
  297. F: 0
  298. };
  299. // 定义一个辅助函数来更新计数
  300. function updateCounts(arr) {
  301. if (Array.isArray(arr)) {
  302. arr.forEach(item => {
  303. if (typeof item === 'string' && ['A', 'B', 'C', 'D', 'E', 'F'].includes(item)) {
  304. letterCounts[item]++;
  305. }
  306. });
  307. }
  308. }
  309. // 对每个数组调用辅助函数
  310. updateCounts(arr1);
  311. updateCounts(arr2);
  312. updateCounts(arr3);
  313. updateCounts(arr4);
  314. updateCounts(arr5);
  315. updateCounts(arr6);
  316. updateCounts(arr7);
  317. updateCounts(arr8);
  318. console.log('arr1=' + arr1);
  319. console.log('arr2=' + arr2);
  320. console.log('arr3=' + arr3);
  321. console.log('arr4=' + arr4);
  322. console.log('arr5=' + arr5);
  323. console.log('arr6=' + arr6);
  324. console.log('arr7=' + arr7);
  325. console.log('arr8=' + arr8);
  326. countABCDEF = letterCounts;
  327. // 找出出现次数最多的字母及其计数
  328. let maxCount = 0;
  329. let mostFrequentLetters = [];
  330. for (let letter in letterCounts) {
  331. if (letterCounts[letter] == 0) {
  332. continue;
  333. }
  334. if (letterCounts[letter] > maxCount) {
  335. maxCount = letterCounts[letter];
  336. mostFrequentLetters = [letter]; // 重置为当前最多的字母
  337. } else if (letterCounts[letter] === maxCount) {
  338. mostFrequentLetters.push(letter); // 如果计数相同,则添加到列表中
  339. }
  340. }
  341. console.log('letterCounts=' + JSON.stringify(letterCounts) );
  342. // 如果所有字母的计数都是0或数组为空,则返回空
  343. if (mostFrequentLetters.length === 0) {
  344. return '';
  345. }
  346. // 返回出现次数最多的字母或字母集合
  347. return mostFrequentLetters;
  348. },
  349. // 提交问卷的函数
  350. submitSurvey: function () {
  351. var that = this;
  352. // 清空表单:
  353. this.setData({
  354. ratingResultsList: [{
  355. index: 0,
  356. title: "气虚型",
  357. icon: "/subpages/icons/ic_triangle_down_1.svg",
  358. color: "#70B3FE",
  359. opacity: "0"
  360. }, {
  361. index: 1,
  362. title: "气滞型",
  363. icon: "/subpages/icons/ic_triangle_down_2.svg",
  364. color: "#68D89E",
  365. opacity: "0"
  366. }, {
  367. index: 2,
  368. title: "血虚型",
  369. icon: "/subpages/icons/ic_triangle_down_3.svg",
  370. color: "#FFA95A",
  371. opacity: "0"
  372. }, {
  373. index: 3,
  374. title: "淤血型",
  375. icon: "/subpages/icons/ic_triangle_down_4.svg",
  376. color: "#cffc6d",
  377. opacity: "0"
  378. }, {
  379. index: 4,
  380. title: "水虚型",
  381. icon: "/subpages/icons/ic_triangle_down_1.svg",
  382. color: "#80f5ff",
  383. opacity: "0"
  384. }, {
  385. index: 5,
  386. title: "痰湿型",
  387. icon: "/subpages/icons/ic_triangle_down_2.svg",
  388. color: "#ef00b3",
  389. opacity: "0"
  390. }],
  391. });
  392. const { nickName } = wx.getStorageSync('userInfo');
  393. const unionid = wx.getStorageSync('unionid');
  394. console.log('nickName==' + nickName);
  395. console.log('unionid==' + unionid);
  396. let resultMostFrequentLetters = this.findMostFrequentLetters(
  397. this.getRemarkValues(this.data.bodySynthesisOptions, this.data.bodySynthesis),
  398. this.getRemarkValues(this.data.facialFeaturesOptions, this.data.facialFeatures),
  399. this.getRemarkValues(this.data.skinHairOptions, this.data.skinHair),
  400. this.getRemarkValues(this.data.emotionOptions, this.data.emotion),
  401. this.getRemarkValues(this.data.menstruationOptions, this.data.menstruation),
  402. this.getRemarkValues(this.data.characterOptions, this.data.character),
  403. this.getRemarkValues(this.data.sleepOptions, this.data.sleep),
  404. this.getRemarkValues(this.data.tongueStateOptions, this.data.tongueState)
  405. );
  406. console.log('resultMostFrequentLetters==' + resultMostFrequentLetters);
  407. let comScoreIndex = [];
  408. let _comScoreStatus = "";
  409. let _comScoreDesc = ""
  410. if (!resultMostFrequentLetters || !Array.isArray(resultMostFrequentLetters) || !resultMostFrequentLetters.length) {
  411. comScoreIndex = [];
  412. _comScoreStatus = "";
  413. _comScoreDesc = ""
  414. } else {
  415. comScoreIndex = [];
  416. // 遍历输入数组
  417. resultMostFrequentLetters.forEach(item => {
  418. console.log('item=' + item);
  419. if (item == 'A') {
  420. if (_comScoreStatus) {
  421. _comScoreStatus += "\n气虚型";
  422. } else {
  423. _comScoreStatus += "气虚型";
  424. }
  425. if (_comScoreDesc) {
  426. _comScoreDesc += "\n气虚型:填写内容";
  427. } else {
  428. _comScoreDesc += "气虚型:填写内容";
  429. }
  430. comScoreIndex.push(0);
  431. } else if (item == 'B') {
  432. if (_comScoreStatus) {
  433. _comScoreStatus += "\n气滞型";
  434. } else {
  435. _comScoreStatus += "气滞型";
  436. }
  437. if (_comScoreDesc) {
  438. _comScoreDesc += "\n气滞型:填写内容";
  439. } else {
  440. _comScoreDesc += "气滞型:填写内容";
  441. }
  442. comScoreIndex.push(1);
  443. } else if (item == 'C') {
  444. if (_comScoreStatus) {
  445. _comScoreStatus += "\n血虚型";
  446. } else {
  447. _comScoreStatus += "血虚型";
  448. }
  449. if (_comScoreDesc) {
  450. _comScoreDesc += "\n血虚型:填写内容";
  451. } else {
  452. _comScoreDesc += "血虚型:填写内容";
  453. }
  454. comScoreIndex.push(2);
  455. } else if (item == 'D') {
  456. if (_comScoreStatus) {
  457. _comScoreStatus += "\n淤血型";
  458. } else {
  459. _comScoreStatus += "淤血型";
  460. }
  461. if (_comScoreDesc) {
  462. _comScoreDesc += "\n淤血型:填写内容";
  463. } else {
  464. _comScoreDesc += "淤血型:填写内容";
  465. }
  466. comScoreIndex.push(3);
  467. } else if (item == 'E') {
  468. if (_comScoreStatus) {
  469. _comScoreStatus += "\n水虚型";
  470. } else {
  471. _comScoreStatus += "水虚型";
  472. }
  473. if (_comScoreDesc) {
  474. _comScoreDesc += "\n水虚型:填写内容";
  475. } else {
  476. _comScoreDesc += "水虚型:填写内容";
  477. }
  478. comScoreIndex.push(4);
  479. } else if (item == 'F') {
  480. if (_comScoreStatus) {
  481. _comScoreStatus += "\n痰湿型";
  482. } else {
  483. _comScoreStatus += "痰湿型";
  484. }
  485. if (_comScoreDesc) {
  486. _comScoreDesc += "\n痰湿型:填写内容";
  487. } else {
  488. _comScoreDesc += "痰湿型:填写内容";
  489. }
  490. comScoreIndex.push(5);
  491. }
  492. });
  493. }
  494. console.log('comScoreIndex=' + comScoreIndex.join());
  495. console.log('_comScoreStatus=' + _comScoreStatus);
  496. console.log('_comScoreDesc=' + _comScoreDesc);
  497. this.setData({
  498. comScoreStatus: _comScoreStatus,
  499. comScoreIndex: comScoreIndex.join(),
  500. comScoreDesc: _comScoreDesc,
  501. promptTextMessageFlag: true,
  502. ratingResultsList: this.updateOpacity(this.data.ratingResultsList, comScoreIndex),
  503. })
  504. console.log('ratingResultsList=' + JSON.stringify(this.data.ratingResultsList));
  505. let surveyData = {
  506. hotel: this.data.hotel,
  507. room: this.data.room,
  508. userId: nickName,
  509. id2: unionid,
  510. bodySynthesis: this.getFormattedString(this.data.bodySynthesis, this.data.bodySynthesisOptions),
  511. facialFeatures: this.getFormattedString(this.data.facialFeatures, this.data.facialFeaturesOptions),
  512. skinHair: this.getFormattedString(this.data.skinHair, this.data.skinHairOptions),
  513. emotion: this.getFormattedString(this.data.emotion, this.data.emotionOptions),
  514. menstruation: this.getFormattedString(this.data.menstruation, this.data.menstruationOptions),
  515. character: this.getFormattedString(this.data.character, this.data.characterOptions),
  516. sleep: this.getFormattedString(this.data.sleep, this.data.sleepOptions),
  517. //舌头状态是新增加项,赋给value1了,数据库里有value1...value8,以备增加项用
  518. value1: this.getFormattedString(this.data.tongueState, this.data.tongueStateOptions),
  519. //value2 保存A、B、C、D、E、F 每个的个数
  520. value2: JSON.stringify(countABCDEF),
  521. comScoreStatus: _comScoreStatus ? _comScoreStatus : '健康型',
  522. comScoreIndex: comScoreIndex.join(),
  523. comScoreDesc: _comScoreDesc,
  524. };
  525. console.log('surveyData=' + JSON.stringify(surveyData));
  526. var isFinish = true;
  527. var emptyKey = "";
  528. let checkList = {
  529. bodySynthesis: this.data.bodySynthesis,
  530. facialFeatures: this.data.facialFeatures,
  531. skinHair: this.data.skinHair,
  532. emotion: this.data.emotion,
  533. menstruation: this.data.menstruation,
  534. character: this.data.character,
  535. sleep: this.data.sleep,
  536. tongueState: this.data.tongueState
  537. }
  538. for (const key in checkList) {
  539. if (checkList.hasOwnProperty(key)) {
  540. const element = checkList[key];
  541. if (!element || (Array.isArray(element) && element.length <= 0)) { // 检查属性值是否为空
  542. // 这里可以添加更复杂的判断,比如仅针对字符串检查是否为空字符串
  543. // if (typeof obj[key] === 'string' && obj[key].trim() === '') {
  544. isFinish = false;
  545. emptyKey = key;
  546. wx.showModal({
  547. title: '无法提交',
  548. content: '您还有部分题目未完成,请检查后重新提交',
  549. showCancel: false,
  550. confirmColor: '#0BC3AA',
  551. confirmText: "好的",
  552. success(res) {
  553. console.log(emptyKey.toString());
  554. that.setData({
  555. mInputId: emptyKey.toString()
  556. })
  557. }
  558. })
  559. return; // 停止循环
  560. }
  561. }
  562. }
  563. if (!isFinish) {
  564. wx.showModal({
  565. title: '无法提交',
  566. content: '您还有部分题目未完成,请检查后重新提交',
  567. showCancel: false,
  568. confirmColor: '#0BC3AA',
  569. confirmText: "好的",
  570. success(res) {
  571. console.log(emptyKey.toString());
  572. that.setData({
  573. mInputId: emptyKey.toString()
  574. })
  575. }
  576. })
  577. return;
  578. }
  579. // 将surveyData发送到服务器
  580. console.log('提交的问卷数据:', surveyData);
  581. if (!that.data.intervalId1) {
  582. that.data.intervalId1 = setInterval(() => {
  583. //提交到数据库
  584. wx.request({
  585. url: `${homeApi}/system/constitutionDiagnosis`, //
  586. method: 'POST',
  587. header: {
  588. 'content-type': 'application/json', // 默认值
  589. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  590. },
  591. data: surveyData,
  592. success(res) {
  593. console.log('res===' + JSON.stringify(res));
  594. console.log('res.code===' + res.code);
  595. if (res && res.data && res.data.code == 200) {
  596. if (that.data.intervalId1) {
  597. clearInterval(that.data.intervalId1);
  598. that.data.intervalId1 = null;
  599. }
  600. wx.showToast({
  601. title: '问卷提交成功',
  602. icon: 'success',
  603. duration: 2000,
  604. success() {
  605. setTimeout(() => {
  606. wx.redirectTo({
  607. url: `/subpages/detectionResult/detectionResult?comScoreIndex=${comScoreIndex.slice(0, 1)}`,
  608. })
  609. }, 1000);
  610. }
  611. });
  612. }
  613. },
  614. fail: function (error) {
  615. console.error('error', error);
  616. },
  617. complete: function (e) {
  618. }
  619. });
  620. }, 1000);
  621. }
  622. // wx.showToast({
  623. // title: '问卷提交成功',
  624. // icon: 'success',
  625. // duration: 2000
  626. // });
  627. },
  628. // 取出最大值的obj
  629. findMaxValueKeyAndIndex(obj) {
  630. let maxValue = -Infinity;
  631. let maxKey = '';
  632. let maxIndex = -1;
  633. const keys = Object.keys(obj);
  634. keys.forEach((key, index) => {
  635. const value = obj[key];
  636. if (value > maxValue) {
  637. maxValue = value;
  638. maxKey = key;
  639. maxIndex = index;
  640. }
  641. });
  642. return {
  643. key: maxKey,
  644. value: maxValue,
  645. index: maxIndex
  646. };
  647. },
  648. export() {
  649. var that = this;
  650. const { nickName } = wx.getStorageSync('userInfo');
  651. const unionid = wx.getStorageSync('unionid');
  652. let exportData = {
  653. hotel: this.data.hotel,
  654. room: this.data.room,
  655. userId: nickName,
  656. id2: unionid,
  657. }
  658. if (!that.data.intervalId1) {
  659. that.data.intervalId1 = setInterval(() => {
  660. wx.request({
  661. url: `${homeApi}/system/constitutionDiagnosis/export`,
  662. method: 'POST',
  663. header: {
  664. 'content-type': 'application/json', // 默认值
  665. 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
  666. },
  667. // 参数
  668. data: exportData,
  669. responseType: "arraybuffer", // 该属性处理二进制数据
  670. success: res => {
  671. console.log('res==' + JSON.stringify(res));
  672. if (res.statusCode == 200) {
  673. if (that.data.intervalId3) {
  674. clearInterval(that.data.intervalId3);
  675. that.data.intervalId3 = null;
  676. }
  677. const fs = wx.getFileSystemManager(); // 获取全局唯一的文件管理器
  678. fs.writeFile({ //写文件
  679. // wx.env.USER_DATA_PATH是小程序提供的访问用户文件路劲的变量
  680. filePath: wx.env.USER_DATA_PATH + '/' + '体质问卷调查.xlsx', // 一般后端回返回文件名
  681. data: res.data, // res.data就是获取到的二进制文件流
  682. encoding: "binary", //二进制流文件必须是 binary
  683. success(e) {
  684. wx.openDocument({ // 打开文档
  685. filePath: wx.env.USER_DATA_PATH + '/' + '体质问卷调查.xlsx',
  686. showMenu: true, // 显示右上角菜单
  687. success: function (res) {
  688. console.log("打开文件", res);
  689. },
  690. })
  691. }
  692. })
  693. }
  694. },
  695. error(err) {
  696. console.log('export-err==' + err)
  697. }
  698. })
  699. }, 2000);
  700. }
  701. },
  702. onCloseResultsDialog() {
  703. this.setData({ promptTextMessageFlag: false });
  704. },
  705. onLoad(option) {
  706. var that = this;
  707. console.log("constitutionDiagnosis页面");
  708. // wx.clearStorage();
  709. // console.log('option.res=' + JSON.stringify(wx.getStorageSync('res')));
  710. // if (!wx.getStorageSync('res') || !wx.getStorageSync('res').result) {
  711. // wx.showModal({
  712. // title: '提示',
  713. // content: '请先扫描房间二维码',
  714. // showCancel: false
  715. // });
  716. // setTimeout(function () {
  717. // wx.reLaunch({
  718. // url: '/subpages/scan/scan',
  719. // })
  720. // }, 2000) // 设置延时时间,单位为毫秒
  721. // } else if (wx.getStorageSync('res').result.split('|').length != 2) {
  722. // wx.showModal({
  723. // title: '提示',
  724. // content: '房间二维码不正确,请重新扫码',
  725. // showCancel: false
  726. // });
  727. // setTimeout(function () {
  728. // wx.reLaunch({
  729. // url: '/subpages/scan/scan',
  730. // })
  731. // }, 2000) // 设置延时时间,单位为毫秒
  732. // } else {
  733. // const expiresAt = wx.getStorageSync('scanResultExpiresAt');
  734. // const now = Date.now()
  735. // if (expiresAt || expiresAt < now) {
  736. // // 扫码结果已过期
  737. // wx.showToast({
  738. // title: '扫码结果失效或已过期,请重新扫码',
  739. // icon: 'none'
  740. // });
  741. // // 清除过期的扫码结果
  742. // wx.removeStorageSync('scanResultExpiresAt');
  743. // setTimeout(function() {
  744. // wx.reLaunch({
  745. // url: '/pages/scan/scan',
  746. // })
  747. // }, 2000) // 设置延时时间,单位为毫秒
  748. // }else{
  749. // //续期
  750. // wx.setStorageSync('scanResultExpiresAt', Date.now() + 2 * 60 * 60 * 1000)
  751. // }
  752. let hotelTemp = '';
  753. let roomTemp = '';
  754. hotelTemp = wx.getStorageSync('hotelEmpower');
  755. roomTemp = wx.getStorageSync('roomEmpower');
  756. // hotelTemp = wx.getStorageSync('res').result.split('|')[0];
  757. // roomTemp = wx.getStorageSync('res').result.split('|')[1];
  758. this.setData({
  759. hotel: hotelTemp,
  760. room: roomTemp,
  761. });
  762. // }
  763. },
  764. areAllArraysEmpty: function (arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8) {
  765. // 定义一个数组来包含所有传入的数组
  766. const arrays = [arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8];
  767. // 遍历这个数组,检查每一项(即传入的数组)是否为空
  768. for (let i = 0; i < arrays.length; i++) {
  769. // 检查当前数组是否为空(即长度为0)
  770. if (arrays[i] && arrays[i].length > 0) {
  771. // 如果发现任何一个数组不为空,则返回false
  772. return false;
  773. }
  774. }
  775. // 如果所有数组都检查过了,且都是空的,则返回true
  776. return true;
  777. },
  778. //根据第二个数组对应第一个数组的value列,取第一个数组的remark的值,组成新的数组
  779. getRemarkValues: function (options, values) {
  780. if (!options || options.length === 0 || !values || values.length === 0) {
  781. return [];
  782. }
  783. // 初始化一个空数组来存储结果
  784. let remarkValues = [];
  785. // 遍历values数组
  786. values.forEach(value => {
  787. // 遍历options数组
  788. options.forEach(option => {
  789. // 如果找到了对应的value,则将该option的remark添加到result数组中
  790. if (option.value == value) {
  791. remarkValues.push(option.remark);
  792. }
  793. });
  794. });
  795. console.log('remarkValues=' + remarkValues);
  796. // 返回包含所有remark值的数组
  797. return remarkValues;
  798. },
  799. // ratingResultsList里的index和list字段相对应,如果两个值相等,将opacity的值改为'1'
  800. updateOpacity: function (ratingResultsList, list) {
  801. // 如果ratingResultsList为空,则直接返回
  802. if (!ratingResultsList || ratingResultsList.length === 0) {
  803. return ratingResultsList;
  804. }
  805. // 如果list为空,则直接返回原ratingResultsList
  806. if (!list || list.length === 0) {
  807. return ratingResultsList;
  808. }
  809. // 否则,进行更新操作
  810. return ratingResultsList.map(item => {
  811. // 如果item的index在list中,则修改opacity为'1',否则保持原样
  812. if (list.includes(item.index)) {
  813. return {
  814. ...item,
  815. opacity: '1'
  816. };
  817. }
  818. return item;
  819. });
  820. },
  821. submitDB: function () {
  822. var that = this;
  823. if (!that.data.intervalId1) {
  824. that.data.intervalId1 = setInterval(() => {
  825. that.submitSurvey();
  826. }, 1000);
  827. }
  828. },
  829. onShow: function (options) {
  830. // var that = this;
  831. // if (!that.data.intervalId2) {
  832. // that.data.intervalId2 = setInterval(() => {
  833. // // 这里执行你的代码
  834. // console.log('sleepEvaluation页面:'+Date.now());
  835. // }, 10000);
  836. // }
  837. },
  838. // startInterval: function () {
  839. // var that = this;
  840. // if (!that.data.intervalId) {
  841. // that.data.intervalId = setInterval(() => {
  842. // that.submitSurvey();
  843. // }, 1000);
  844. // }
  845. // },
  846. // clearInterval: function () {
  847. // var that = this;
  848. // if (that.data.intervalId) {
  849. // clearInterval(that.data.intervalId);
  850. // that.data.intervalId = null;
  851. // }
  852. // },
  853. /**
  854. * 生命周期函数--监听页面隐藏
  855. */
  856. onHide: function () {
  857. var that = this;
  858. if (that.data.intervalId1) {
  859. clearInterval(that.data.intervalId1);
  860. that.data.intervalId1 = null;
  861. }
  862. // if (this.data.intervalId2) {
  863. // clearInterval(this.data.intervalId2);
  864. // this.data.intervalId2 = null; // 可选,但建议清除以避免潜在的错误
  865. // }
  866. if (that.data.intervalId3) {
  867. clearInterval(that.data.intervalId3);
  868. that.data.intervalId3 = null;
  869. }
  870. },
  871. /**
  872. * 生命周期函数--监听页面卸载
  873. */
  874. onUnload: function () {
  875. var that = this;
  876. if (that.data.intervalId1) {
  877. clearInterval(that.data.intervalId1);
  878. that.data.intervalId1 = null;
  879. }
  880. // if (this.data.intervalId2) {
  881. // clearInterval(this.data.intervalId2);
  882. // this.data.intervalId2 = null; // 可选,但建议清除以避免潜在的错误
  883. // }
  884. if (that.data.intervalId3) {
  885. clearInterval(that.data.intervalId3);
  886. that.data.intervalId3 = null;
  887. }
  888. },
  889. //取出arr2的value和arr1对应的remark和label项,取出的数据组装成一个字符串,加上'char10'
  890. getFormattedString: function (arr1, arr2) {
  891. // 检查 arr1 和 arr2 是否为非空数组
  892. if (!arr1 || !arr2 || !Array.isArray(arr1) || arr1.length === 0 || !Array.isArray(arr2) || arr2.length === 0) {
  893. return '';
  894. }
  895. let result = '';
  896. arr1.forEach(value => {
  897. const valueStr = value ? value.toString() : '';
  898. const item = arr2.find(obj => obj.value == valueStr);
  899. if (item) {
  900. result += ` ${item.remark}、${item.label} char10`;
  901. }
  902. });
  903. return result;
  904. }
  905. });