timing.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view style="padding: 10px;">
  3. <u--form>
  4. <text class="u-demo-block__title">执行周期</text>
  5. <u-form-item>
  6. <view style="padding: 10px;">
  7. <checkbox-group @change="checkboxChange">
  8. <label v-for="item in checkboxList" :key="item.value">
  9. <view>
  10. <u-row style="width: 90px;margin-bottom: 5px;">
  11. <u-col span="4">
  12. <checkbox :value="item.value" :checked="item.checked" />
  13. </u-col>
  14. <u-col span="8">
  15. <view>{{item.value}}</view>
  16. </u-col>
  17. </u-row>
  18. </view>
  19. </label>
  20. </checkbox-group>
  21. </view>
  22. </u-form-item>
  23. <text class="u-demo-block__title">开启/停止 时间</text>
  24. <view style="padding: 10px;">
  25. <view style="padding: 15px; border-bottom: 1px solid #d6d6d6;">
  26. <picker mode="time" :value="form.startTime" @change="bindTimeChangeStart">
  27. <text class="tit" style="font-size: 14px; color: #787878; margin-right:50upx;">开启时间</text>
  28. <text class="uni-input" v-if="form.startTime" style="width:320upx;">{{form.startTime}}</text>
  29. <text class="uni-input grey" v-else>请选择开启时间</text>
  30. </picker>
  31. </view>
  32. <view style="padding: 15px; border-bottom: 1px solid #d6d6d6;">
  33. <picker mode="time" :value="form.endTime" @change="bindTimeChangeEnd">
  34. <text style="font-size: 14px; color: #787878; margin-right:50upx;">停止时间</text>
  35. <text class="uni-input" v-if="form.endTime" style="width:520upx;">{{form.endTime}}</text>
  36. <text class="uni-input grey" v-else>请选择停止时间</text>
  37. </picker>
  38. </view>
  39. </view>
  40. </u--form>
  41. <view class="uni-list">
  42. </view>
  43. <view style="margin: 30px;">
  44. <u-button color="#26a495" text="提交" @click="submit()"></u-button>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. show: false,
  53. showBirthday: false,
  54. time: '13:00',
  55. timeType: 0,
  56. timeValue: '',
  57. data: [],
  58. //横向排列形式数据
  59. checkboxList: [{
  60. value: '星期日',
  61. checked: false
  62. }, {
  63. value: '星期一',
  64. checked: false
  65. }, {
  66. value: '星期二',
  67. checked: false
  68. }, {
  69. value: '星期三',
  70. checked: false
  71. }, {
  72. value: '星期四',
  73. checked: false
  74. }, {
  75. value: '星期五',
  76. checked: false
  77. },
  78. {
  79. value: '星期六',
  80. checked: false
  81. }
  82. ],
  83. form: {
  84. cycle: [],
  85. useNoId: 0,
  86. startTime: null,
  87. endTime: null
  88. }
  89. }
  90. },
  91. onLoad() {
  92. this.form.useNoId = uni.getStorageSync("deviceInfo").deviceUseNo
  93. this.getTimingInfo()
  94. },
  95. methods: {
  96. bindTimeChangeStart: function(e) {
  97. this.form.startTime = e.target.value + ":00"
  98. },
  99. bindTimeChangeEnd: function(e) {
  100. this.form.endTime = e.target.value + ":00"
  101. },
  102. checkboxChange: function(e) {
  103. var items = this.checkboxList,
  104. values = e.detail.value;
  105. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  106. const item = items[i]
  107. if (values.includes(item.value)) {
  108. this.$set(item, 'checked', true)
  109. } else {
  110. this.$set(item, 'checked', false)
  111. }
  112. }
  113. },
  114. openUseNo() {
  115. this.show = true
  116. },
  117. confirm(e) {
  118. //console.log('confirm', e)
  119. this.orgInfo = e.value[0];
  120. this.show = false
  121. },
  122. cancel() {
  123. uni.showTabBar({
  124. animation: true
  125. })
  126. this.show = false
  127. },
  128. submit() {
  129. let st = this.form.startTime
  130. let et = this.form.endTime
  131. st = st.split(":")
  132. et = et.split(":")
  133. if (st[0] === et[0]) {
  134. var cz = parseInt(et[1]) - parseInt(st[1])
  135. if(cz < 5){
  136. uni.showToast({
  137. icon:"none",
  138. duration: 2500,
  139. title: "间隔时间必须大于5分钟",
  140. });
  141. return;
  142. }
  143. }
  144. var cycle = []
  145. this.checkboxList.forEach((c, i) => {
  146. if (c.checked === true) {
  147. cycle.push(i)
  148. }
  149. })
  150. this.form.cycle = cycle + ''
  151. this.submitTiming()
  152. },
  153. async submitTiming() {
  154. const {
  155. data: res
  156. } = await this.$httpRequest({
  157. url: '/api/control/timing',
  158. method: 'put',
  159. data: this.form,
  160. isNotErrorMsg: true
  161. });
  162. if (res.code === 200) {
  163. var data = res.data
  164. uni.showToast({
  165. duration: 1000,
  166. title: "保存成功",
  167. });
  168. } else {
  169. }
  170. },
  171. async getTimingInfo() {
  172. const {
  173. data: res
  174. } = await this.$httpRequest({
  175. url: '/api/control/timing?' + "useNoId=" + this.form.useNoId,
  176. method: 'get',
  177. isNotErrorMsg: true
  178. });
  179. if (res.code === 200) {
  180. var data = res.data
  181. console.log(data)
  182. this.form.startTime = data.startTime
  183. this.form.endTime = data.endTime
  184. data.cycle.split(",").forEach((c, i) => {
  185. this.checkboxList[c].checked = true
  186. })
  187. } else {
  188. }
  189. },
  190. hideKeyboard() {
  191. uni.hideKeyboard()
  192. },
  193. result(time, mode) {
  194. const timeFormat = uni.$u.timeFormat,
  195. toast = uni.$u.toast
  196. switch (mode) {
  197. case 'datetime':
  198. return toast(timeFormat(time, 'yyyy-mm-dd hh:MM'))
  199. case 'date':
  200. return toast(timeFormat(time, 'yyyy-mm-dd'))
  201. case 'year-month':
  202. return toast(timeFormat(time, 'yyyy-mm'))
  203. case 'time':
  204. return toast(time)
  205. default:
  206. return ''
  207. }
  208. },
  209. }
  210. }
  211. </script>
  212. <style>
  213. </style>