timingSetting.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <view class="timing-setting-page">
  3. <custom-card>
  4. <block slot="backText">定时设置</block>
  5. </custom-card>
  6. <view class="timing-content">
  7. <!-- 定时卡片列表 -->
  8. <view
  9. class="timer-card"
  10. v-for="(timer, index) in timerList"
  11. :key="index"
  12. >
  13. <!-- 定时标题和开关 -->
  14. <view class="timer-header">
  15. <text class="timer-title">定时{{ index + 1 }}</text>
  16. <u-switch
  17. size="40"
  18. space="4"
  19. activeColor="#0BBC58"
  20. inactiveColor="#C3CAD8"
  21. v-model="timer.enabled"
  22. @change="onSwitchChange($event, index, timer)"
  23. />
  24. </view>
  25. <!-- 单选按钮组 -->
  26. <view class="radio-group">
  27. <view
  28. class="radio-item"
  29. :class="{ active: timer.frequency === 'once' }"
  30. @click="selectFrequency(index, 'once', timer)"
  31. >
  32. <view class="radio-icon">
  33. <view v-if="timer.frequency === 'once'" class="radio-dot"></view>
  34. </view>
  35. <text class="radio-text">仅一次</text>
  36. </view>
  37. <view
  38. class="radio-item"
  39. style="margin-left: 48rpx;"
  40. :class="{ active: timer.frequency === 'daily' }"
  41. @click="selectFrequency(index, 'daily', timer)"
  42. >
  43. <view class="radio-icon">
  44. <view v-if="timer.frequency === 'daily'" class="radio-dot"></view>
  45. </view>
  46. <text class="radio-text">每天一次</text>
  47. </view>
  48. </view>
  49. <!-- 时间选择器 -->
  50. <picker
  51. mode="time"
  52. :value="timer.time"
  53. @change="onTimeChange($event, index)"
  54. >
  55. <view class="time-picker">
  56. <text class="time-text" :class="{ placeholder: !timer.time }">
  57. {{ timer.timeLabel }}
  58. </text>
  59. <u-icon name="clock" color="#999999" size="32rpx" />
  60. </view>
  61. </picker>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. export default {
  68. data() {
  69. return {
  70. devBid:'',
  71. timerList: [],
  72. };
  73. },
  74. onLoad(options) {
  75. const { devBid } = options;
  76. this.devBid = devBid;
  77. this.getTimerList();
  78. },
  79. methods: {
  80. // 编辑
  81. async editInfo(data){
  82. const params = {
  83. devBid: parseInt(this.devBid),
  84. data: data,
  85. };
  86. const resData = await this.$myRequest({
  87. url:'/api/v2/iot/device/sf/yunshang/timer/edit/',
  88. method:'POST',
  89. data: params,
  90. header: {
  91. 'Content-Type': 'application/json',
  92. 'accept': 'application/json, text/plain, */*'
  93. }
  94. })
  95. console.log(resData,'resDataresData')
  96. if(resData.code === '000000'){
  97. uni.showToast({
  98. title: '保存成功',
  99. icon: 'success',
  100. })
  101. }
  102. },
  103. async getTimerList(){
  104. const resData = await this.$myRequest({
  105. url:'/api/v2/iot/device/sf/yunshang/timer/list/',
  106. method:'POST',
  107. data: {
  108. devBid: this.devBid,
  109. },
  110. })
  111. for (let i = 0; i < resData.length; i++) {
  112. const item = resData[i];
  113. const time = item[`Timer0${i}:TimerHM`];
  114. const hour = time.slice(0, 2);
  115. const minute = time.slice(2, 4);
  116. item.enabled = item[`Timer0${i}:TimerEn`] == 1;
  117. item.frequency = item[`Timer0${i}:Mode`] == 1 ? 'daily' : 'once';
  118. item.time = hour + ':' + minute;
  119. item.timeLabel = hour + ':' + minute;
  120. }
  121. this.timerList = resData;
  122. },
  123. // 开关状态改变
  124. onSwitchChange(e, index,timer) {
  125. console.log(timer,e,'开关状态改变')
  126. this.timerList[index].enabled = e;
  127. this.editInfo({
  128. [`Timer0${index}:TimerEn`]: e ? 1 : 0,
  129. });
  130. },
  131. // 选择频率
  132. selectFrequency(index, frequency) {
  133. this.timerList[index].frequency = frequency;
  134. this.editInfo({
  135. [`Timer0${index}:Mode`]: frequency === 'daily' ? 1 : 0,
  136. });
  137. },
  138. // 时间改变
  139. onTimeChange(e, index) {
  140. console.log(e.detail.value,'时间改变')
  141. this.timerList[index].time = e.detail.value;
  142. this.timerList[index].timeLabel = e.detail.value;
  143. this.editInfo({
  144. [`Timer0${index}:TimerHM`]: e.detail.value.slice(0, 2) + e.detail.value.slice(3, 5),
  145. });
  146. },
  147. // 确认按钮
  148. handleConfirm() {
  149. const enabledTimers = this.timerList.filter((timer, index) => {
  150. if (timer.enabled) {
  151. if (!timer.time) {
  152. uni.showToast({
  153. title: `定时${index + 1}请选择时间`,
  154. icon: 'none'
  155. });
  156. return false;
  157. }
  158. return true;
  159. }
  160. return false;
  161. });
  162. console.log('保存的定时设置:', enabledTimers);
  163. uni.showToast({
  164. title: '保存成功',
  165. icon: 'success'
  166. });
  167. // TODO: 调用接口保存定时设置
  168. },
  169. },
  170. };
  171. </script>
  172. <style scoped lang="scss">
  173. uni-page-body {
  174. position: relative;
  175. height: 100%;
  176. overflow-y: auto;
  177. }
  178. .timing-setting-page {
  179. min-height: 100%;
  180. background: linear-gradient(180deg, #f5f6fa00 0%, #F5F6FA 23.64%, #F5F6FA 100%), linear-gradient(102deg, #BFEADD 6.77%, #B8F1E7 40.15%, #B9EEF5 84.02%);
  181. overflow-x: hidden;
  182. overflow-y: auto;
  183. .right-icons {
  184. display: flex;
  185. align-items: center;
  186. }
  187. .timing-content {
  188. height: 100%;
  189. padding: 24rpx 32rpx;
  190. overflow-y: auto;
  191. }
  192. // 定时卡片
  193. .timer-card {
  194. background: #ffffff;
  195. border-radius: 12rpx;
  196. padding: 24rpx;
  197. margin-bottom: 20rpx;
  198. // 卡片头部
  199. .timer-header {
  200. display: flex;
  201. justify-content: space-between;
  202. align-items: center;
  203. margin-bottom: 24rpx;
  204. .timer-title {
  205. font-size: 32rpx;
  206. font-weight: 600;
  207. color: #333333;
  208. font-family: 'Source Han Sans CN';
  209. }
  210. .timer-switch {
  211. transform: scale(0.9);
  212. }
  213. }
  214. // 单选按钮组
  215. .radio-group {
  216. display: flex;
  217. margin-bottom: 24rpx;
  218. .radio-item {
  219. display: flex;
  220. align-items: center;
  221. margin-right: 48rpx;
  222. cursor: pointer;
  223. .radio-icon {
  224. width: 36rpx;
  225. height: 36rpx;
  226. border: 4rpx solid #cccccc;
  227. border-radius: 50%;
  228. display: flex;
  229. align-items: center;
  230. justify-content: center;
  231. margin-right: 12rpx;
  232. box-sizing: border-box;
  233. .radio-dot {
  234. width: 18rpx;
  235. height: 18rpx;
  236. background: #00c853;
  237. border-radius: 50%;
  238. }
  239. }
  240. &.active {
  241. .radio-icon {
  242. border-color: #00c853;
  243. }
  244. .radio-text {
  245. color: #333333;
  246. }
  247. }
  248. .radio-text {
  249. font-size: 28rpx;
  250. color: #999999;
  251. font-family: 'Source Han Sans CN';
  252. }
  253. }
  254. }
  255. // 时间选择器
  256. .time-picker {
  257. display: flex;
  258. justify-content: space-between;
  259. align-items: center;
  260. padding: 10rpx 24rpx;
  261. background: #F5F6FA;
  262. border-radius: 8rpx;
  263. .time-text {
  264. font-size: 28rpx;
  265. color: #333333;
  266. font-family: 'Source Han Sans CN';
  267. &.placeholder {
  268. color: #999999;
  269. }
  270. }
  271. }
  272. }
  273. }
  274. </style>