健康同学微信公众号h5项目
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

240 líneas
6.7KB

  1. <template>
  2. <div class="sleep" :style="{ background: listData.length == 0 ? '#fff ' : '#f2f4f5' }">
  3. <van-nav-bar title="休眠设置" left-arrow :border="true" @click-left="onNavBack">
  4. <van-icon name="plus" slot="right" id="plus-icon" @click="onAddClick" />
  5. </van-nav-bar>
  6. <div class="sleep-list-container" v-show="isShowPage">
  7. <div class="con">
  8. <van-cell v-for="(item, index) in listData" :key="`prohibit_${index}`">
  9. <van-swipe-cell>
  10. <div class="area">
  11. <div :class="[{ active: item.Active }, 'left']" @click="onListClick(item.Id)">
  12. <div class="title">{{ item.StartTime }}-{{ item.EndTime }}</div>
  13. </div>
  14. <van-switch :value="item.Active == 1" @input="onInput($event, item.Id)" :active-color="$green" />
  15. </div>
  16. <template slot="right">
  17. <van-button square type="danger" text="删除" @click="onClose(item.Id)" />
  18. </template>
  19. </van-swipe-cell>
  20. </van-cell>
  21. <div class="watchTips" v-show="deviceType == '2'">
  22. <p>休眠时间段:期间会自动切断网络,但有呼入电话或者亮屏设备时自动结束休眠</p>
  23. </div>
  24. </div>
  25. <div class="noData_img" v-show="listData.length == 0">
  26. <div v-if="deviceType == '1'">您还没有给定位卡设置休眠时段,赶紧去添加吧~</div>
  27. <div v-else class="watchTips">
  28. <p>请点击右上角“+”号添加休眠时段。</p>
  29. <p>休眠时间段:期间会自动切断网络,但有呼入电话或者亮屏设备时自动结束休眠</p>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import { DeviceCommandModel } from '../../config/models';
  37. import DialogService from '@/services/dialog-service';
  38. import ToastService from '@/services/toast-service';
  39. import APICommand from '@/api/command';
  40. export default {
  41. data() {
  42. return {
  43. switchShow: false,
  44. listData: [],
  45. serialNo: '',
  46. deviceType: this.$store.getters.deviceType,
  47. isShowPage: false
  48. };
  49. },
  50. methods: {
  51. //返回
  52. onNavBack() {
  53. this.$router.push({ name: 'Myself' });
  54. },
  55. onAddClick() {
  56. this.$router.push({
  57. name: 'setupSleepPeriod',
  58. query: { code: this.$route.query.code }
  59. });
  60. },
  61. switchClick() {
  62. this.switchShow = !this.switchShow;
  63. },
  64. onInput(checked, id) {
  65. /* this.$dialog.confirm({
  66. title: "提醒",
  67. className: "device_confirm",
  68. message: "是否切换开关?"
  69. }) */
  70. this.listData.map(val => {
  71. if (val.Id == id) {
  72. val.Active = checked ? 1 : 0;
  73. }
  74. return val;
  75. });
  76. let cmdCode = DeviceCommandModel.sleep;
  77. let cmdValue = {
  78. Items: this.listData
  79. };
  80. this.sendCommand(cmdCode, JSON.stringify(cmdValue));
  81. },
  82. onListClick(id) {
  83. this.$router.push({
  84. name: 'setupSleepPeriod',
  85. query: { code: this.$route.query.code, id }
  86. });
  87. },
  88. //滑动单元格
  89. onClose(id) {
  90. this.listData.some((val, i) => {
  91. if (val.Id == id) {
  92. this.listData.splice(i, 1);
  93. return true;
  94. }
  95. });
  96. let cmdCode = DeviceCommandModel.sleep;
  97. let cmdValue = {
  98. Items: this.listData
  99. };
  100. this.sendCommand(cmdCode, JSON.stringify(cmdValue));
  101. },
  102. //获取信息
  103. getCommandList() {
  104. /* let url = `/api/Command/CommandList`;
  105. let jsonData = { deviceId: this.$store.getters.deviceId };
  106. ToastService.loading();
  107. this.$axios
  108. .post(url, jsonData) */
  109. APICommand.commandList({
  110. deviceId: this.$store.getters.deviceId
  111. })
  112. .then(res => {
  113. ToastService.clear();
  114. console.log(res.data);
  115. let item = res.data;
  116. let listData = [];
  117. let cmdData = item.items.filter(val => val.cmdCode == DeviceCommandModel.sleep);
  118. let parseValue = JSON.parse(cmdData[0].cmdValue);
  119. parseValue.Items.forEach(val => {
  120. listData.push(val);
  121. });
  122. this.listData = listData;
  123. this.isShowPage = true;
  124. })
  125. .catch(() => {
  126. this.isShowPage = true;
  127. });
  128. },
  129. //处理方面的
  130. formatWeekdays(str) {
  131. let arr = Array.from(str);
  132. let newArr = [];
  133. arr.forEach(val => {
  134. switch (Number(val)) {
  135. case 1:
  136. newArr.push('周一 ');
  137. break;
  138. case 2:
  139. newArr.push('周二 ');
  140. break;
  141. case 3:
  142. newArr.push('周三 ');
  143. break;
  144. case 4:
  145. newArr.push('周四 ');
  146. break;
  147. case 5:
  148. newArr.push('周五 ');
  149. break;
  150. case 6:
  151. newArr.push('周六 ');
  152. break;
  153. case 7:
  154. newArr.push('周日 ');
  155. break;
  156. default:
  157. newArr = [];
  158. }
  159. });
  160. return newArr;
  161. },
  162. //提交
  163. sendCommand(cmdCode, cmdValue) {
  164. ToastService.loading();
  165. /* let url = `/api/Command/SendCommand`;
  166. let jsonData = {
  167. deviceId: this.$store.getters.deviceId,
  168. userId: this.$store.getters.userId,
  169. serialNo: this.$store.getters.serialNo,
  170. cmdCode,
  171. cmdValue
  172. }; */
  173. ToastService.loading();
  174. /* this.$axios
  175. .post(url, jsonData) */
  176. APICommand.sendCommand({
  177. deviceId: this.$store.getters.deviceId,
  178. userId: this.$store.getters.userId,
  179. serialNo: this.$store.getters.serialNo,
  180. cmdCode,
  181. cmdValue
  182. })
  183. .then(res => {
  184. console.log(res.data);
  185. ToastService.clear();
  186. let item = res.data;
  187. if (item.stateCode == 1) {
  188. ToastService.clear();
  189. ToastService.success({ message: '操作成功' });
  190. } else {
  191. DialogService.confirm({ title: '操作失败' });
  192. }
  193. })
  194. .catch(() => {});
  195. }
  196. },
  197. created() {
  198. this.getCommandList();
  199. }
  200. };
  201. </script>
  202. <style lang="scss" scoped>
  203. .sleep {
  204. position: relative;
  205. height: 100vh;
  206. width: 100%;
  207. overflow: hidden;
  208. .sleep-list-container {
  209. position: relative;
  210. height: calc(100vh - 160px);
  211. overflow: scroll;
  212. .con {
  213. width: 100%;
  214. background: #fff;
  215. .area {
  216. padding: 0 30px;
  217. height: 100px;
  218. display: flex;
  219. justify-content: space-between;
  220. align-items: center;
  221. .title {
  222. font-size: 36px;
  223. }
  224. }
  225. }
  226. .noData_img,
  227. .watchTips {
  228. font-size: 32px;
  229. height: 400px;
  230. padding: 0 40px;
  231. @include flexbox(center, center, column, nowrap);
  232. }
  233. }
  234. }
  235. </style>