control.vue 12 KB

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