control.vue 7.9 KB

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