clockalarm.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view>
  3. <uni-nav-bar fixed :border="false" backgroundColor="#fff" :title="title" :statusBar="true" left-icon="left" @clickLeft="$navBack()" @clickRight="handleAdd">
  4. <!-- #ifndef MP-WEIXIN -->
  5. <template v-slot:right>
  6. <uni-icons type="plusempty" size="20"></uni-icons>
  7. </template>
  8. <!-- #endif -->
  9. </uni-nav-bar>
  10. <scroll-view scroll-y="true" :style="{height: `calc(100vh - ${statusBarHeight} - 88rpx)`}">
  11. <view class="container-body">
  12. <myEmpty text="暂无闹钟" v-show="$isEmpty(clockalarmInfo) || clockalarmInfo.length == 0"></myEmpty>
  13. <view class="list">
  14. <uni-swipe-action-item v-for="(item,idx) in clockalarmInfo" :key="idx" :right-options="options" @click="onClick(idx)">
  15. <view class="list-item border-line">
  16. <view class="list-item-left" @click.stop="editClockalarm(item,idx)">
  17. <view class="item-time">{{item.hour}}:{{item.minute}}</view>
  18. <view class="item-repeat">{{repeatTxT(item)}}</view>
  19. </view>
  20. <mySwitch :value="item.status" @change="onSwitchChange($event,item,idx)"></mySwitch>
  21. </view>
  22. </uni-swipe-action-item>
  23. </view>
  24. </view>
  25. <!-- #ifndef APP-PLUS || H5 -->
  26. <view class="footer-add" @click="handleAdd">新增</view>
  27. <!-- #endif -->
  28. </scroll-view>
  29. </view>
  30. </template>
  31. <script>
  32. import myEmpty from "/pages_watch/components/myEmpty/myEmpty.vue";
  33. import mySwitch from "/pages_watch/components/mySwitch/mySwitch.vue";
  34. import {getSetUpInfoByDeviceId,setClockalarm} from "@/api/pages_watch/index.js";
  35. export default {
  36. components: {
  37. myEmpty,
  38. mySwitch
  39. },
  40. data() {
  41. return {
  42. statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
  43. deviceId: "",
  44. title: "",
  45. options: [{
  46. text: '删除',
  47. style: {
  48. backgroundColor: '#dd524d'
  49. }
  50. }],
  51. clockalarmInfo: [],
  52. }
  53. },
  54. computed: {
  55. repeatTxT() {
  56. return (item)=>{
  57. if(item.repeat == false) {
  58. return '不重复'
  59. } else{
  60. let list = []
  61. const weekDays = {
  62. monday: '周一',
  63. tuesday: '周二',
  64. wednesday: '周三',
  65. thursday: '周四',
  66. friday: '周五',
  67. saturday: '周六',
  68. sunday: '周日'
  69. };
  70. Object.keys(weekDays).forEach((day) => {
  71. if (item[day]) {
  72. list.push(weekDays[day]);
  73. }
  74. });
  75. return list.join(',')
  76. }
  77. }
  78. }
  79. },
  80. onLoad(option) {
  81. this.title = option.title || ''
  82. uni.setNavigationBarTitle({
  83. title: this.title,
  84. });
  85. },
  86. onShow() {
  87. this.deviceId = uni.getStorageSync("deviceId") || ""
  88. if (this.$isLogin()) {
  89. if (this.deviceId) {
  90. this.getSetUpInfo()
  91. } else {
  92. console.log("set.vue ---- deviceId is undefined")
  93. // uni.showToast({
  94. // title: "deviceId不存在",
  95. // icon: "none"
  96. // })
  97. }
  98. } else {
  99. this.$showLoginPage()
  100. }
  101. },
  102. methods: {
  103. getSetUpInfo() {
  104. getSetUpInfoByDeviceId({
  105. deviceId: this.deviceId
  106. }).then(res => {
  107. if (res.code == 200 && res.data) {
  108. this.clockalarmInfo = res.data.alarmClock.alarmClockObjectVos || []
  109. } else {
  110. uni.showToast({
  111. title: res.msg,
  112. icon: "none"
  113. })
  114. }
  115. })
  116. },
  117. handleAdd() {
  118. if(this.clockalarmInfo&&this.clockalarmInfo.length>4) {
  119. uni.showToast({
  120. title: "最多设置5个闹钟",
  121. icon: "none"
  122. })
  123. return
  124. }
  125. // 最多设置5个闹钟
  126. uni.navigateTo({
  127. url: "/pages_watch/index/equipment/set?title=添加闹钟"
  128. })
  129. },
  130. onClick(index) {
  131. this.clockalarmInfo.splice(index,1)
  132. this.setClockalarm()
  133. },
  134. onSwitchChange(e,item,index) {
  135. item.status = e
  136. this.setClockalarm("status",index)
  137. },
  138. setClockalarm(type,index) {
  139. const param = {
  140. deviceid: uni.getStorageSync("deviceId"),
  141. alarmclock: this.clockalarmInfo
  142. }
  143. setClockalarm(param).then(res => {
  144. if (res.code != 200) {
  145. if(type=="status") {
  146. this.clockalarmInfo[index].status = !this.clockalarmInfo[index].status
  147. }
  148. uni.showToast({
  149. title: res.msg,
  150. icon: "none"
  151. })
  152. }
  153. })
  154. },
  155. editClockalarm(item,idx) {
  156. uni.navigateTo({
  157. url: "/pages_watch/index/equipment/set?title=添加闹钟&isEdit=true&index="+idx
  158. })
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. .footer-add {
  165. width: 622rpx;
  166. height: 88rpx;
  167. margin: 24rpx auto;
  168. border-radius: 88rpx;
  169. border: 2rpx solid #ECECEC;
  170. background: #FFFFFF;
  171. font-family: PingFang SC, PingFang SC;
  172. font-weight: 500;
  173. font-size: 32rpx;
  174. color: #FF7700;
  175. line-height: 88rpx;
  176. text-align: center;
  177. position: fixed;
  178. left: 50%;
  179. transform: translateX(-50%);
  180. bottom: calc(var(--window-bottom) + 24rpx);
  181. }
  182. .list {
  183. background-color: #fff;
  184. &-item {
  185. padding: 24rpx 40rpx;
  186. display: flex;
  187. align-items: center;
  188. justify-content: space-between;
  189. font-family: PingFang SC, PingFang SC;
  190. font-weight: 400;
  191. font-size: 28rpx;
  192. color: #333;
  193. &-left {
  194. flex: 1;
  195. }
  196. .item-time {
  197. font-family: DIN, DIN;
  198. font-weight: 500;
  199. font-size: 60rpx;
  200. }
  201. .item-repeat {
  202. margin-top: 10rpx;
  203. color: #999;
  204. }
  205. }
  206. }
  207. </style>