equip-set.vue 6.5 KB

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