| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305 |
- // subpages/textStep/textStep.js
- const baseUrl = "https://fare.somnisix.top/";
- const authorization = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6Ijk5YzI3MjI2LTdkOWQtNDhiOC1hYjlhLWM4YjVjYWZiZGNkNyIsInVzZXJuYW1lIjoiYWRtaW4ifQ.zITQOINFkHs19_1RAgHS4I9YMaVxVq0Dsn3t6r_K7rv3rXvJy0sMtodejIMi_PNa_m4uQYxnU-6k3wC2LZht_Q";
- const api = "system/sleepEvaluation";
- const homeApi = "https://fare.somnisix.top";
- const homeApiTest = "http://localhost:8080";
- const token = "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6Ijk5YzI3MjI2LTdkOWQtNDhiOC1hYjlhLWM4YjVjYWZiZGNkNyIsInVzZXJuYW1lIjoiYWRtaW4ifQ.zITQOINFkHs19_1RAgHS4I9YMaVxVq0Dsn3t6r_K7rv3rXvJy0sMtodejIMi_PNa_m4uQYxnU-6k3wC2LZht_Q";
- let countABCDEF;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- type: "sleep",//报告类型
- testTitle: "睡眠质量指数评测",
- step: 1,
- stepTotal: 9,
- gender: 1,//1 男 2 女
- age: '',//年龄
- height: '',//身高
- weight: '',//体重
- currentDate: "",
- currentDateItem: null,
- showDateDialog: false,
- formatter(type, value) {
- if (type === 'hour') {
- return `${value}时`;
- }
- if (type === 'minute') {
- return `${value}分`;
- }
- return value;
- },
- hotel: '',//酒店
- room: '',//房间
- physiqueData: [
- {
- id: 1,
- title: '身体综合(多选)',
- type: 'checkbox',
- value: [],//选出来的values
- options: [
- { value: '0', remark: 'A', label: '易疲劳,总感到疲倦' },
- { value: '1', remark: 'A', label: '好出汗,一活动就冒汗' },
- { value: '2', remark: 'A', label: '易感冒,恢复慢' },
- { value: '3', remark: 'A', label: '稍一活动就气喘' },
- { value: '4', remark: 'A', label: '疲劳后身体就不舒服' },
- { value: '5', remark: 'A', label: '无食欲' },
- { value: '6', remark: 'A', label: '手脚发凉' },
- { value: '7', remark: 'A', label: '肌肉无力' },
- { value: '8', remark: 'B', label: '腹部易滞气' },
- { value: '9', remark: 'B', label: '头痛、肩凝、关节痛、胃疼、手脚麻痹' },
- { value: '10', remark: 'B', label: '紧张、发怒后身体不舒服' },
- { value: '11', remark: 'B', label: '身体有痛感后,疼痛部位游走不定' },
- { value: '12', remark: 'C', label: '易眩晕和站起时头晕' },
- { value: '13', remark: 'C', label: '常感到心慌' },
- { value: '14', remark: 'C', label: '易头晕眼花' },
- { value: '15', remark: 'D', label: '有受伤和手术后的旧伤痛' },
- { value: '16', remark: 'D', label: '感到肩和腰、头有针扎样痛' },
- { value: '17', remark: 'D', label: '入夜后容易出现肩、腰、头疼痛' },
- { value: '18', remark: 'E', label: '喉咙易渴,常想喝水' },
- { value: '19', remark: 'E', label: '感冒愈后常干咳' },
- { value: '20', remark: 'E', label: '易便秘,大便呈球状' },
- { value: '21', remark: 'E', label: '尿量少、色浓' },
- { value: '22', remark: 'E', label: '身体总是发热' },
- { value: '23', remark: 'E', label: '持续低烧' },
- { value: '24', remark: 'F', label: '常感到身体和手脚沉重,易浮肿' },
- { value: '25', remark: 'F', label: '胃部不适、恶心' },
- { value: '26', remark: 'F', label: '雨天和湿度高时身体状况就很糟糕' },
- { value: '27', remark: 'F', label: '有时眩晕' },
- { value: '28', remark: 'F', label: '大便偏软' },
- { value: '29', remark: 'F', label: '易恶心、呕吐、晕车' },
- { value: '30', remark: '', label: '以上都没有' },
- ]
- },
- {
- id: 2,
- title: '面部五官(多选)',
- type: 'checkbox',
- value: [],//选出来的values
- options: [
- { value: '0', remark: 'B', label: '喉头部有异物感' },
- { value: '1', remark: 'C', label: '脸色不好' },
- { value: '2', remark: 'D', label: '眼圈发黑' },
- { value: '3', remark: 'E', label: '眼睛经常模糊不清' },
- { value: '4', remark: 'E', label: '多呈现消极、羸弱的面孔' },
- { value: '5', remark: 'F', label: '唾液和痰较多,中发黏' },
- { value: '6', remark: 'F', label: '易犯花粉症和鼻炎,容易淌鼻涕' },
- { value: '7', remark: '', label: '以上都没有' },
- ]
- },
- {
- id: 3,
- title: '皮肤毛发(多选)',
- type: 'checkbox',
- value: [],//选出来的values
- options: [
- { value: '0', remark: 'C', label: '头发脆弱,脱发' },
- { value: '1', remark: 'C', label: '皮肤和指甲无光泽' },
- { value: '2', remark: 'D', label: '皮肤干燥易皲裂,色斑、雀斑多' },
- { value: '3', remark: 'D', label: '皮肤呈青紫色或黑紫色,不光滑' },
- { value: '4', remark: 'D', label: '肤色暗淡' },
- { value: '5', remark: 'E', label: '洗浴后皮肤很快干燥,易发痒' },
- { value: '6', remark: 'E', label: '皮肤纹理粗糙、毛孔张开' },
- { value: '7', remark: '', label: '以上都没有' },
- ]
- },
- {
- id: 4,
- title: '情绪方面(多选)',
- type: 'checkbox',
- value: [],//选出来的values
- options: [
- { value: '0', remark: 'A', label: '经常情绪低落,容易受伤害' },
- { value: '1', remark: 'B', label: '焦虑、易怒' },
- { value: '2', remark: 'B', label: '常长吁短叹、嗳气' },
- { value: '3', remark: '', label: '以上都没有' },
- ]
- },
- {
- id: 5,
- title: '月经方面(多选)',
- type: 'checkbox',
- value: [],//选出来的values
- options: [
- { value: '0', remark: 'B', label: '月经前身体不适' },
- { value: '1', remark: 'C', label: '经血量少或月经周期过长' },
- { value: '2', remark: 'D', label: '月经痛加重、经血中有动物肝脏血块' },
- { value: '3', remark: '', label: '以上都没有' },
- ]
- },
- {
- id: 6,
- title: '性格方面(多选)',
- type: 'checkbox',
- value: [],//选出来的values
- options: [
- { value: '0', remark: 'A', label: '过度依赖人际关系' },
- { value: '1', remark: 'B', label: '具有攻击性,不善于体谅别人' },
- { value: '2', remark: 'C', label: '属冷静、认真型' },
- { value: '3', remark: 'C', label: '善于制造一个自我世界并沉溺其中' },
- { value: '4', remark: 'D', label: '忍耐性较强的性格,容易积聚压力' },
- { value: '5', remark: 'D', label: '接人待物中规中矩,严守礼节' },
- { value: '6', remark: 'F', label: '以自我为中心,争强好胜,嫉妒心强,爱慕虚荣' },
- { value: '7', remark: 'F', label: '喜欢奢华、热闹的氛围' },
- { value: '8', remark: '', label: '以上都没有' },
- ]
- },
- {
- id: 7,
- title: '睡眠(多选)',
- type: 'checkbox',
- value: [],//选出来的values
- options: [
- { value: '0', remark: 'B', label: '入睡困难' },
- { value: '1', remark: 'C', label: '睡眠浅,易做梦' },
- { value: '2', remark: '', label: '以上都没有' },
- ]
- },
- {
- id: 8,
- title: '舌头状态(多选)',
- type: 'checkbox',
- value: [],//选出来的values
- options: [
- { value: '0', remark: 'A', label: '整体色淡;厚、肿大;边缘呈齿状' },
- { value: '1', remark: 'B', label: '两侧赤红;中间色淡或偏白;薄薄的黄色舌苔' },
- { value: '2', remark: 'C', label: '舌体偏小;色淡、偏白,舌苔整体偏薄' },
- { value: '3', remark: 'D', label: '舌色暗、偏紫色;有黑色斑点;舌下两根静脉粗粗地浮现出来' },
- { value: '4', remark: 'E', label: '舌色整体发红;舌苔少、甚至没有;舌面有齿痕' },
- { value: '5', remark: 'F', label: '舌苔厚、黏黏糊糊;舌苔色黄或白;舌体肿胀' },
- { value: '6', remark: '', label: '以上都没有' },
- ]
- }
- ],
- sleepData: [
- {
- id: 1,
- title: '过去1个月通常上床睡觉的时间是?',
- type: 'date',
- value: '',//选出来的value
- options: [
- { value: '', label: '上床睡觉的时间' },
- ]
- }, {
- id: 2,
- title: '过去1个月你每晚通常要多长时间(分钟)才能入睡?',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '<15分钟' },
- { value: 'b', label: '16-30分钟' },
- { value: 'c', label: '31-60分钟' },
- { value: 'd', label: '>60分钟' },
- ]
- }, {
- id: 3,
- title: '过去1个月每天早上通常什么时候起床?',
- type: 'date',
- value: '',//选出来的value
- options: [
- { value: '', label: '起床时间' },
- ]
- }, {
- id: 4,
- title: '过去1个月你每天实际睡眠的时间有多少?',
- type: 'date',
- value: '',//选出来的value
- options: [
- { value: '', label: '每晚实际睡眠时间' },
- ]
- }, {
- id: 5,
- title: '过去1个月你是否因为以下问题而经常睡眠不好?',
- subTitle: 'A.不能在30分钟内入睡',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 6,
- title: '过去1个月你是否因为以下问题而经常睡眠不好?',
- subTitle: 'B.在晚上睡眠中醒来或早醒',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 7,
- title: '过去1个月你是否因为以下问题而经常睡眠不好?',
- subTitle: 'C.晚上有无起床上洗手间',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 8,
- title: '过去1个月你是否因为以下问题而经常睡眠不好?',
- subTitle: 'D.不舒服的呼吸',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 9,
- title: '过去1个月你是否因为以下问题而经常睡眠不好?',
- subTitle: 'E.大声咳嗽或打鼾',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 10,
- title: '过去1个月你是否因为以下问题而经常睡眠不好?',
- subTitle: 'F.感到寒冷',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 11,
- title: '过去1个月你是否因为以下问题而经常睡眠不好?',
- subTitle: 'G.感到太热',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 12,
- title: '过去1个月你是否因为以下问题而经常睡眠不好?',
- subTitle: 'H.做噩梦',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 13,
- title: '过去1个月你是否因为以下问题而经常睡眠不好?',
- subTitle: 'H.出现疼痛',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 14,
- title: '过去1个月你是否因为以下问题而经常睡眠不好?',
- subTitle: 'J.其他影响睡眠的事情',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 15,
- title: '你对过去1个月睡眠质量评分',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '非常好' },
- { value: 'b', label: '尚好' },
- { value: 'c', label: '不好' },
- { value: 'd', label: '非常差' },
- ]
- }, {
- id: 16,
- title: '近1个月你用催眠药物的情况',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 17,
- title: '过去1个月你在开车、吃饭或参加社会活动时难以保持清醒状态?',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 18,
- title: '过去1个月你在积极完成事情上有无困难?',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '没有困难' },
- { value: 'b', label: '有一点困难' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 19,
- title: '你是与人同睡一床(睡觉同伴,包括配偶等)或有室友?',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '没有与人同睡一床或有室友' },
- { value: 'b', label: '同伴或室友在另外房间' },
- { value: 'c', label: '同伴在同一房间但不睡同床' },
- { value: 'd', label: '同伴在同一床上' },
- ]
- }, {
- id: 20,
- title: '在你睡觉时,有无打鼾声',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 21,
- title: '在你睡觉时,呼吸之间有没有长时间停顿',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 22,
- title: '在你睡觉时,你的腿有无抽动或者有痉挛',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }, {
- id: 23,
- title: '在你睡觉时是否出现不能辨认方向或混乱状态',
- type: 'radio',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- },
- {
- id: 24,
- title: '在你睡觉时你有无其他睡不安宁的情况',
- type: 'radio&input',
- subTitle: '若有,请描述',
- value: '',//选出来的value
- options: [
- { value: 'a', label: '过去1个月没有' },
- { value: 'b', label: '每周平均不足1个晚上' },
- { value: 'c', label: '每周平均1-2个晚上' },
- { value: 'd', label: '每周平均3个或更多晚上' },
- ]
- }],
- inputValue: '',// 睡眠质量专用
- intervalId1:null
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- if (options.type) {
- var type = options.type;
- var testTitle = "";
- var testDesc = "";
- var stepTotal = 1;
- if (type == "physique") {
- // 体质
- testTitle = "体质诊断检测";
- testDesc = "本测试表由山东省中医药大学中医专家组(具有中医针灸师、中医芳香疗法指导师、医院临床检验科资质的主任医师们)提出。中医学依据气、血、水的平衡状态,将人分为六种体质。要改善身体的“不调”,最重要的就是先了解自己的体质。有人也可能是不同体质混合的“复合型”,而且人的体质日常是变化的,因此应根据每天变化的身体状态进行相应调理的养生疗法。我们根据人体部位分了八个方面,请从下面选项里选出和自己相符的项,提交后,系统会进行判断,并显示您的体质、分析和建议。";
- stepTotal = this.data.physiqueData.length + 1;
- } else if (type == "sleep") {
- // 睡眠质量
- testTitle = "睡眠质量指数评测";
- testDesc = "本测评系统依据山东睡眠质量指数量表(SDPSQI)开发。\nSDPSO1由山东省中医药大学医学中心精神科睡眠和生物节律研究中心睡眠专家组编制,专门用于评定被试者近一个月的主观睡眠质量。SDPSQI作为一种科学、系统的睡眠质量评估工具为了解个体睡眠状况、诊断睡眠障碍以及制定相应的干预措施提供了重要的工具和平台。";
- stepTotal = this.data.sleepData.length + 1;
- }
- this.setData({
- testTitle,
- testDesc,
- type,
- stepTotal
- })
- }
- let hotelTemp = '';
- let roomTemp = '';
- hotelTemp = wx.getStorageSync('hotelEmpower');
- roomTemp = wx.getStorageSync('roomEmpower');
- this.setData({
- hotel: hotelTemp,
- room: roomTemp,
- });
- },
- leftBack() {
- wx.navigateBack()
- },
- checkGender(e) {
- console.log(e.currentTarget.dataset.id);
- this.setData({
- gender: e.currentTarget.dataset.id - 0
- })
- },
- //单选框
- handleRadioBox(e) {
- if (this.data.type == "physique") {
- // 体质
- } else if (this.data.type == "sleep") {
- // 睡眠质量
- var list = this.data.sleepData;
- var index = e.currentTarget.dataset.index;
- var subIndex = e.currentTarget.dataset.subindex;
- var value = list[index].options[subIndex].value;
- list[index].value = value;
- this.setData({
- sleepData: list
- })
- }
- },
- // 多选框
- handleCheckBox(e) {
- console.log(e.currentTarget.dataset);
- if (this.data.type == "physique") {
- // 体质
- var list = this.data.physiqueData;
- var index = e.currentTarget.dataset.index;
- var subIndex = e.currentTarget.dataset.subindex;
- var values = list[index].value || [];
- var value = list[index].options[subIndex].value;
- if (values.indexOf(value) >= 0) {
- values = values.filter((item) => item != value);
- } else {
- values.push(value);
- }
- list[index].value = values;
- this.setData({
- physiqueData: list
- })
- } else if (this.data.type == "sleep") {
- // 睡眠质量
- }
- },
- toNext() {
- if (this.data.step == 1) {
- // 判断基本信息是否为空
- } else {
- // 判断列表是否有值
- if (this.data.type == "physique") {
- // 体质
- var list = this.data.physiqueData;
- var index = this.data.step - 2;
- var values = list[index].value || [];
- if (values <= 0) {
- wx.showModal({
- title: '无法提交',
- content: '您还有部分题目未完成,请检查后重新提交',
- showCancel: false,
- confirmColor: '#0BC3AA',
- confirmText: "好的",
- success(res) {
- }
- })
- return
- }
- } else if (this.data.type == "sleep") {
- // 睡眠质量
- var list = this.data.sleepData;
- var index = this.data.step - 2;
- var values = list[index].value;
- if ((list[index].type == 'radio&input' && this.data.inputValue.length <= 0 && values.length <= 0) || (list[index].type != 'radio&input' && (!values || values.length <= 0))) {
- wx.showModal({
- title: '无法提交',
- content: '您还有部分题目未完成,请检查后重新提交',
- showCancel: false,
- confirmColor: '#0BC3AA',
- confirmText: "好的",
- success(res) {
- }
- })
- return
- }
- }
- }
- if (this.data.step < this.data.stepTotal) {
- this.setData({
- step: this.data.step + 1
- })
- } else {
- // 结束了
- console.log('结束了');
- if (this.data.type == "physique") {
- // 体质
- this.commitPhysique();
- } else if (this.data.type == "sleep") {
- // 睡眠质量
- var that = this;
- wx.showLoading({
- title: '加载中',
- })
- if (!that.data.intervalId1) {
- that.data.intervalId1 = setInterval(() => {
- that.commitSleep();
- }, 1000);
- }
- }
- }
- },
- commitPhysique() {
- var that = this;
- var list = this.data.physiqueData;
- let resultMostFrequentLetters = this.findMostFrequentLetters(
- this.getRemarkValues(list[0].options, list[0].value),
- this.getRemarkValues(list[1].options, list[1].value),
- this.getRemarkValues(list[2].options, list[2].value),
- this.getRemarkValues(list[3].options, list[3].value),
- this.getRemarkValues(list[4].options, list[4].value),
- this.getRemarkValues(list[5].options, list[5].value),
- this.getRemarkValues(list[6].options, list[6].value),
- this.getRemarkValues(list[7].options, list[7].value)
- );
- const { nickName } = wx.getStorageSync('userInfo');
- const unionid = wx.getStorageSync('unionid');
-
- let comScoreIndex = [];
- let _comScoreStatus = "";
- let _comScoreDesc = ""
- if (!resultMostFrequentLetters || !Array.isArray(resultMostFrequentLetters) || !resultMostFrequentLetters.length) {
- comScoreIndex = [];
- _comScoreStatus = "";
- _comScoreDesc = ""
- } else {
- comScoreIndex = [];
- // 遍历输入数组
- resultMostFrequentLetters.forEach(item => {
- console.log('item=' + item);
- if (item == 'A') {
- if (_comScoreStatus) {
- _comScoreStatus += "\n气虚型";
- } else {
- _comScoreStatus += "气虚型";
- }
- if (_comScoreDesc) {
- _comScoreDesc += "\n气虚型:填写内容";
- } else {
- _comScoreDesc += "气虚型:填写内容";
- }
- comScoreIndex.push(0);
- } else if (item == 'B') {
- if (_comScoreStatus) {
- _comScoreStatus += "\n气滞型";
- } else {
- _comScoreStatus += "气滞型";
- }
- if (_comScoreDesc) {
- _comScoreDesc += "\n气滞型:填写内容";
- } else {
- _comScoreDesc += "气滞型:填写内容";
- }
- comScoreIndex.push(1);
- } else if (item == 'C') {
- if (_comScoreStatus) {
- _comScoreStatus += "\n血虚型";
- } else {
- _comScoreStatus += "血虚型";
- }
- if (_comScoreDesc) {
- _comScoreDesc += "\n血虚型:填写内容";
- } else {
- _comScoreDesc += "血虚型:填写内容";
- }
- comScoreIndex.push(2);
- } else if (item == 'D') {
- if (_comScoreStatus) {
- _comScoreStatus += "\n淤血型";
- } else {
- _comScoreStatus += "淤血型";
- }
- if (_comScoreDesc) {
- _comScoreDesc += "\n淤血型:填写内容";
- } else {
- _comScoreDesc += "淤血型:填写内容";
- }
- comScoreIndex.push(3);
- } else if (item == 'E') {
- if (_comScoreStatus) {
- _comScoreStatus += "\n水虚型";
- } else {
- _comScoreStatus += "水虚型";
- }
- if (_comScoreDesc) {
- _comScoreDesc += "\n水虚型:填写内容";
- } else {
- _comScoreDesc += "水虚型:填写内容";
- }
- comScoreIndex.push(4);
- } else if (item == 'F') {
- if (_comScoreStatus) {
- _comScoreStatus += "\n痰湿型";
- } else {
- _comScoreStatus += "痰湿型";
- }
- if (_comScoreDesc) {
- _comScoreDesc += "\n痰湿型:填写内容";
- } else {
- _comScoreDesc += "痰湿型:填写内容";
- }
- comScoreIndex.push(5);
- }
- });
- }
- let surveyData = {
- hotel: this.data.hotel,
- room: this.data.room,
- userId: nickName,
- id2: unionid,
- bodySynthesis: this.getFormattedString(list[0].value, list[0].options),
- facialFeatures: this.getFormattedString(list[1].value, list[1].options),
- skinHair: this.getFormattedString(list[2].value, list[2].options),
- emotion: this.getFormattedString(list[3].value, list[3].options),
- menstruation: this.getFormattedString(list[4].value, list[4].options),
- character: this.getFormattedString(list[5].value, list[5].options),
- sleep: this.getFormattedString(list[6].value, list[6].options),
- //舌头状态是新增加项,赋给value1了,数据库里有value1...value8,以备增加项用
- value1: this.getFormattedString(list[7].value, list[7].options),
- //value2 保存A、B、C、D、E、F 每个的个数
- value2: JSON.stringify(countABCDEF),
- comScoreStatus: _comScoreStatus ? _comScoreStatus : '健康型',
- comScoreIndex: comScoreIndex,
- comScoreDesc: _comScoreDesc,
- };
- var maxValueObj = that.findMaxValueKeyAndIndex(countABCDEF);
- console.log(countABCDEF);
- console.log(maxValueObj);
-
- // 体质提交
- if (!that.data.intervalId1) {
- that.data.intervalId1 = setInterval(() => {
- //提交到数据库
- wx.request({
- url: `${homeApi}/system/constitutionDiagnosis`, //
- method: 'POST',
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- data: surveyData,
- success(res) {
- console.log('res===' + JSON.stringify(res));
- console.log('res.code===' + res.code);
- if (res && res.data && res.data.code == 200) {
- if (that.data.intervalId1) {
- clearInterval(that.data.intervalId1);
- that.data.intervalId1 = null;
- }
- wx.showToast({
- title: '问卷提交成功',
- icon: 'success',
- duration: 2000,
- success() {
- setTimeout(() => {
- wx.redirectTo({
- url: `/subpages/testResultB/testResultB?comScoreIndex=${maxValueObj.index}`
- })
- }, 1000);
- }
- });
- }
- },
- fail: function (error) {
- console.error('error', error);
- },
- complete: function (e) {
- }
- });
- }, 1000);
- }
- },
- commitSleep() {
- // 睡眠质量提交
- var that = this;
- const { nickName } = wx.getStorageSync('userInfo');
- const unionid = wx.getStorageSync('unionid');
- const answerJson = this.data.sleepData;
- let value1 = answerJson[0].value;
- let value2 = answerJson[1].value;
- let value3 = answerJson[2].value;
- let value4 = answerJson[3].value;
- let value5a = answerJson[4].value;
- let value5b = answerJson[5].value;
- let value5c = answerJson[6].value;
- let value5d = answerJson[7].value;
- let value5e = answerJson[8].value;
- let value5f = answerJson[9].value;
- let value5g = answerJson[10].value;
- let value5h = answerJson[11].value;
- let value5i = answerJson[12].value;
- let value5j = answerJson[13].value;
- let value5jDes = '';//这个值没有算
- let value6 = answerJson[14].value;
- let value7 = answerJson[15].value;
- let value8 = answerJson[16].value;
- let value9 = answerJson[17].value;
- let value10 = answerJson[18].value;
- let value11 = answerJson[19].value;
- let value12 = answerJson[20].value;
- let value13 = answerJson[21].value;
- let value14 = answerJson[22].value;
- let value15 = answerJson[23].value;
- let value15Des = that.data.inputValue;//这个值没有算
- //计算规则 https://mp.weixin.qq.com/s/QyTzuPoNErMjc2KcA1M61g
- let comA = 0;//条目6
- let comB = 0;
- let comB1 = 0;
- let comC = 0;
- let comD = 0;
- let comE = 0;
- let comF = 0;
- let comG = 0;
- comA = this.resultABCD(value6);
- comB1 = this.resultABCD(value2) + this.resultABCD(value5a);
- if (comB1 == 0) {
- comB = 0;
- } else if (comB1 >= 1 && comB1 <= 2) {
- comB = 1;
- } else if (comB1 >= 3 && comB1 <= 4) {
- comB = 2;
- } else if (comB1 >= 5 && comB1 <= 6) {
- comB = 3;
- }
- let value41 = parseInt((value4.split(':')[0]), 10) || 0;
- let value42 = parseInt((value4.split(':')[1]), 10) || 0;
- let value43 = value41 * 60 + value42;
- if (value43 > 420) {
- comC = 0;
- } else if (value43 >= 360 && value43 <= 420) {
- comC = 1;
- } else if (value43 >= 300 && value43 < 360) {
- comC = 2;
- } else if (value43 < 300) {
- comC = 3;
- }
- let datediff = this.calculateTimeDifference(value1, value3);
- let sleepRate = datediff ? ((value43 / datediff) * 100) : 0;
- if (sleepRate >= 85) {
- comD = 0;
- } else if (sleepRate >= 75 && sleepRate <= 84) {
- comD = 1;
- } else if (sleepRate >= 65 && sleepRate < 74) {
- comD = 2;
- } else if (sleepRate < 65) {
- comD = 3;
- }
- let value5All = this.resultABCD(value5b)
- + this.resultABCD(value5c)
- + this.resultABCD(value5d)
- + this.resultABCD(value5e)
- + this.resultABCD(value5f)
- + this.resultABCD(value5g)
- + this.resultABCD(value5h)
- + this.resultABCD(value5i)
- + this.resultABCD(value5j);
- if (value5All == 0) {
- comE = 0;
- } else if (value5All >= 1 && value5All <= 9) {
- comE = 1;
- } else if (value5All >= 10 && value5All <= 18) {
- comE = 2;
- } else if (value5All >= 19 && value5All <= 27) {
- comE = 3;
- }
- comF = this.resultABCD(value7);
- let valueGAll = this.resultABCD(value8) + this.resultABCD(value9);
- if (valueGAll == 0) {
- comG = 0;
- } else if (valueGAll >= 1 && valueGAll <= 2) {
- comG = 1;
- } else if (valueGAll >= 3 && valueGAll <= 4) {
- comG = 2;
- } else if (valueGAll >= 5 && valueGAll <= 6) {
- comG = 3;
- }
- let comAll = comA + comB + comC + comD + comE + comF + comG;
- let comScoreIndex = 0;
- let _comScoreStatus = "";
- let _comScoreDesc = "";
- if (comAll >= 0 && comAll <= 5) {
- _comScoreStatus = "非常好";
- } else if (comAll >= 6 && comAll <= 10) {
- _comScoreStatus = "良好";
- comScoreIndex = 1;
- } else if (comAll >= 11 && comAll <= 15) {
- _comScoreStatus = "一般";
- comScoreIndex = 2;
- } else {
- // if (comAll >= 16 && comAll <= 21)
- _comScoreStatus = "差";
- comScoreIndex = 3;
- }
- if (this.judgmentScoreRange(comAll, 0, 5)) {
- _comScoreDesc = "你目前的睡眠质量非常高,而且健康状况良好,这一切应该继续保持下去。"
- } else if (this.judgmentScoreRange(comAll, 6, 10)) {
- _comScoreDesc = "你的睡眠质量平平,健康状况也受到影响, 如果再不引起你对睡眠质量的足够重视, 那么你的睡眠质量很可能会迅速下降,向下一级别发展。"
- } else if (this.judgmentScoreRange(comAll, 11, 15)) {
- _comScoreDesc = "如果你在这一级别内,那么你的睡眠质量可 就亮起红灯了。你必须警惕,因为你的睡眠质量确实比较糟糕,健康状况明显受损。饮食起居会受到一定影响,甚至部分工作你都开始感觉吃力。"
- } else {
- _comScoreDesc = "天啊!你的睡眠质量已经到了令人发指的地 步—长期睡眠不足导致了你的健康状况严重恶化,这就是你工作力不从心,情绪起伏不定的原因。"
- }
- let surveyData = {
- hotel: this.data.hotel,
- room: this.data.room,
- userId: nickName,
- id2: unionid,
- value1: value1,
- value2: value2,
- value3: value3,
- value4: value4,
- value5a: value5a,
- value5b: value5b,
- value5c: value5c,
- value5d: value5d,
- value5e: value5e,
- value5f: value5f,
- value5g: value5g,
- value5h: value5h,
- value5i: value5i,
- value5j: value5j,
- value5jDes: value5jDes,
- value6: value6,
- value7: value7,
- value8: value8,
- value9: value9,
- value10: value10,
- value11: value11,
- value12: value12,
- value13: value13,
- value14: value14,
- value15: value15,
- value15Des: value15Des,
- value16: comAll,//备用16(评分)
- value17: _comScoreStatus,//备用17(评分说明)
- value18: _comScoreDesc,
- value18: comA + ',' + comB + ',' + comC + ',' + comD + ',' + comE + ',' + comF + ',' + comG //备用18(comA、comB、comC、comD、comE、comF、comG)
- };
- //提交到数据库
- wx.request({
- url: `${homeApi}/system/questionInvest`, //
- method: 'POST',
- header: {
- 'content-type': 'application/json', // 默认值
- 'Authorization': 'Bearer ' + token // 在头部设置认证信息,例如使用Bearer Token
- },
- data: surveyData,
- success(res) {
- console.log('res===' + JSON.stringify(res));
- console.log('res.code===' + res.data.code);
- if (res && res.data && res.data.code == 200) {
- wx.hideLoading();
- if (that.data.intervalId1) {
- clearInterval(that.data.intervalId1);
- that.data.intervalId1 = null;
- }
- wx.showToast({
- title: '问卷提交成功',
- icon: 'success',
- duration: 2000,
- success() {
- setTimeout(() => {
- wx.redirectTo({
- url: `/subpages/testResultA/testResultA?comScore=${comAll}`
- })
- }, 1000);
- }
- });
- }
- },
- fail: function (error) {
- console.error('error', error);
- },
- complete: function (e) {
- }
- });
- },
- handleSelectDate(event) {
- var item = event.currentTarget.dataset.item;
- const value = item.value || "";
- this.setData({ currentDateItem: item, currentDate: value, showDateDialog: true });
- console.log(this.data.currentDateItem);
- },
- onCloseDateDialog() {
- this.setData({ showDateDialog: false, currentDateItem: null });
- },
- onCloseResultsDialog() {
- this.setData({ promptTextMessageFlag: false });
- },
- onDateInput(event) {
- const item = this.data.currentDateItem;
- if (!item) {
- return
- }
- if (this.data.type == "physique") {
- // 体质
- } else if (this.data.type == "sleep") {
- // 睡眠质量
- let sleepData = this.data.sleepData;
- for (let i = 0; i < sleepData.length; i++) {
- const element = sleepData[i];
- if (element.id == item.id) {
- element.value = event.detail;
- break;
- }
- }
- console.log(event);
- this.setData({
- sleepData: sleepData
- });
- }
- this.onCloseDateDialog()
- },
- // 睡眠质量的方法
- resultABCD: function (a) {
- if (a == 'a') {
- return 0;
- } else if (a == 'b') {
- return 1;
- } else if (a == 'c') {
- return 2;
- } else if (a == 'd') {
- return 3;
- }
- },
- judgmentScoreRange(scoreValue, startScore, endScore) {
- return scoreValue >= startScore && scoreValue <= endScore;
- },
- // 将时间字符串转换为分钟数
- timeStringToMinutes: function (timeStr) {
- var parts = timeStr.split(":");
- return parseInt(parts[0], 10) * 60 + parseInt(parts[1], 10);
- },
- // 计算时间差(分钟)
- calculateTimeDifference: function (sleepTimeStr, wakeUpTimeStr) {
- // 将时间字符串转换为分钟
- var sleepTimeMinutes = this.timeStringToMinutes(sleepTimeStr);
- var wakeUpTimeMinutes = this.timeStringToMinutes("24:00") + this.timeStringToMinutes(wakeUpTimeStr); // 加上第二天的0点到起床时间的分钟数
- // 计算时间差
- var diffInMinutes = wakeUpTimeMinutes - sleepTimeMinutes;
- // 将分钟数转换回时间字符串格式 HH:mm
- var diffInHours = Math.floor(diffInMinutes / 60);
- var diffInMins = diffInMinutes % 60;
- // 返回时间差字符串
- return diffInMinutes;
- },
- // 体质的方法
- // 取出最大值的obj
- findMaxValueKeyAndIndex(obj) {
- if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
- throw new Error('Input must be a plain object');
- }
- let maxKey = null;
- let maxValue = 0;
- let maxIndex = 6;
- const keys = Object.keys(obj);
- keys.forEach((key, index) => {
- const value = obj[key];
- if (value > maxValue) {
- maxValue = value;
- maxKey = key;
- maxIndex = index;
- }
- });
- return {
- key: maxKey,
- value: maxValue,
- index: maxIndex
- };
- },
- /**
- * A、B、C、D、E、F 最后积累的数量对比,按数量多少来判断,6个分别对应:气虚型、气滞型、血虚型、淤血型、水虚型、痰湿型
- * 找出对象中值最大的键
- * @param {Object} obj - 包含键值对的对象
- * @returns {string|null} - 值最大的键,如果没有找到则返回null
- */
- findKeyWithMaxValue(obj) {
- if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
- throw new Error('Input must be a plain object');
- }
- let maxKey = null;
- let maxValue = 0;
- for (let key in obj) {
- if (obj.hasOwnProperty(key)) {
- if (obj[key] > maxValue) {
- maxValue = obj[key];
- maxKey = key;
- }
- }
- }
- return maxKey;
- },
- areAllArraysEmpty: function (arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8) {
- // 定义一个数组来包含所有传入的数组
- const arrays = [arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8];
- // 遍历这个数组,检查每一项(即传入的数组)是否为空
- for (let i = 0; i < arrays.length; i++) {
- // 检查当前数组是否为空(即长度为0)
- if (arrays[i] && arrays[i].length > 0) {
- // 如果发现任何一个数组不为空,则返回false
- return false;
- }
- }
- // 如果所有数组都检查过了,且都是空的,则返回true
- return true;
- },
- //统计这8个数组,总共包含A,B,C,D,E,F的个数,返回最多的一项(也可能多项):
- //如果有多个 最多 的情况,返回最多的几个,如果都是0或者空,返回空
- findMostFrequentLetters: function (arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8) {
- //判断6个数组是否都为空
- if (this.areAllArraysEmpty(arr1, arr2, arr3, arr4, arr5, arr6, arr7, arr8))
- return '';
- // 初始化一个对象来存储每个字母的计数
- const letterCounts = {
- A: 0,
- B: 0,
- C: 0,
- D: 0,
- E: 0,
- F: 0
- };
- // 定义一个辅助函数来更新计数
- function updateCounts(arr) {
- if (Array.isArray(arr)) {
- arr.forEach(item => {
- if (typeof item === 'string' && ['A', 'B', 'C', 'D', 'E', 'F'].includes(item)) {
- letterCounts[item]++;
- }
- });
- }
- }
- // 对每个数组调用辅助函数
- updateCounts(arr1);
- updateCounts(arr2);
- updateCounts(arr3);
- updateCounts(arr4);
- updateCounts(arr5);
- updateCounts(arr6);
- updateCounts(arr7);
- updateCounts(arr8);
- countABCDEF = letterCounts;
- // 找出出现次数最多的字母及其计数
- let maxCount = 0;
- let mostFrequentLetters = [];
- for (let letter in letterCounts) {
- if (letterCounts[letter] == 0) {
- continue;
- }
- if (letterCounts[letter] > maxCount) {
- maxCount = letterCounts[letter];
- mostFrequentLetters = [letter]; // 重置为当前最多的字母
- } else if (letterCounts[letter] === maxCount) {
- mostFrequentLetters.push(letter); // 如果计数相同,则添加到列表中
- }
- }
- // 如果所有字母的计数都是0或数组为空,则返回空
- if (mostFrequentLetters.length === 0) {
- return '';
- }
- // 返回出现次数最多的字母或字母集合
- return mostFrequentLetters;
- },
- //根据第二个数组对应第一个数组的value列,取第一个数组的remark的值,组成新的数组
- getRemarkValues: function (options, values) {
- if (!options || options.length === 0 || !values || values.length === 0) {
- return [];
- }
- // 初始化一个空数组来存储结果
- let remarkValues = [];
- // 遍历values数组
- values.forEach(value => {
- // 遍历options数组
- options.forEach(option => {
- // 如果找到了对应的value,则将该option的remark添加到result数组中
- if (option.value == value) {
- remarkValues.push(option.remark);
- }
- });
- });
- // 返回包含所有remark值的数组
- return remarkValues;
- },
- getFormattedString: function (arr1, arr2) {
- // 检查 arr1 和 arr2 是否为非空数组
- if (!arr1 || !arr2 || !Array.isArray(arr1) || arr1.length === 0 || !Array.isArray(arr2) || arr2.length === 0) {
- return '';
- }
- let result = '';
- arr1.forEach(value => {
- const valueStr = value ? value.toString() : '';
- const item = arr2.find(obj => obj.value == valueStr);
- if (item) {
- result += ` ${item.remark}、${item.label} char10`;
- }
- });
- return result;
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- var that = this;
- if (that.data.intervalId1) {
- clearInterval(that.data.intervalId1);
- that.data.intervalId1 = null;
- }
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- var that = this;
- if (that.data.intervalId1) {
- clearInterval(that.data.intervalId1);
- that.data.intervalId1 = null;
- }
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|