control.vue 9.9 KB

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