control.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 64px;">
  5. <view style="position: fixed;z-index: 100;width: 100%;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="设备控制"></uni-nav-bar>
  7. </view>
  8. <view class="control">
  9. <view class="control_restart" v-if="myuser_type">
  10. <p class="title_p">管理员操作</p>
  11. <view class="control_restart_but">
  12. <button @click="restart">重启</button>
  13. <button @click="upgrade">升级</button>
  14. </view>
  15. </view>
  16. <view class="control_off">
  17. <p class="title_p">设备开关</p>
  18. <view class="control_off_off">
  19. <p>{{condatas.ds == 1? "开机":"关机"}}</p>
  20. <u-switch v-model="checked1" size="30" style="margin-top: 14rpx;" active-color="#58C876" @change="checkedTF"></u-switch>
  21. </view>
  22. </view>
  23. <view class="control_mo">
  24. <p class="title_p">定时模式</p>
  25. <view class="control_off_off" @click="show1 = !show1">
  26. <p>{{condatas.timctrl==1 ? "时控":"光控"}}</p>
  27. <u-icon name="arrow-down-fill" size="12" color="#7F8082"></u-icon>
  28. </view>
  29. <u-action-sheet :list="options1" v-model="show1" @click="actionSheetCallback"></u-action-sheet>
  30. </view>
  31. <view class="control_time" v-if="condatas.timctrl== 0">
  32. <p class="title_p">定时时长(h)</p>
  33. <view class="control_off_off" @click="show2 = !show2">
  34. <p>{{condatas.tt==0?'常亮':condatas.tt}}</p>
  35. <u-icon name="arrow-down-fill" size="12" color="#7F8082"></u-icon>
  36. </view>
  37. </view>
  38. <view class="control_time" v-else>
  39. <p class="title_p">开始结束时间</p>
  40. <view class="control_off_off" @click="show3 = !show3">
  41. <p>开始时间:{{condatas.st}}:00</p>
  42. <u-picker v-model="show3" mode="time" :params="params" @confirm="confirmFun"></u-picker>
  43. <u-icon name="arrow-down-fill" size="12" color="#7F8082"></u-icon>
  44. </view>
  45. <view class="control_off_off" @click="show4 = !show4">
  46. <p>结束时间:{{condatas.et}}:00</p>
  47. <u-picker v-model="show4" mode="time" :params="params" @confirm="confirmFun2"></u-picker>
  48. <u-icon name="arrow-down-fill" size="12" color="#7F8082"></u-icon>
  49. </view>
  50. </view>
  51. <view class="control_interval">
  52. <p class="title_p">上传时间间隔(min)</p>
  53. <view class="slider">
  54. <view class="" style="width: 90%;padding-top: 18rpx;">
  55. <u-slider v-model="condatas.dattim" min="0" max="100" step="1" active-color="#58C876"></u-slider>
  56. </view>
  57. <view class="" style="width: 10%;text-align: center;">
  58. {{condatas.dattim || 0}}
  59. </view>
  60. </view>
  61. </view>
  62. <view class="control_timing">
  63. <p class="title_p">自清虫定时(min)</p>
  64. <view class="slider">
  65. <view class="" style="width: 90%;padding-top: 18rpx;">
  66. <u-slider v-model="condatas.clt" min="0" max="100" step="1" active-color="#58C876"></u-slider>
  67. </view>
  68. <view class="" style="width: 10%;text-align: center;">
  69. {{condatas.clt || 0}}
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="ensure">
  76. <view class="ensure_btn" @click="ensure">
  77. 确 定
  78. </view>
  79. </view>
  80. <u-popup v-model="show2" mode="bottom" length="30%" class="pop-up">
  81. <scroll-view scroll-y="true" class="sheet">
  82. <view class="sheet-text" v-for="(item,index) in options2" :key="index">
  83. <p @click="typesofroles(index)">{{item.text}}</p>
  84. </view>
  85. </scroll-view>
  86. <button @click="show2 = false">取消</button>
  87. </u-popup>
  88. </view>
  89. </template>
  90. <script>
  91. export default {
  92. data() {
  93. return {
  94. condatas: {},
  95. checked1: false,
  96. show1: false,
  97. show2: false,
  98. show3: false,
  99. show4: false,
  100. options1: [{
  101. text: '光控'
  102. },
  103. {
  104. text: '时控'
  105. }
  106. ],
  107. options2: [{
  108. text: '常亮'
  109. },
  110. {
  111. text: '1'
  112. },
  113. {
  114. text: '2'
  115. },
  116. {
  117. text: '3'
  118. },
  119. {
  120. text: '4'
  121. },
  122. {
  123. text: '5'
  124. },
  125. {
  126. text: '6'
  127. },
  128. {
  129. text: '7'
  130. },
  131. {
  132. text: '8'
  133. },
  134. {
  135. text: '9'
  136. },
  137. {
  138. text: '10'
  139. },
  140. {
  141. text: '00'
  142. }
  143. ],
  144. params: {
  145. year: false,
  146. month: false,
  147. day: false,
  148. hour: true,
  149. minute: false,
  150. second: false
  151. },
  152. myuser_type:false
  153. }
  154. },
  155. methods: { //forecast.send_control.device_control_info
  156. async controldata(data) { //设备列表
  157. const res = await this.$myRequest({
  158. url: '/api/api_gateway?method=forecast.send_control.device_control_info',
  159. data: {
  160. d_id: data,
  161. cmd: 'paramconf'
  162. }
  163. })
  164. console.log(res)
  165. this.condatas = res
  166. if (this.condatas.ds == 1) {
  167. this.checked1 = true
  168. } else {
  169. this.checked1 = false
  170. }
  171. },
  172. //forecast.send_control.admin_device_control
  173. async reorup(data) { //设备列表
  174. const res = await this.$myRequest({
  175. url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
  176. data: {
  177. d_id: data.d_id,
  178. device_type_id: 2,
  179. cmd: data.cmd
  180. }
  181. })
  182. if (res == true) {
  183. uni.showToast({
  184. title: '指令下发成功!'
  185. });
  186. } else {
  187. uni.showToast({
  188. title: '指令下发失败!'
  189. });
  190. }
  191. },
  192. //forecast.send_control.device_control
  193. async controlby(data) { //设备列表
  194. const res = await this.$myRequest({
  195. url: '/api/api_gateway?method=forecast.send_control.device_control',
  196. data: {
  197. d_id: this.d_id,
  198. device_type_id: 2,
  199. config: data
  200. }
  201. })
  202. },
  203. clickLeft() {
  204. uni.navigateBack({
  205. delta: 1
  206. })
  207. },
  208. typesofroles(index) {
  209. this.condatas.tt = index
  210. this.show2 = false
  211. },
  212. actionSheetCallback(index) {
  213. this.condatas.timctrl = index
  214. },
  215. checkedTF(e) { //设备开关
  216. if (e == true) {
  217. this.condatas.ds = 1
  218. } else {
  219. this.condatas.ds = 0
  220. }
  221. },
  222. confirmFun(e) { //开始时间
  223. this.condatas.st = Number(e.hour)
  224. },
  225. confirmFun2(e) { //结束时间
  226. this.condatas.et = Number(e.hour)
  227. },
  228. restart() { //重启
  229. let obj = {
  230. d_id: this.d_id,
  231. cmd: 'reboot'
  232. }
  233. this.reorup(obj)
  234. },
  235. upgrade() { //升级
  236. let obj = {
  237. d_id: this.d_id,
  238. cmd: 'update'
  239. }
  240. this.reorup(obj)
  241. },
  242. ensure() {
  243. let str = JSON.stringify(this.condatas)
  244. console.log(str)
  245. this.controlby(str)
  246. this.clickLeft()
  247. }
  248. },
  249. onLoad(option) {
  250. this.$forceUpdate()
  251. this.controldata(option.id)
  252. this.d_id = option.id
  253. uni.getStorage({
  254. key: "myuser_type",
  255. success: (res) => {
  256. if (Number(res.data) == 1) {
  257. this.myuser_type = true
  258. }
  259. }
  260. })
  261. }
  262. }
  263. </script>
  264. <style lang="scss">
  265. .control {
  266. position: absolute;
  267. top: 50px;
  268. width: 90%;
  269. left: 5%;
  270. .title_p {
  271. padding-left: 20rpx;
  272. border-left: 6rpx solid #28AE4F;
  273. height: 40rpx;
  274. margin-bottom: 20rpx;
  275. }
  276. .control_off_off {
  277. display: flex;
  278. justify-content: space-between;
  279. margin-left: 24rpx;
  280. padding: 0 30rpx;
  281. background-color: #F7F8FA;
  282. height: 60rpx;
  283. line-height: 60rpx;
  284. margin-bottom: 20rpx;
  285. }
  286. .slider {
  287. display: flex;
  288. padding: 0 30rpx 0 0;
  289. margin-left: 24rpx;
  290. margin-bottom: 20rpx;
  291. }
  292. .control_restart {
  293. margin-bottom: 20rpx;
  294. .title_p {
  295. border-left: 6rpx solid #D17978;
  296. }
  297. .control_restart_but {
  298. display: flex;
  299. justify-content: flex-start;
  300. margin-left: 24rpx;
  301. button {
  302. width: 110rpx;
  303. height: 50rpx;
  304. line-height: 50rpx;
  305. font-size: 26rpx;
  306. margin: 0 20rpx 0 0;
  307. color: #FFFFFF;
  308. background-color: #D17978;
  309. }
  310. }
  311. }
  312. .control_off {}
  313. }
  314. .pop-up {
  315. .sheet {
  316. background-color: white;
  317. height: 400rpx;
  318. overflow: hidden;
  319. .sheet-text {
  320. height: 80rpx;
  321. border-bottom: 2rpx solid #F7F8FA;
  322. p {
  323. text-align: center;
  324. height: 80rpx;
  325. line-height: 80rpx;
  326. color: black;
  327. font-size: 16px;
  328. }
  329. }
  330. }
  331. button {
  332. color: black;
  333. position: absolute;
  334. bottom: 0;
  335. width: 100%;
  336. font-size: 16px;
  337. height: 80rpx;
  338. }
  339. }
  340. .ensure {
  341. width: 100%;
  342. position: absolute;
  343. bottom: 100rpx;
  344. .ensure_btn {
  345. width: 90%;
  346. margin: 0 auto;
  347. height: 60rpx;
  348. line-height: 60rpx;
  349. text-align: center;
  350. background-color: #28AE4F;
  351. color: #FFFFFF;
  352. border-radius: 30rpx;
  353. }
  354. }
  355. </style>