健康同学微信公众号h5项目
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1289 linhas
40KB

  1. <template>
  2. <div class="psychological-setting-container">
  3. <!-- nav -->
  4. <div class="nav-bar">
  5. <van-nav-bar title="心理监测参数设置" left-text="返回" @click-left="onNavBack" left-arrow>
  6. <!-- <template #right>
  7. <div class="setupClock_save" @click="onSubmit">保存</div>
  8. </template> -->
  9. </van-nav-bar>
  10. </div>
  11. <!-- main -->
  12. <div class="main">
  13. <div class="list">
  14. <div class="item">
  15. <div class="left">
  16. <span class="title">开启心理监测</span>
  17. </div>
  18. <div class="right">
  19. <van-switch v-model="enabled" :active-color="$green" />
  20. </div>
  21. </div>
  22. <div class="item left-gray" v-show="enabled">
  23. <div class="left">
  24. <span class="title">设备显示:</span>
  25. </div>
  26. <div class="right">
  27. <!-- <img :src="rightIcon" alt=""> -->
  28. <van-switch v-model="checked" :active-color="$green" />
  29. </div>
  30. </div>
  31. <!-- <div class="item left-gray" >
  32. <div class="left">
  33. <span class="title gray">检测周期:</span>
  34. </div>
  35. <div class="right" @click="onClick('interval')">
  36. <span>{{ interval }}分钟</span>
  37. <img :src="rightIcon" alt="">
  38. </div>
  39. </div> -->
  40. <div class="item time left-gray" v-show="enabled">
  41. <div class="left">
  42. <span class="title">监测时段:</span>
  43. </div>
  44. <div class="right time">
  45. <div class="time-item" @click="onClickDate('add')" v-show="date.dateList.length < 4">
  46. <span>添加时段</span>
  47. <img :src="rightIcon" alt="" />
  48. </div>
  49. <!-- <div class="time-item date" v-for="(item, index) in date.dateList" :key="index" @click="onClickDate('update', item)">
  50. <span>{{ item.startTime }} - {{ item.endTime }}</span>
  51. <img :src="rightIcon" alt="">
  52. <template slot="right">
  53. <van-button square type="danger" text="返回" />
  54. </template>
  55. </div>
  56. <div class="time-item" v-show="date.dateList.length === 10">
  57. <span>监测时段最大可设置10个</span>
  58. </div> -->
  59. </div>
  60. </div>
  61. <div class="item time-list" v-show="enabled">
  62. <div class="date-time" v-for="(item, index) in date.dateList" :key="index">
  63. <div class="time-left" @click="onClickDate('update', item)">
  64. <div class="left">
  65. <span>时段{{ index + 1 }}:</span>
  66. </div>
  67. <div class="right">
  68. <div class="border">{{ item.startTime }}</div>
  69. <span> - </span>
  70. <div class="border">{{ item.endTime }}</div>
  71. </div>
  72. </div>
  73. <div class="time-right">
  74. <div class="left">
  75. <span>时长:</span>
  76. <input
  77. type="tel"
  78. maxlength="2"
  79. v-model="item.duration"
  80. @input="onInput(index)"
  81. oninput="value=value.replace(/e|-|\+/ig,'').replace(/[^0-9]/ig,'').replace(/\s+/g,'')"
  82. />
  83. <span>小时</span>
  84. </div>
  85. <div class="right">
  86. <img :src="rightIcon" alt="" />
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. <!-- 提醒设置 -->
  92. <div class="item left-gray" v-show="enabled">
  93. <div class="left">
  94. <span class="title">提醒设置:</span>
  95. </div>
  96. <div class="right">
  97. <van-switch v-model="reminderChecked" :active-color="$green" />
  98. </div>
  99. </div>
  100. <div class="item left-gray" v-show="enabled">
  101. <div class="left">
  102. <span class="title gray">抑郁等级:</span>
  103. </div>
  104. <div class="right" @click="onClick('depressive')">
  105. <span>{{ formatReminder(setting.depressive) || '请选择' }}</span>
  106. <img :src="rightIcon" alt="" />
  107. </div>
  108. </div>
  109. <div class="item left-gray" v-show="enabled">
  110. <div class="left">
  111. <span class="title gray">压力等级:</span>
  112. </div>
  113. <div class="right" @click="onClick('pressure')">
  114. <span>{{ formatReminder(setting.pressure) || '请选择' }}</span>
  115. <img :src="rightIcon" alt="" />
  116. </div>
  117. </div>
  118. <div class="item left-gray" v-show="enabled">
  119. <div class="left">
  120. <span class="title gray">疲劳等级:</span>
  121. </div>
  122. <div class="right" @click="onClick('fatigue')">
  123. <span>{{ formatReminder(setting.fatigue) || '请选择' }}</span>
  124. <img :src="rightIcon" alt="" />
  125. </div>
  126. </div>
  127. <div class="item alarmType left-gray" v-show="enabled">
  128. <div class="left">
  129. <span class="title gray">提醒方式:</span>
  130. </div>
  131. <div class="right">
  132. <div class="checkbox-group">
  133. <van-checkbox name="a" shape="square" v-model="vibrateenabled" direction="horizontal">震动</van-checkbox>
  134. <van-checkbox name="b" shape="square" v-model="lcdenabled" direction="horizontal">亮屏</van-checkbox>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. <!-- bottom -->
  141. <div class="bottom">
  142. <div class="btn" @click="onPre" v-show="!showSubmit">上一步</div>
  143. <div class="btn" @click="onNext" v-show="!showSubmit">下一步</div>
  144. <div class="btn submit" @click="onSubmit" v-show="showSubmit">保存</div>
  145. </div>
  146. <!-- 弹窗 -->
  147. <van-dialog v-model="dialog.isDialogshow" show-cancel-button :show-confirm-button="false">
  148. <template #title>
  149. <div class="title">
  150. <span>{{ dialog.title }}</span>
  151. </div>
  152. </template>
  153. <template #default>
  154. <div class="dialog-container">
  155. <div class="selectConfirm">
  156. <div class="con">
  157. <van-cell v-for="(item, index) in dialog.confirmData" :key="`selectVPT${index}`" @click="onSelect(item)">
  158. <div class="text">
  159. <div v-html="item.text"></div>
  160. </div>
  161. <em :class="['circle', { on: selectConfirmActive == index }]"></em>
  162. </van-cell>
  163. </div>
  164. </div>
  165. </div>
  166. </template>
  167. </van-dialog>
  168. <!-- 时间选择器弹窗 -->
  169. <van-dialog v-model="dateDialog.show" :show-confirm-button="false" :close-on-click-overlay="true" @close="onCancel">
  170. <template #default>
  171. <div class="date-dialog-container">
  172. <div class="date-top">
  173. <div :class="['top-item', { active: date.currentCount === 0 }]" @click="onChooseDate(0)">
  174. <span>开始时段</span>
  175. </div>
  176. <div :class="['top-item', { active: date.currentCount === 1 }]" @click="onChooseDate(1)">
  177. <span>结束时段</span>
  178. </div>
  179. </div>
  180. <div class="date-bottom">
  181. <van-datetime-picker
  182. v-show="date.currentCount === 0"
  183. v-model="date.defaultStartTime"
  184. type="time"
  185. :formatter="formatter"
  186. :show-toolbar="false"
  187. :item-height="itemHeight"
  188. :visible-item-count="4"
  189. />
  190. <van-datetime-picker
  191. v-show="date.currentCount === 1"
  192. v-model="date.defaultEndTime"
  193. type="time"
  194. :formatter="formatter"
  195. :show-toolbar="false"
  196. :item-height="itemHeight"
  197. :visible-item-count="4"
  198. />
  199. </div>
  200. <div class="button-box">
  201. <!-- <div class="button" @click="onCancel">
  202. <span>关闭</span>
  203. </div> -->
  204. <div class="button">
  205. <div class="btn-item" @click="onCancel" v-show="date.action !== 'update'"><p class="cancel">返回</p></div>
  206. <div class="btn-item" @click="onDelete" v-show="date.action === 'update'"><p class="delete">删除</p></div>
  207. <div class="btn-item" @click="onConfirm(date.dateList.length)"><p class="confirm">完成</p></div>
  208. </div>
  209. </div>
  210. </div>
  211. </template>
  212. </van-dialog>
  213. <!-- 涉水停留告警间隔弹窗 -->
  214. <van-dialog
  215. v-model="isWearDialogshow"
  216. :close-on-click-overlay="false"
  217. :show-cancel-button="false"
  218. :show-confirm-button="false"
  219. >
  220. <template #title>
  221. <div class="title">
  222. <span>检测周期</span>
  223. </div>
  224. </template>
  225. <template #default>
  226. <div class="wear-dialog-container">
  227. <div class="selectConfirm">
  228. <div class="con">
  229. <p>请输入时间:</p>
  230. <div class="input-con">
  231. <label for="">检测周期: </label>
  232. <input type="text" maxlength="2" oninput="value=value.replace(/\s+/g,'')" v-model.trim="interval" />
  233. <label for="">分钟 </label>
  234. </div>
  235. <!-- <p>温馨提示:</p> -->
  236. <!-- <p>设置范围:30~500之间</p> -->
  237. <p class="error-tips">{{ warningDistanceTips }}</p>
  238. </div>
  239. <div class="button">
  240. <p @click="onCancelWear">返回</p>
  241. <p @click="onConfirmWear" class="confirm">确认</p>
  242. </div>
  243. </div>
  244. </div>
  245. </template>
  246. </van-dialog>
  247. </div>
  248. </template>
  249. <script>
  250. import ToastService from '@/services/toast-service';
  251. import DialogService from '@/services/dialog-service';
  252. import APIHealthy from '@/api/heathly';
  253. import APIDevice from '@/api/device';
  254. import { checkPeriodExist, isNotNull, isNull } from '@/services/utils-service';
  255. export default {
  256. name: '',
  257. data() {
  258. return {
  259. rightIcon: require('../../../assets/myself/health/right_more.png'), //右边图标
  260. checked: null, //是否选中
  261. interval: 60, //检测周期-定位检测
  262. alarmType: ['reportenabled'], //告警方式
  263. reportenabled: true, //是否上报数据,默认为true
  264. // 弹窗内容
  265. dialog: {
  266. isDialogshow: false,
  267. title: '告警等级',
  268. confirmData: [
  269. /* {
  270. text: "不告警",
  271. model: 3,
  272. checked: false,
  273. value: 0
  274. }, */
  275. {
  276. text: '轻度',
  277. model: 0,
  278. checked: false,
  279. value: 1
  280. },
  281. {
  282. text: '中度',
  283. model: 1,
  284. checked: false,
  285. value: 2
  286. },
  287. {
  288. text: '重度',
  289. model: 2,
  290. checked: false,
  291. value: 3
  292. }
  293. ]
  294. },
  295. // 日期弹窗内容
  296. dateDialog: {
  297. show: false
  298. },
  299. // 日期时间
  300. date: {
  301. action: '',
  302. model: null,
  303. defaultStartTime: '07:00',
  304. defaultEndTime: '23:00',
  305. currentCount: 0,
  306. currentDuration: '',
  307. dateList: [
  308. { startTime: '07:00', endTime: '23:00', model: 0, duration: 6 }
  309. /* { startTime: '08:00', endTime: '21:00', model: 0, reqTime: '08002100' },
  310. { startTime: '08:00', endTime: '21:00', model: 0, reqTime: '08002100' },
  311. { startTime: '08:00', endTime: '21:00', model: 0, reqTime: '08002100' },
  312. { startTime: '08:00', endTime: '21:00', model: 0, reqTime: '08002100' }, */
  313. ]
  314. },
  315. selectConfirmActive: 0, // 弹窗选中
  316. itemHeight: Number(((document.body.clientWidth / 750) * 95).toFixed()), // 日历组件item高度
  317. warningDistanceTips: '',
  318. isWearDialogshow: false,
  319. currentInterval: null,
  320. radioModel: '1',
  321. lcdenabled: false, //亮屏
  322. vibrateenabled: false, //震动
  323. setting: {
  324. depressive: 1,
  325. pressure: 1,
  326. fatigue: 1
  327. },
  328. currentReminder: '',
  329. currentDuration: '',
  330. durationList: [{ duration: '' }, { duration: '' }, { duration: '' }, { duration: '' }, { duration: '' }],
  331. showSubmit: null,
  332. reminderChecked: null, //提醒设置
  333. enabled: null, //心理监测开始与关闭
  334. isCompleted: null, //心理监测资料是否填写完整
  335. uid: ''
  336. };
  337. },
  338. watch: {
  339. interval: {
  340. handler(n) {
  341. let reg = /^[1-9]+[0-9]*$/;
  342. if (n === '') {
  343. this.warningDistanceTips = '检测周期不能为空';
  344. this.isCanSave = false;
  345. } else if (!reg.test(n)) {
  346. this.warningDistanceTips = '检测周期只能为整数';
  347. this.isCanSave = false;
  348. } else if (parseInt(n) < 3 || parseInt(n) > 60) {
  349. this.warningDistanceTips = '请输入3-60的整数';
  350. this.isCanSave = false;
  351. } else {
  352. this.warningDistanceTips = '';
  353. this.isCanSave = true;
  354. }
  355. },
  356. deep: true
  357. },
  358. enabled: {
  359. handler(n, o) {
  360. if (o === false && n === true) {
  361. // 2023.8.30 需求变更 关闭打开,不根据从接口获取到的设置来显示 根据设备角色使用默认设置
  362. this.checked = this.watchRole === 2;
  363. this.reminderChecked = this.watchRole === 2;
  364. this.setting =
  365. this.watchRole === 2
  366. ? { depressive: 1, pressure: 1, fatigue: 1 }
  367. : { depressive: 1, pressure: 1, fatigue: 1 };
  368. this.lcdenabled = this.watchRole === 2;
  369. this.vibrateenabled = this.watchRole === 2;
  370. this.date.dateList[0] = { startTime: '07:00', endTime: '23:00', model: 0, duration: 6 };
  371. // 2023.09.13 新需求 对于心理监测参数设置时,启用时,如果用户资料还未设置完成,则自动跳转到用户资料的参数设置
  372. if (this.isCompleted) {
  373. // 如果不完整,则自动跳转到用户资料的参数设置
  374. this.$router.push({
  375. name: 'personInfos',
  376. query: {
  377. from: 'psychologicalSetting',
  378. // 加多一个参数来识别显示保存文字按钮的文字,因为资料设置页面会有多个页面跳转
  379. isShowSubmit: true
  380. }
  381. });
  382. }
  383. } else if (o === true && n === false) {
  384. // 2023.8.30 新增需求 打开关闭,统一关闭显示,提醒,提醒方式开关
  385. this.checked = false;
  386. this.reminderChecked = false;
  387. this.lcdenabled = false;
  388. this.vibrateenabled = false;
  389. }
  390. },
  391. deep: true
  392. },
  393. // 2023.09.19 设置了“设备显示”关闭,则联动把“提醒设置”设置为不启用,提醒方式的2个选项都不选中
  394. checked: {
  395. handler(n, o) {
  396. if (o === true && n === false) {
  397. this.reminderChecked = false;
  398. }
  399. },
  400. deep: true
  401. },
  402. // 提醒设置,2023.9.1 需求变更 关闭打开,震动亮屏相应关闭打开
  403. reminderChecked: {
  404. handler(n, o) {
  405. if (o === false && n === true) {
  406. this.vibrateenabled = true;
  407. this.lcdenabled = true;
  408. this.setting =
  409. this.watchRole === 2
  410. ? { depressive: 1, pressure: 1, fatigue: 1 }
  411. : { depressive: 1, pressure: 1, fatigue: 1 };
  412. } else if (o === true && n === false) {
  413. this.vibrateenabled = false;
  414. this.lcdenabled = false;
  415. }
  416. },
  417. deep: true
  418. }
  419. },
  420. computed: {
  421. imei() {
  422. return this.$store.getters.serialNo;
  423. },
  424. watchRole() {
  425. return this.$store.getters.watchRole;
  426. }
  427. },
  428. created() {
  429. this.loadParams();
  430. this.getPersonData();
  431. this.getPsychAbilityConfig();
  432. },
  433. methods: {
  434. loadParams() {
  435. let params = this.$route.query;
  436. if (params) {
  437. this.showSubmit = params.from !== 'personInfos';
  438. }
  439. },
  440. // 获取个人信息
  441. getPersonData() {
  442. APIDevice.getPersonInfo({
  443. userId: this.$store.getters.userId,
  444. deviceId: this.$store.getters.deviceId
  445. }).then(res => {
  446. let data = res.data;
  447. this.uid = data.uid;
  448. if (
  449. isNotNull(data.gender) &&
  450. data.height > 0 &&
  451. data.weight > 0 &&
  452. isNotNull(data.bornDate) &&
  453. data.profession > 0 &&
  454. isNotNull(data.uid)
  455. ) {
  456. console.log('资料完整');
  457. this.isCompleted = true;
  458. }
  459. });
  460. },
  461. onNavBack() {
  462. this.$router.push({
  463. name: this.$route.query.from ? `${this.$route.query.from}` : 'watchSetting'
  464. });
  465. },
  466. getPsychAbilityConfig(action) {
  467. if (action !== 'delete') {
  468. ToastService.loading({ message: '数据加载中' });
  469. }
  470. //ToastService.loading({message: "数据加载中"});
  471. APIHealthy.getPsychAbilityConfig(this.imei)
  472. .then(res => {
  473. if (action !== 'delete') {
  474. ToastService.success({ message: '数据加载完成' });
  475. }
  476. //ToastService.success({message: "数据加载完成"});
  477. let data = res.data.data;
  478. if (data) {
  479. this.checked = data.device_display === 1;
  480. this.lcdenabled = data.brightening_screen === 1;
  481. this.vibrateenabled = data.vibrating_screen === 1;
  482. this.enabled = data.enabled === 1;
  483. this.setting = { ...data.reminder_setting.setting };
  484. this.reminderChecked = data.reminder_setting.enable === 1;
  485. this.date.dateList = data.time_area.map((item, index) => {
  486. console.log('item', item);
  487. return {
  488. startTime: item.time.slice(0, 5),
  489. endTime: item.time.slice(6, 11),
  490. duration: item.duration,
  491. model: index
  492. };
  493. });
  494. } else {
  495. // 根据设备角色 部分修改默认参数值
  496. this.enabled = false;
  497. this.checked = this.watchRole === 2;
  498. this.reminderChecked = this.watchRole === 2;
  499. this.setting =
  500. this.watchRole === 2
  501. ? { depressive: 2, pressure: 2, fatigue: 2 }
  502. : { depressive: 1, pressure: 1, fatigue: 1 };
  503. }
  504. })
  505. .catch(e => {
  506. DialogService.confirm({
  507. message: `${e.message}`
  508. });
  509. })
  510. .finally(() => {
  511. setTimeout(() => {
  512. ToastService.clear();
  513. }, 1500);
  514. });
  515. },
  516. // 获取个人信息
  517. /* getPersonData() {
  518. APIDevice.getPersonInfo({
  519. userId: this.$store.getters.userId,
  520. deviceId: this.$store.getters.deviceId
  521. }).then(res => {
  522. let data = res.data;
  523. this.uid = data.uid;
  524. if(isNotNull(data.gender) && data.height > 0 && data.weight > 0 && isNotNull(data.bornDate) && data.profession > 0 && isNotNull(data.uid)) {
  525. console.log("资料完整");
  526. this.isCompleted = true;
  527. }
  528. })
  529. }, */
  530. onSubmit(action) {
  531. const messageText = action === 'delete' ? '删除' : '设置';
  532. /* if(!this.isCanSave) {
  533. return DialogService.confirm({
  534. message: '请输入正确的检测周期'
  535. })
  536. } */
  537. let isNullDuration = this.date.dateList.some(d => {
  538. return isNull(d.duration);
  539. });
  540. if (isNullDuration) {
  541. return DialogService.confirm({
  542. message: `时长不能为空`
  543. });
  544. }
  545. let reqDateList = this.date.dateList.map(item => {
  546. return {
  547. duration: Number(item.duration),
  548. time: item.startTime + '-' + item.endTime
  549. };
  550. });
  551. let reqBody = {
  552. enabled: this.enabled ? 1 : 0,
  553. imei: this.imei,
  554. time_area: [
  555. /* { //监测时间段集合
  556. time: "08:00-12:00", //时间段范围
  557. duration: 2 //需要监测时长
  558. },
  559. {
  560. time: "12:00-18:00",
  561. duration: 3
  562. } */ ...reqDateList
  563. ],
  564. reminder_setting: {
  565. //设备提醒设置
  566. enable: this.reminderChecked ? 1 : 0, //启用 0禁用 1启用,//是否提醒 0否 1是(默认)
  567. setting: {
  568. ...this.setting
  569. /* depressive: 1,//抑郁:1=轻度(默认)/2=中度/3=高
  570. pressure: 1, //压力:1=轻度(默认)/2=中度/3=高
  571. fatigue: 1 //劳累:1=轻度(默认)/2=中度/3=高 */
  572. }
  573. },
  574. device_display: this.checked === true ? 1 : 0, //设备端显示 0否 1是
  575. brightening_screen: this.lcdenabled ? 1 : 0, //是否亮屏 0否 1是
  576. vibrating_screen: this.vibrateenabled ? 1 : 0 //是否振动 0否 1是
  577. };
  578. ToastService.loading({
  579. message: `${messageText}中`
  580. });
  581. APIHealthy.setPsychAbilityConfig(reqBody)
  582. .then(async res => {
  583. if (res.data.stateCode === 1) {
  584. ToastService.success({ message: `${messageText}成功` });
  585. if (action === 'delete') {
  586. setTimeout(() => {
  587. this.date.dateList = [];
  588. this.getPsychAbilityConfig('delete');
  589. }, 1500);
  590. } else {
  591. if (this.showSubmit) {
  592. setTimeout(() => {
  593. this.$router.push({
  594. name: 'watchSetting'
  595. });
  596. }, 1500);
  597. } else {
  598. // 2023.11.17
  599. // 首次设置心理参数后,调取自动填写问卷答案接口
  600. /* let autoCommit = await */ this.psychQuestionAutoCommit();
  601. /* if (isNotNull(autoCommit)) {
  602. setTimeout(() => {
  603. const authToken = this.$store.getters.authToken;
  604. const baseUrl =
  605. process.env.NODE_ENV === 'production'
  606. ? 'https://ai.ssjlai.com/h5-frontendweb'
  607. : 'https://id.ssjlai.com/h5-frontendweb';
  608. window.location.href = `${baseUrl}/#/PsychologicalModeling?uid=${this.uid}&token=${authToken}&fromSsjl=true&fromMenu=health`;
  609. }, 1500);
  610. } */
  611. /* setTimeout(() => {
  612. const authToken = this.$store.getters.authToken;
  613. const baseUrl = process.env.NODE_ENV === "production" ? 'https://ai.ssjlai.com/h5-frontendweb' : 'https://id.ssjlai.com/h5-frontendweb';
  614. window.location.href = `${baseUrl}/#/PsychologicalModeling?uid=${this.$route.query.uid}&token=${authToken}&fromSsjl=true&fromMenu=health`;
  615. },1500) */
  616. }
  617. }
  618. } else {
  619. ToastService.clear();
  620. DialogService.confirm({
  621. title: `${messageText}失败`,
  622. message: `${res.data.message}`
  623. });
  624. }
  625. })
  626. .catch(() => {})
  627. .finally(() => {
  628. setTimeout(() => {
  629. ToastService.clear();
  630. }, 1500);
  631. });
  632. },
  633. // 自动提交问卷调查接口
  634. psychQuestionAutoCommit() {
  635. let reqParams = {
  636. uid: this.uid
  637. };
  638. return new Promise((resolve, reject) => {
  639. APIDevice.psychQuestionAutoCommit(reqParams)
  640. .then(() => {
  641. resolve(true);
  642. })
  643. .catch(() => {
  644. reject(true);
  645. });
  646. });
  647. },
  648. // 转换时间格式
  649. shiftTime(time, model) {
  650. if (time) {
  651. let startTime = time.slice(0, 2) + ':' + time.slice(2, 4);
  652. let endTime = time.slice(4, 6) + ':' + time.slice(6, 8);
  653. let timeObj = {
  654. startTime: startTime,
  655. endTime: endTime,
  656. model: model,
  657. reqTime: time
  658. };
  659. this.date.dateList.push(timeObj);
  660. }
  661. },
  662. // 判断时间段数组里面的是否有对象,然后返回对应对象的值
  663. getReqTime(dateArr, index) {
  664. if (dateArr.length > 0) {
  665. if (dateArr[index]) {
  666. return dateArr[index].reqTime;
  667. } else {
  668. return '';
  669. }
  670. } else {
  671. return '';
  672. }
  673. },
  674. onSelect(data) {
  675. console.log('data', data, this.currentReminder);
  676. let currentReminder = this.currentReminder;
  677. this.setting[currentReminder] = data.value;
  678. this.selectConfirmActive = data.model;
  679. this.dialog.isDialogshow = false;
  680. console.log('currentReminder', this.setting[currentReminder], this.setting);
  681. },
  682. // 格式化提醒设置文字
  683. formatReminder(value) {
  684. let text = '';
  685. if (value == 1) {
  686. text = '轻度';
  687. } else if (value == 2) {
  688. text = '中度';
  689. } else if (value == 3) {
  690. text = '重度';
  691. } /* else if (value == 0) {
  692. text = '不告警'
  693. } */
  694. return text;
  695. },
  696. onClick(name) {
  697. console.log('name', name);
  698. this.dialog.isDialogshow = true;
  699. this.currentReminder = name;
  700. let seclectIndex = this.dialog.confirmData.findIndex(item => {
  701. return item.value == this.setting[name];
  702. });
  703. this.selectConfirmActive = seclectIndex;
  704. },
  705. onClickDate(action, data) {
  706. this.date.action = action;
  707. if (action === 'update') {
  708. this.date.defaultStartTime = data.startTime;
  709. this.date.defaultEndTime = data.endTime;
  710. this.date.model = data.model;
  711. console.log('action', action, data, this.date.dateList);
  712. }
  713. this.dateDialog.show = true;
  714. },
  715. onChooseDate(value) {
  716. this.date.currentCount = value;
  717. },
  718. formatter(type, val) {
  719. if (type === 'hour') {
  720. return val + '时';
  721. }
  722. if (type === 'minute') {
  723. return val + '分';
  724. }
  725. return val;
  726. },
  727. resetDate() {
  728. this.dateDialog.show = false;
  729. this.date.currentCount = 0;
  730. this.date.defaultStartTime = '08:00';
  731. this.date.defaultEndTime = '21:00';
  732. this.date.action = '';
  733. this.date.model = null;
  734. },
  735. onCancel() {
  736. this.resetDate();
  737. },
  738. // 判断新增或更新的 是否有时间交叉 todo
  739. checkPeriodExist() {
  740. let canSave = true;
  741. let list = null;
  742. if (this.date.action === 'add') {
  743. // 新增-跟所有判断
  744. list = this.date.dateList.map(item => {
  745. item.startTime = item.startTime.replace('-', ':');
  746. item.endTime = item.endTime.replace('-', ':');
  747. item.weekdays = '0';
  748. return item;
  749. });
  750. } else {
  751. // 更新-跟除自己以外判断
  752. list = this.date.dateList.filter(item => {
  753. return this.date.model !== item.model;
  754. });
  755. }
  756. console.log('list', list);
  757. let currentTimeObj = {
  758. startTime: this.date.defaultStartTime.replace('-', ':'),
  759. endTime: this.date.defaultEndTime.replace('-', ':'),
  760. weekdays: '0'
  761. };
  762. console.log('新增的时间对象', currentTimeObj);
  763. list.forEach(t => {
  764. if (checkPeriodExist(currentTimeObj, t)) {
  765. canSave = false;
  766. }
  767. });
  768. return canSave;
  769. },
  770. onDelete() {
  771. console.log('当前选中的time', this.date.defaultStartTime + this.date.defaultEndTime);
  772. console.log('当前第几个时间段', this.date.model);
  773. if (this.date.dateList.length === 1) {
  774. return DialogService.confirm({
  775. message: '心理监测至少要保留1个监测时间段'
  776. });
  777. }
  778. DialogService.confirm({
  779. message: '是否要删除当前的检测时段',
  780. showCancelButton: true
  781. })
  782. .then(() => {
  783. this.date.dateList = this.date.dateList.filter(item => {
  784. return item.model !== this.date.model;
  785. });
  786. console.log('dateList', this.date.dateList);
  787. this.onSubmit('delete');
  788. //this.resetDate();
  789. this.dateDialog.show = false;
  790. })
  791. .catch(() => {});
  792. },
  793. onConfirm(index) {
  794. console.log('当前的时间列表', this.date.dateList, index);
  795. console.log('时间段是否有交叉', this.checkPeriodExist());
  796. let startConflict = this.date.defaultStartTime.replace(':', '');
  797. let endConflict = this.date.defaultEndTime.replace(':', '');
  798. if (Number(startConflict) >= Number(endConflict)) {
  799. return DialogService.confirm({
  800. title: '设置失败',
  801. message: '开始时间不能大于结束时间'
  802. });
  803. } else if (!this.checkPeriodExist()) {
  804. return DialogService.confirm({
  805. title: '设置失败',
  806. message: '检测时间有交叉,请重新选择'
  807. });
  808. }
  809. if (this.date.action === 'add') {
  810. let dateObj = {
  811. startTime: this.date.defaultStartTime,
  812. endTime: this.date.defaultEndTime,
  813. time: this.date.defaultStartTime.replace(':', '') + this.date.defaultEndTime.replace(':', '')
  814. };
  815. this.date.dateList.push(dateObj);
  816. this.resetDate();
  817. } else if (this.date.action === 'update') {
  818. let selectIndex = this.date.dateList.findIndex(item => {
  819. console.log('item', item);
  820. return item.model === this.date.model;
  821. });
  822. this.date.dateList[selectIndex].startTime = this.date.defaultStartTime;
  823. this.date.dateList[selectIndex].endTime = this.date.defaultEndTime;
  824. this.date.dateList[selectIndex].time =
  825. this.date.defaultStartTime.replace(':', '') + this.date.defaultEndTime.replace(':', '');
  826. this.resetDate();
  827. }
  828. },
  829. onInput(index) {
  830. // eslint-disable-next-line no-self-assign
  831. this.date.dateList[index].duration = this.date.dateList[index].duration;
  832. this.durationList[index].duration = this.date.dateList[index].duration;
  833. },
  834. onCancelWear() {
  835. this.isWearDialogshow = false;
  836. this.interval = this.currentInterval;
  837. //this.warningDistanceTips = '';
  838. },
  839. onConfirmWear() {
  840. if (this.isCanSave) {
  841. this.isWearDialogshow = false;
  842. this.warningDistanceTips = '';
  843. }
  844. },
  845. onPre() {
  846. this.$router.push({
  847. name: 'personInfos'
  848. });
  849. },
  850. onNext() {
  851. let isInputNull = this.date.dateList.some(item => {
  852. return !isNotNull(item.duration);
  853. });
  854. let isMoreThan = this.date.dateList.some(item => {
  855. return this.checkTimeMorethan(item.startTime, item.endTime, item.duration);
  856. });
  857. if (!this.enabled) {
  858. return DialogService.confirm({
  859. message: '需要开启心理监测才能进行下一步'
  860. });
  861. } else if (isInputNull) {
  862. return DialogService.confirm({
  863. message: '监测时长不能为空'
  864. });
  865. } else if (isMoreThan) {
  866. return DialogService.confirm({
  867. message: '监测时长不能大于设置的监测时间间隔'
  868. });
  869. }
  870. this.onSubmit();
  871. },
  872. checkTimeMorethan(sTime, eTime, t) {
  873. // eslint-disable-next-line no-useless-escape
  874. let startTime = sTime.replace(/\:/g, '');
  875. // eslint-disable-next-line no-useless-escape
  876. let endTime = eTime.replace(/\:/g, '');
  877. console.log('startTime', startTime, 'startTime', endTime);
  878. let diff = (endTime - startTime) / 100;
  879. if (t > diff) {
  880. return true;
  881. } else {
  882. return false;
  883. }
  884. }
  885. }
  886. };
  887. </script>
  888. <style scoped lang="scss">
  889. .psychological-setting-container {
  890. height: 100vh;
  891. overflow: hidden;
  892. .nav-bar {
  893. height: 100px;
  894. padding: 0 20px;
  895. }
  896. .main {
  897. height: calc(100vh - 80px);
  898. background-color: $background;
  899. padding: 20px 0;
  900. overflow: scroll;
  901. padding-bottom: constant(safe-area-inset-bottom); //解决iphone X底部安全区域
  902. padding-bottom: env(safe-area-inset-bottom); //解决 iphone X底部安全区域
  903. .list {
  904. flex: 1;
  905. max-height: 80%;
  906. background-color: #fff;
  907. border-radius: 8px;
  908. overflow: scroll;
  909. .item {
  910. flex: 1;
  911. padding: 20px 20px;
  912. display: flex;
  913. justify-content: space-between;
  914. align-items: center;
  915. border-bottom: 2px solid #e5e5e5;
  916. .left {
  917. height: 60px;
  918. @include center();
  919. span {
  920. color: #282828;
  921. font-size: 32px;
  922. }
  923. .title {
  924. font-weight: 450;
  925. &.gray {
  926. color: gray;
  927. }
  928. }
  929. }
  930. .right {
  931. @include center();
  932. font-size: 32px;
  933. img {
  934. height: 35px;
  935. width: 35px;
  936. }
  937. span {
  938. font-size: 32px;
  939. margin-right: 10px;
  940. color: #aaaaaa;
  941. }
  942. &.time {
  943. width: 480px;
  944. display: flex;
  945. justify-content: space-between;
  946. align-items: flex-end;
  947. flex-direction: column;
  948. .time-item {
  949. height: 70px;
  950. width: 100%;
  951. display: flex;
  952. justify-content: flex-end;
  953. align-items: center;
  954. margin-bottom: 5px;
  955. .van-swipe-cell {
  956. display: flex;
  957. justify-content: flex-end;
  958. .van-swipe-cell__right {
  959. .van-button--danger {
  960. background-color: #ee0a24;
  961. @include center();
  962. span {
  963. color: #fff;
  964. }
  965. }
  966. }
  967. }
  968. &.date {
  969. display: flex;
  970. justify-content: flex-start;
  971. align-items: center;
  972. }
  973. }
  974. }
  975. }
  976. &.left-gray {
  977. padding-left: 30px;
  978. color: gray;
  979. }
  980. &.time {
  981. display: flex;
  982. justify-content: space-between;
  983. align-items: flex-start;
  984. }
  985. &.time-list {
  986. flex: 1;
  987. display: flex;
  988. justify-content: flex-start;
  989. align-items: flex-start;
  990. flex-direction: column;
  991. .date-time {
  992. width: 100%;
  993. display: flex;
  994. justify-content: space-between;
  995. align-items: center;
  996. margin: 20px 0;
  997. .time-left,
  998. .time-right {
  999. display: flex;
  1000. justify-content: flex-start;
  1001. align-items: center;
  1002. span {
  1003. font-size: 32px;
  1004. margin: 0 5px;
  1005. color: #999;
  1006. }
  1007. .left {
  1008. @include center();
  1009. .title {
  1010. font-weight: 450;
  1011. &.gray {
  1012. color: #999;
  1013. }
  1014. }
  1015. input {
  1016. height: 40px;
  1017. width: 60px;
  1018. font-size: 32px;
  1019. color: #999;
  1020. border: 1px solid #999;
  1021. margin: 0 5px;
  1022. }
  1023. }
  1024. .right {
  1025. .border {
  1026. font-size: 32px;
  1027. border: 1px solid #999;
  1028. padding: 5px;
  1029. margin: 0 10px;
  1030. color: #999;
  1031. span {
  1032. font-size: 32px;
  1033. margin: 0 5px;
  1034. }
  1035. }
  1036. img {
  1037. height: 35px;
  1038. width: 35px;
  1039. }
  1040. span {
  1041. font-size: 32px;
  1042. margin-right: 10px;
  1043. color: #999;
  1044. }
  1045. }
  1046. }
  1047. }
  1048. }
  1049. &.alarmType {
  1050. height: auto;
  1051. display: flex;
  1052. justify-content: space-between;
  1053. align-items: flex-start;
  1054. .right {
  1055. height: auto;
  1056. margin-left: 40px;
  1057. width: 50%;
  1058. display: flex;
  1059. justify-content: flex-start;
  1060. align-items: center;
  1061. .checkbox-group {
  1062. @include center();
  1063. .van-checkbox {
  1064. padding: 5px;
  1065. }
  1066. }
  1067. }
  1068. }
  1069. }
  1070. }
  1071. }
  1072. .bottom {
  1073. position: absolute;
  1074. bottom: -60px;
  1075. left: 0;
  1076. height: 120px;
  1077. width: 100%;
  1078. @include center();
  1079. .btn {
  1080. position: relative;
  1081. height: 80px;
  1082. width: 323px;
  1083. background-color: $green;
  1084. color: #fff;
  1085. font-size: 36px;
  1086. border-radius: 55px;
  1087. margin: 0 20px;
  1088. @include center();
  1089. &.gray {
  1090. background-color: #d1d2d4;
  1091. margin-right: 45px;
  1092. }
  1093. &.submit {
  1094. width: 80%;
  1095. }
  1096. }
  1097. }
  1098. .date-dialog-container {
  1099. min-height: 550px;
  1100. .date-top {
  1101. width: 100%;
  1102. height: 120px;
  1103. display: flex;
  1104. justify-content: space-between;
  1105. align-items: center;
  1106. .top-item {
  1107. height: 100%;
  1108. width: 50%;
  1109. @include center();
  1110. //border-right: .5 solid #e5e5e5;
  1111. background-color: #e5e5e5;
  1112. border-bottom: 2px solid #e5e5e5;
  1113. span {
  1114. font-size: 32px;
  1115. color: #000;
  1116. }
  1117. &.active {
  1118. background-color: #fff;
  1119. }
  1120. }
  1121. }
  1122. .date-bottom {
  1123. height: 380px;
  1124. }
  1125. .button-box {
  1126. position: absolute;
  1127. bottom: 0;
  1128. height: 100px;
  1129. width: 100%;
  1130. z-index: 999;
  1131. background-color: #fff;
  1132. @include center();
  1133. .button {
  1134. width: 100%;
  1135. display: flex;
  1136. justify-content: space-around;
  1137. align-items: center;
  1138. .btn-item {
  1139. width: 220px;
  1140. p {
  1141. font-size: 32px;
  1142. height: 80px;
  1143. width: 100%;
  1144. color: #000;
  1145. @include center();
  1146. }
  1147. .confirm {
  1148. color: $green;
  1149. }
  1150. .delete {
  1151. color: red;
  1152. }
  1153. .cancel {
  1154. color: #000;
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160. .wear-dialog-container {
  1161. padding: 30px 40px 0 40px;
  1162. font-size: 32px;
  1163. .selectConfirm {
  1164. padding: 0;
  1165. }
  1166. .con {
  1167. width: 100%;
  1168. overflow: scroll;
  1169. padding-bottom: 20px;
  1170. border-bottom: 1px solid #999;
  1171. .select-con {
  1172. height: 400px;
  1173. overflow: scroll;
  1174. padding: 15px 0;
  1175. }
  1176. .tips {
  1177. margin: 15px 0;
  1178. }
  1179. }
  1180. .button {
  1181. height: 80px;
  1182. @include center();
  1183. p {
  1184. font-size: 32px;
  1185. color: #000;
  1186. }
  1187. }
  1188. .input-con {
  1189. display: flex;
  1190. justify-content: flex-start;
  1191. align-items: center;
  1192. label {
  1193. color: #000;
  1194. }
  1195. input {
  1196. margin-left: 15px;
  1197. display: flex;
  1198. width: 80px;
  1199. height: 72px;
  1200. text-indent: 15px;
  1201. border-bottom: 1px solid #000;
  1202. }
  1203. }
  1204. p {
  1205. font-size: 32px;
  1206. margin: 15px 0;
  1207. color: #999;
  1208. }
  1209. .error-tips {
  1210. color: red;
  1211. }
  1212. .button {
  1213. display: flex;
  1214. justify-content: space-around;
  1215. align-items: center;
  1216. p {
  1217. width: 40%;
  1218. color: #000;
  1219. @include center();
  1220. }
  1221. .confirm {
  1222. color: $green;
  1223. }
  1224. }
  1225. }
  1226. .title {
  1227. font-size: 32px;
  1228. }
  1229. .selectConfirm {
  1230. padding: 0;
  1231. .con {
  1232. .van-cell {
  1233. height: 60px;
  1234. .van-cell__value {
  1235. em {
  1236. font-style: normal;
  1237. position: absolute;
  1238. top: 0;
  1239. right: 0;
  1240. @include colorAndFont(#999, 24);
  1241. &.circle {
  1242. width: 20px;
  1243. height: 20px;
  1244. border: 2px solid #bfbfbf;
  1245. border-radius: 50%;
  1246. position: absolute;
  1247. right: 15px;
  1248. &.on {
  1249. border-color: $green;
  1250. &:before {
  1251. content: '';
  1252. position: absolute;
  1253. left: 50%;
  1254. top: 50%;
  1255. transform: translate(-50%, -50%);
  1256. width: 14px;
  1257. height: 14px;
  1258. background: $green;
  1259. border-radius: 50%;
  1260. }
  1261. }
  1262. }
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. }
  1269. </style>