constitutionDiagnosis.js 27 KB

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