control.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 40px;">
  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-if="condatas.timctrl == 1">
  39. <p class="title_p">开始结束时间</p>
  40. <view class="control_off_off" @click="show3 = !show3">
  41. <p>开始时间:{{condatas.st?condatas.st:"00"}}: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?condatas.et:"00"}}: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: 100%;padding-top: 18rpx;">
  55. <slider value="0" v-model="condatas.dat_f" min="0" max="120" step="1" show-value block-size="18" activeColor="#57C878" @changing="changing"></slider>
  56. </view>
  57. </view>
  58. </view>
  59. <view class="control_timing">
  60. <p class="title_p">自清虫定时(min)</p>
  61. <view class="slider">
  62. <view class="" style="width: 100%;padding-top: 18rpx;">
  63. <slider value="0" v-model="condatas.clt_t" min="0" max="120" step="1" show-value block-size="18" activeColor="#57C878" @changing="changing2"></slider>
  64. </view>
  65. </view>
  66. <view class="qingchong" v-if="allqingchong">
  67. <view class="qingchongbox" @click="suzumusi">
  68. 清 虫
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <view class="ensure">
  75. <view class="ensure_btn" @click="ensure">
  76. 确 定
  77. </view>
  78. </view>
  79. <u-popup v-model="show2" mode="bottom" length="30%" class="pop-up">
  80. <scroll-view scroll-y="true" class="sheet">
  81. <view class="sheet-text" v-for="(item,index) in options2" :key="index">
  82. <p @click="typesofroles(index)">{{item.text}}</p>
  83. </view>
  84. </scroll-view>
  85. <button @click="show2 = false">取消</button>
  86. </u-popup>
  87. </view>
  88. </template>
  89. <script>
  90. export default {
  91. data() {
  92. return {
  93. myuid:"",
  94. condatas: {
  95. clt:0,
  96. dattim:0
  97. },
  98. checked1: false,
  99. show1: false,
  100. show2: false,
  101. show3: false,
  102. show4: false,
  103. options1: [{
  104. text: '光控'
  105. },
  106. {
  107. text: '时控'
  108. }
  109. ],
  110. options2: [{
  111. text: '常亮'
  112. },
  113. {
  114. text: '1'
  115. },
  116. {
  117. text: '2'
  118. },
  119. {
  120. text: '3'
  121. },
  122. {
  123. text: '4'
  124. },
  125. {
  126. text: '5'
  127. },
  128. {
  129. text: '6'
  130. },
  131. {
  132. text: '7'
  133. },
  134. {
  135. text: '8'
  136. },
  137. {
  138. text: '9'
  139. },
  140. {
  141. text: '10'
  142. },
  143. {
  144. text: '00'
  145. }
  146. ],
  147. params: {
  148. year: false,
  149. month: false,
  150. day: false,
  151. hour: true,
  152. minute: false,
  153. second: false
  154. },
  155. myuser_type:false,
  156. allqingchong:false
  157. }
  158. },
  159. methods: { //forecast.send_control.device_control_info
  160. async controldata(data) { //设备列表
  161. const res = await this.$myRequest({
  162. url: '/api/api_gateway?method=forecast.send_control.device_control_info',
  163. data: {
  164. d_id: data,
  165. cmd: 'paramconf'
  166. }
  167. })
  168. console.log(res)
  169. this.condatas = res
  170. this.condatas.timctrl = Number(res.ts)
  171. if (this.condatas.ds == 1) {
  172. this.checked1 = true
  173. } else {
  174. this.checked1 = false
  175. }
  176. },
  177. //forecast.send_control.admin_device_control
  178. async reorup(data) { //设备列表
  179. const res = await this.$myRequest({
  180. url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
  181. data: {
  182. d_id: data.d_id,
  183. device_type_id: 2,
  184. cmd: data.cmd
  185. }
  186. })
  187. if (res == true) {
  188. uni.showToast({
  189. title: '指令下发成功!'
  190. });
  191. } else {
  192. uni.showToast({
  193. title: '指令下发失败!'
  194. });
  195. }
  196. },
  197. //forecast.send_control.device_control
  198. async controlby(data) { //设备列表
  199. const res = await this.$myRequest({
  200. url: '/api/api_gateway?method=forecast.send_control.device_control',
  201. data: {
  202. d_id: this.d_id,
  203. device_type_id: 2,
  204. config: data
  205. }
  206. })
  207. },
  208. clickLeft() {
  209. uni.navigateBack({
  210. delta: 1
  211. })
  212. },
  213. typesofroles(index) {
  214. this.condatas.tt = index
  215. this.show2 = false
  216. },
  217. actionSheetCallback(index) {
  218. this.condatas.timctrl = index
  219. },
  220. checkedTF(e) { //设备开关
  221. if (e == true) {
  222. this.condatas.ds = 1
  223. } else {
  224. this.condatas.ds = 0
  225. }
  226. },
  227. confirmFun(e) { //开始时间
  228. this.condatas.st = Number(e.hour)
  229. },
  230. confirmFun2(e) { //结束时间
  231. this.condatas.et = Number(e.hour)
  232. },
  233. restart() { //重启
  234. let obj = {
  235. d_id: this.d_id,
  236. cmd: 'reboot'
  237. }
  238. this.reorup(obj)
  239. },
  240. upgrade() { //升级
  241. let obj = {
  242. d_id: this.d_id,
  243. cmd: 'update'
  244. }
  245. this.reorup(obj)
  246. },
  247. ensure() {
  248. console.log(this.condatas)
  249. var obj = {}
  250. for(var key in this.condatas){
  251. if(key == "dat_f"){
  252. obj["dattim"] = this.condatas[key]
  253. }else if(key == "clt_t"){
  254. obj["clt"] = this.condatas[key]
  255. }else{
  256. obj[key] = this.condatas[key]
  257. }
  258. }
  259. let str = JSON.stringify(obj)
  260. this.controlby(str)
  261. this.clickLeft()
  262. },
  263. async getworm() {
  264. const res = await this.$myRequest({
  265. url: '/api/api_gateway?method=forecast.send_control.clear_insects_permission',
  266. data: {}
  267. })
  268. console.log(res)
  269. this.allqingchong = res[0] == 1 ? true : false;
  270. },
  271. async suzumusi(){
  272. const res = await this.$myRequest({
  273. url: '/api/api_gateway?method=forecast.send_control.device_control',
  274. data: {
  275. config: '{"cmd":"ctr_clear"}',
  276. d_id: this.d_id,
  277. device_type_id: "2",
  278. req: "ctr_clear",
  279. }
  280. })
  281. // console.log(res)
  282. if (res == true) {
  283. uni.showToast({
  284. title: '指令下发成功!'
  285. });
  286. } else {
  287. uni.showToast({
  288. title: '指令下发失败!'
  289. });
  290. }
  291. },
  292. changing(e){
  293. // console.log(e.detail.value)
  294. this.condatas.dat_f = e.detail.value
  295. },
  296. changing2(e){
  297. // console.log(e.detail.value)
  298. this.condatas.clt_t = e.detail.value
  299. },
  300. },
  301. onLoad(option) {
  302. this.$forceUpdate()
  303. this.getworm()
  304. this.controldata(option.id)
  305. this.d_id = option.id
  306. uni.getStorage({
  307. key: "myuid",
  308. success: (res) => {
  309. this.myuid = res.data
  310. }
  311. })
  312. uni.getStorage({
  313. key: "myuser_type",
  314. success: (res) => {
  315. if (Number(res.data) == 1) {
  316. this.myuser_type = true
  317. }
  318. }
  319. })
  320. }
  321. }
  322. </script>
  323. <style lang="scss">
  324. .control {
  325. position: absolute;
  326. top: 50px;
  327. width: 90%;
  328. left: 5%;
  329. .title_p {
  330. padding-left: 20rpx;
  331. border-left: 6rpx solid #28AE4F;
  332. height: 40rpx;
  333. margin-bottom: 20rpx;
  334. }
  335. .control_off_off {
  336. display: flex;
  337. justify-content: space-between;
  338. margin-left: 24rpx;
  339. padding: 0 30rpx;
  340. background-color: #F7F8FA;
  341. height: 60rpx;
  342. line-height: 60rpx;
  343. margin-bottom: 20rpx;
  344. }
  345. .slider {
  346. display: flex;
  347. padding: 0 30rpx 0 0;
  348. margin-left: 24rpx;
  349. margin-bottom: 20rpx;
  350. /deep/uni-slider{
  351. margin: 0 !important;
  352. }
  353. }
  354. .control_restart {
  355. margin-bottom: 20rpx;
  356. .title_p {
  357. border-left: 6rpx solid #D17978;
  358. }
  359. .control_restart_but {
  360. display: flex;
  361. justify-content: flex-start;
  362. margin-left: 24rpx;
  363. button {
  364. width: 110rpx;
  365. height: 50rpx;
  366. line-height: 50rpx;
  367. font-size: 26rpx;
  368. margin: 0 20rpx 0 0;
  369. color: #FFFFFF;
  370. background-color: #D17978;
  371. }
  372. }
  373. }
  374. .control_off {}
  375. }
  376. .pop-up {
  377. .sheet {
  378. background-color: white;
  379. height: 400rpx;
  380. overflow: hidden;
  381. .sheet-text {
  382. height: 80rpx;
  383. border-bottom: 2rpx solid #F7F8FA;
  384. p {
  385. text-align: center;
  386. height: 80rpx;
  387. line-height: 80rpx;
  388. color: black;
  389. font-size: 16px;
  390. }
  391. }
  392. }
  393. button {
  394. color: black;
  395. position: absolute;
  396. bottom: 0;
  397. width: 100%;
  398. font-size: 16px;
  399. height: 80rpx;
  400. }
  401. }
  402. .ensure {
  403. width: 100%;
  404. position: absolute;
  405. bottom: 100rpx;
  406. .ensure_btn {
  407. width: 90%;
  408. margin: 0 auto;
  409. height: 60rpx;
  410. line-height: 60rpx;
  411. text-align: center;
  412. background-color: #28AE4F;
  413. color: #FFFFFF;
  414. border-radius: 30rpx;
  415. }
  416. }
  417. .qingchong{
  418. width: 90%;
  419. margin: 10px auto;
  420. text-align: right;
  421. display: flex;
  422. justify-content: flex-end;
  423. .qingchongbox{
  424. padding: 2px 8px 3px 8px;
  425. background-color: #28AE4F;
  426. color: #fff;
  427. border-radius: 5px;
  428. // line-height: 27px;
  429. }
  430. }
  431. </style>