equip-set.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view>
  3. <view class="" v-if="myuser_type">
  4. <view class="tit adminTit">
  5. 操作
  6. </view>
  7. <view class="btns">
  8. <button type="warn" @click="equipBtnControl('update')" size="mini">升级</button>
  9. <button type="warn" @click="equipBtnControl('reboot')" size="mini">重启</button>
  10. <button type="warn" @click="equipBtnControl('clearworm')" size="mini">清网</button>
  11. </view>
  12. <view class="tit adminTit">
  13. 设备开关
  14. </view>
  15. <view class="uni-list-cell" @click="cell">
  16. <text class="uni-input">{{equipContrlForm1.ds=="0"?'关机':'开机'}}</text>
  17. <view class="arrow"></view>
  18. <u-select v-model="ds_show" mode="single-column" :list="ds_list" @confirm="confirm($event,'ds')"></u-select>
  19. </view>
  20. <view class="tit adminTit">
  21. 时控开关
  22. </view>
  23. <view class="uni-list-cell" @click="shicell">
  24. <text class="uni-input">{{equipContrlForm1.timctrl=="0"?'关':'开'}}</text>
  25. <view class="arrow"></view>
  26. <u-select v-model="timctrl_show" mode="single-column" :list="timctrl_list" @confirm="confirm($event,'timctrl')"></u-select>
  27. </view>
  28. </view>
  29. <view class="" v-if="Number(equipContrlForm1.timctrl)">
  30. <view class="tit">
  31. 时控时长
  32. </view>
  33. <view class="selectTime">
  34. <view class="uni-list-cell time" @click="selectTime('st')">
  35. <text>{{time.time1||'开始时间'}}</text>
  36. <u-icon name="clock"></u-icon>
  37. </view>
  38. <text class="line">-</text>
  39. <view class="uni-list-cell time" @click="selectTime('et')">
  40. <text>{{time.time2||'结束时间'}}</text>
  41. <u-icon name="clock"></u-icon>
  42. </view>
  43. <u-select v-model="timeShow" mode="single-column" :list="timeList" @confirm="timeConfirm($event,timeType)"></u-select>
  44. </view>
  45. </view>
  46. <view class="tit">
  47. 数据频率(min)
  48. </view>
  49. <view class="">
  50. <slider :value="equipContrlForm1.dat_f" show-value="true" :min="10" :max="60" @change="sliderChange" block-color="#57C878"
  51. activeColor="#57C878" step="1" />
  52. </view>
  53. <view class="submit-box">
  54. <u-button @click="submit" type="success">确定</u-button>
  55. </view>
  56. <u-toast ref="toast" />
  57. </view>
  58. </template>
  59. <script>
  60. export default {
  61. data() {
  62. return {
  63. d_id: '',
  64. equipContrlForm1: {
  65. st: '', //时控开始时间
  66. et: '', //时控结束时间
  67. dat_f: 10, //数据上传时间间隔
  68. ds: '', //开关,1开机,0关机
  69. timctrl: '' //时控开关 1开,0关
  70. },
  71. time: {
  72. time1: '',
  73. time2: ''
  74. },
  75. ds_list: [{
  76. value: 0,
  77. label: '关机'
  78. }, {
  79. value: 1,
  80. label: '开机'
  81. }],
  82. ds_show: false,
  83. timctrl_list: [{
  84. value: 0,
  85. label: '关'
  86. }, {
  87. value: 1,
  88. label: '开'
  89. }],
  90. timctrl_show: false,
  91. timeList: [],
  92. timeShow: false,
  93. timeType: '',
  94. myuser_type: false
  95. }
  96. },
  97. onLoad(option) {
  98. this.d_id = option.d_id
  99. this.equipSet()
  100. uni.getStorage({
  101. key: "myuser_type",
  102. success: (res) => {
  103. if (Number(res.data) == 1) {
  104. this.myuser_type = true
  105. }
  106. }
  107. })
  108. },
  109. methods: {
  110. //回显设备控制参数
  111. async equipSet() {
  112. let res = await this.$myRequest({
  113. url: '/api/api_gateway?method=forecast.send_control.device_control_info',
  114. data: {
  115. d_id: this.d_id,
  116. cmd: "paramconf"
  117. }
  118. })
  119. console.log(res)
  120. let obj = {
  121. st: res.work_tim.st,
  122. et: res.work_tim.et,
  123. timctrl: res.work_tim.timctrl,
  124. ds: res.power.ds,
  125. dat_f: res.data_tim.dat_f,
  126. };
  127. this.equipContrlForm1 = obj
  128. this.time.time1 = obj.st && obj.st < 10 ? "0" + obj.st + ":00" : obj.st + ":00";
  129. this.time.time2 = obj.et && obj.et < 10 ? "0" + obj.et + ":00" : obj.et + ":00";
  130. },
  131. async equipBtnControl(cmd) {
  132. let res = await this.$myRequest({
  133. url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
  134. data: {
  135. cmd,
  136. device_type_id: 4,
  137. d_id: this.d_id
  138. }
  139. })
  140. if (res) {
  141. this.$refs.toast.show({
  142. title: '指令下发成功!',
  143. type: 'success',
  144. })
  145. }
  146. },
  147. sliderChange(e) {
  148. this.equipContrlForm1.dat_f = e.detail.value
  149. },
  150. selectTime(a) {
  151. this.timeType = a
  152. if (this.timeList.length == 0) {
  153. let arr = []
  154. for (let i = 0; i < 24; i++) {
  155. let label = i < 10 ? `0${i}:00` : `${i}:00`
  156. arr.push({
  157. value: i,
  158. label
  159. })
  160. }
  161. arr.unshift({
  162. value: '',
  163. label: '重置'
  164. })
  165. this.timeList = arr
  166. }
  167. this.timeShow = true
  168. },
  169. confirm(e, a) {
  170. console.log(e)
  171. if (a == 'ds') {
  172. this.equipContrlForm1.ds = e[0].value
  173. } else if (a == 'timctrl') {
  174. this.equipContrlForm1.timctrl = e[0].value
  175. }
  176. },
  177. timeConfirm(e, a) {
  178. if (a == 'st') {
  179. this.time.time1 = e[0].label
  180. this.equipContrlForm1.st = e[0].value
  181. } else {
  182. this.time.time2 = e[0].label
  183. this.equipContrlForm1.et = e[0].value
  184. }
  185. },
  186. cell() { //设备开关
  187. this.ds_show = true
  188. },
  189. shicell() {
  190. this.timctrl_show=true
  191. },
  192. async submit() {
  193. console.log(this.equipContrlForm1)
  194. let obj = {
  195. work_tim: {
  196. timctrl: this.equipContrlForm1.timctrl,
  197. st: this.equipContrlForm1.st,
  198. et: this.equipContrlForm1.et,
  199. },
  200. data_tim: {
  201. dat_f: this.equipContrlForm1.dat_f
  202. },
  203. power: {
  204. ds: this.equipContrlForm1.ds
  205. },
  206. };
  207. let res = await this.$myRequest({
  208. url: '/api/api_gateway?method=forecast.send_control.device_control',
  209. data: {
  210. device_type_id: 4,
  211. d_id: this.d_id,
  212. config: JSON.stringify(obj),
  213. }
  214. })
  215. if(res === true){
  216. this.$refs.toast.show({
  217. title: '指令下发成功',
  218. type: 'success',
  219. callback:function(){
  220. uni.navigateBack({
  221. delta: 1
  222. });
  223. }
  224. })
  225. } else {
  226. this.$refs.toast.show({
  227. title: '服务出错了',
  228. type: 'error'
  229. })
  230. }
  231. // if (res) {
  232. // this.$refs.toast.show({
  233. // title: '指令下发成功',
  234. // type: 'success',
  235. // callback: function() {
  236. // uni.navigateBack({
  237. // delta: 1
  238. // });
  239. // }
  240. // })
  241. // }
  242. }
  243. }
  244. }
  245. </script>
  246. <style lang="scss">
  247. page {
  248. padding: 20rpx;
  249. box-sizing: border-box;
  250. .tit {
  251. line-height: 30rpx;
  252. font-size: 30rpx;
  253. padding-left: 20rpx;
  254. border-left-width: 2px;
  255. border-left-style: solid;
  256. border-left-color: $uni-color-success;
  257. margin: 30rpx 0;
  258. }
  259. .adminTit {
  260. border-left-color: #e64340;
  261. }
  262. .btns {
  263. display: flex;
  264. justify-content: flex-start;
  265. flex-wrap: no-wrap;
  266. button {
  267. margin: 0;
  268. margin-right: 10rpx;
  269. padding: 0 25rpx;
  270. }
  271. }
  272. .uni-list-cell {
  273. background: #F7F8FA;
  274. padding: 10rpx 40rpx;
  275. font-size: 28rpx;
  276. .arrow {
  277. display: inline-block;
  278. border-width: 12rpx 8rpx;
  279. border-style: solid;
  280. float: right;
  281. margin-top: 10rpx;
  282. border-color: #888 transparent transparent transparent;
  283. }
  284. }
  285. .selectTime {
  286. display: flex;
  287. margin-bottom: 20rpx;
  288. .time {
  289. width: 350rpx;
  290. display: flex;
  291. justify-content: space-between;
  292. }
  293. .line {
  294. width: 50rpx;
  295. text-align: center;
  296. }
  297. }
  298. .submit-box {
  299. margin-top: 60rpx
  300. }
  301. }
  302. </style>