controls.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <view class="control-container">
  3. <custom-card>
  4. <block slot="backText">{{ title }}</block>
  5. </custom-card>
  6. <view class="control-content" v-if="leftList.length > 0">
  7. <view class="control-list-left">
  8. <view
  9. class="control-list-left-item"
  10. v-for="(item, index) in leftList"
  11. :key="index"
  12. @click="controlClick(index)"
  13. :class="{ 'control-list-left-item-active': index === activeIndex }"
  14. >
  15. {{ item.title }}
  16. </view>
  17. </view>
  18. <view class="control-list-right">
  19. <view class="action-container" v-if="deviceList.length > 0">
  20. <view class="action-button" @click="openAll">一键开启</view>
  21. <view class="action-button action-button-plain" @click="closeAll">一键关闭</view>
  22. </view>
  23. <view
  24. v-for="(item, index) in deviceList"
  25. class="control-list-right-item"
  26. :key="index"
  27. >
  28. <view style="display: flex; align-items: center;" v-if="item.sfType != '10'">
  29. <view class="control-list-right-item-icon">
  30. <image
  31. :src="solenoidValve"
  32. class="solenoid-valve"
  33. />
  34. </view>
  35. <view class="control-list-right-item-title">{{
  36. item.device_name
  37. }}</view>
  38. <view class="control-list-right-item-action">
  39. <u-switch
  40. :value="item.device_status == 1 ? true : false"
  41. activeColor="#0BBC58"
  42. size="40"
  43. inactiveColor="rgb(230, 230, 230)"
  44. ></u-switch>
  45. </view>
  46. </view>
  47. </view>
  48. <u-empty v-if="deviceList.length === 0" text="暂无数据"></u-empty>
  49. </view>
  50. </view>
  51. <u-empty v-else text="暂无数据"></u-empty>
  52. <u-popup v-model="showPopup" mode="bottom">
  53. <u-form :model="form" label-width="160rpx" :label-style="{marginLeft:'20rpx'}">
  54. <u-form-item label="开启状态">
  55. <u-radio-group v-model="value">
  56. <u-radio
  57. @change="radioChange"
  58. v-for="(item, index) in radioList" :key="index"
  59. :name="item.value"
  60. active-color="#0BBC58"
  61. >
  62. {{item.name}}
  63. </u-radio>
  64. </u-radio-group>
  65. </u-form-item>
  66. <u-form-item label="开阀时间" v-if="value == 1">
  67. <view @click="show1 = true" class="hour">{{hour}} 小时</view>
  68. </u-form-item>
  69. <u-form-item label="开度数值">
  70. <view class="slider-row" style="display:flex;align-items:center;"><view class="slider-container">
  71. <view class="slider-min-value">10</view>
  72. <view
  73. :class="['custom-progress', { dragging: sliderDragging }]"
  74. @touchstart.stop="onSliderTouchStart($event, 'openingValue', 10, 100)"
  75. @touchmove="onSliderTouchMove($event, 10, 100)"
  76. @touchend.stop="onSliderTouchEnd"
  77. >
  78. <view class="progress-track">
  79. <view class="progress-fill" :style="{ width: getProgressWidth(equipContrlForm.openingValue, 10, 100) + '%' }"></view>
  80. <view class="progress-thumb" :style="{ left: getProgressWidth(equipContrlForm.openingValue, 10, 100) + '%' }"></view>
  81. </view>
  82. </view>
  83. <view class="slider-max-value">100</view>
  84. </view>
  85. <text style="margin-left: 20rpx">{{equipContrlForm.openingValue}}</text></view>
  86. </u-form-item>
  87. <u-button type="success" style="width: 94%;margin-left: 3%;margin-bottom: 40rpx" @click="submit">提交</u-button>
  88. </u-form>
  89. </u-popup>
  90. <u-modal
  91. v-model="show2"
  92. :title="'提示'"
  93. :content="content"
  94. @confirm="confirmHandle"
  95. @cancel="show2 = false"
  96. :mask-close-able="true"
  97. :show-cancel-button="true"
  98. ></u-modal>
  99. <u-select v-model="show1" :list="hours" @confirm="changeHour"></u-select>
  100. <u-popup v-model="show4" mode="center" width="80%" :mask-close-able="false">
  101. <view class="progress-container">
  102. <u-line-progress :percent="percentage" style="width: 90%;"></u-line-progress>
  103. </view>
  104. </u-popup>
  105. </view>
  106. </template>
  107. <script>
  108. import solenoidValve from './assets/solenoidValve.png';
  109. export default {
  110. name: 'control',
  111. data() {
  112. return {
  113. show1: false,
  114. show2: false,
  115. show4: false,
  116. percentage: 0,
  117. activeIndex: 0,
  118. showPopup: false,
  119. content:'确定一键关闭所有阀门吗?',
  120. value: 0,
  121. sliderField: '',
  122. sliderMin: 0,
  123. hours: [],
  124. sliderMax: 0,
  125. sliderRect: {},
  126. hour: 1,
  127. minute: 0,
  128. form: {},
  129. radioList:[{
  130. name:'常开',
  131. value:0
  132. },
  133. {
  134. name:'定时',
  135. value:1
  136. }],
  137. sliderDragging: false,
  138. equipContrlForm: {
  139. openingValue: 60,
  140. },
  141. solenoidValve,
  142. title: '分组控制',
  143. leftList: [],
  144. deviceList: [],
  145. timer: null,
  146. };
  147. },
  148. methods: {
  149. changeHour(e){
  150. this.hour = e[0].value
  151. },
  152. setPercentage(msg){
  153. this.timer = setInterval(() => {
  154. this.percentage += 1;
  155. if(this.percentage >= 100){
  156. this.percentage = 100;
  157. uni.showToast({
  158. title: msg,
  159. icon: 'none',
  160. });
  161. clearInterval(this.timer);
  162. this.show4 = false;
  163. this.percentage = 0;
  164. this.getdeviceSfStatus();
  165. }
  166. }, 125);
  167. },
  168. getHours(){
  169. for(let i = 1; i <= 12; i++){
  170. this.hours.push({
  171. label: i + ' 时',
  172. value: i,
  173. })
  174. }
  175. },
  176. async confirmHandle(){
  177. const data = {
  178. group_id: this.leftList[this.activeIndex].id,
  179. control_type:'close',
  180. };
  181. const res = await this.$myRequest({
  182. url: '/api/api_gateway?method=irrigation_system.valvecontrol.control_huapu_valve_group',
  183. method: 'post',
  184. data
  185. });
  186. if(res.code == 0){
  187. this.show4 = true;
  188. this.setPercentage(res.msg);
  189. }
  190. this.showPopup = false;
  191. this.show2 = false;
  192. },
  193. async submit(){
  194. const data = {
  195. group_id: this.leftList[this.activeIndex].id,
  196. control_type:'open',
  197. valve_delayed: this.value == 0 ? 0 : this.hour * 60 + this.minute,
  198. var_value: this.equipContrlForm.openingValue,
  199. };
  200. const res = await this.$myRequest({
  201. url: '/api/api_gateway?method=irrigation_system.valvecontrol.control_huapu_valve_group',
  202. method: 'post',
  203. data
  204. });
  205. if(res.code == 0){
  206. this.show4 = true;
  207. this.setPercentage(res.msg);
  208. }
  209. this.showPopup = false;
  210. this.show2 = false;
  211. },
  212. getProgressWidth(value, min, max) {
  213. if (max === min) return 0
  214. return ((value - min) / (max - min)) * 100
  215. },
  216. getModel(value){
  217. return value == 0 ? false : true
  218. },
  219. controlClick(index) {
  220. this.activeIndex = index;
  221. this.deviceList = this.leftList[this.activeIndex]?.device_list || [];
  222. },
  223. onSliderTouchStart(e, field, min, max) {
  224. this.sliderDragging = true
  225. const clientX = e.touches[0].clientX
  226. this.sliderField = field
  227. this.sliderMin = min
  228. this.sliderMax = max
  229. const query = uni.createSelectorQuery().in(this)
  230. query.selectAll('.custom-progress').boundingClientRect(rects => {
  231. const list = Array.isArray(rects) ? rects : []
  232. this.sliderRect = list.find(r => r && r.width > 0) || list[0] || null
  233. this.updateSliderValue(clientX, field, min, max)
  234. }).exec()
  235. },
  236. onSliderTouchMove(e, min, max) {
  237. if (!this.sliderField || !this.sliderRect) return
  238. this.updateSliderValue(e.touches[0].clientX, this.sliderField, min, max)
  239. },
  240. onSliderTouchEnd() {
  241. this.sliderField = ''
  242. this.sliderDragging = false
  243. },
  244. onSliderTap(e, field, min, max) {
  245. const query = uni.createSelectorQuery().in(this)
  246. query.select('.custom-progress').boundingClientRect(rect => {
  247. this.sliderRect = rect
  248. this.updateSliderValue(e.detail.x + rect.left, field, min, max)
  249. }).exec()
  250. },
  251. updateSliderValue(clientX, field, min, max) {
  252. if (!this.sliderRect || !this.sliderRect.width) return
  253. let ratio = (clientX - this.sliderRect.left) / this.sliderRect.width
  254. ratio = Math.max(0, Math.min(1, ratio))
  255. const value = Math.round(min + ratio * (max - min))
  256. if (this.equipContrlForm[field] === value) return
  257. this.$set(this.equipContrlForm, field, value)
  258. },
  259. openAll(){
  260. this.showPopup = true;
  261. },
  262. closeAll(){
  263. this.show2 = true;
  264. },
  265. initData(res){
  266. this.deviceList = [];
  267. this.leftList = [];
  268. res?.forEach((item) => {
  269. this.leftList.push(item);
  270. });
  271. this.activeIndex = 0;
  272. this.deviceList = this.leftList[this.activeIndex]?.device_list || [];
  273. },
  274. async getdeviceSfStatus() {
  275. this.activeIndex = 0;
  276. const res = await this.$myRequest({
  277. url: '/api/api_gateway?method=irrigation_system.valvecontrol.get_huapu_valve_group_list',
  278. method: 'post',
  279. });
  280. this.initData(res?.data || []);
  281. },
  282. },
  283. onLoad() {
  284. this.getHours();
  285. this.getdeviceSfStatus();
  286. },
  287. };
  288. </script>
  289. <style scoped lang="scss">
  290. uni-page-body {
  291. position: relative;
  292. height: 100%;
  293. }
  294. .progress-container{
  295. display: flex;
  296. justify-content: center;
  297. align-items: center;
  298. height:100%;
  299. }
  300. .hour,.minute{
  301. font-size: 28rpx;
  302. color: #999999;
  303. border-radius: 8rpx;
  304. border: 2rpx solid #aaa;
  305. padding: 4rpx 8rpx;
  306. margin-right: 8rpx;
  307. height: 40rpx;
  308. display: flex;
  309. align-items: center;
  310. justify-content: center;
  311. width: 160rpx;
  312. }
  313. .control-container {
  314. background: linear-gradient(180deg, #ffffff00 0%, #fff 23.64%, #fff 100%),
  315. linear-gradient(102deg, #bfeadd 6.77%, #b8f1e7 40.15%, #b9eef5 84.02%);
  316. height: 100%;
  317. width: 100%;
  318. overflow-x: hidden;
  319. overflow-y: hidden;
  320. .control-content {
  321. display: flex;
  322. width: 100%;
  323. height: calc(100% - 102rpx);
  324. overflow-x: hidden;
  325. overflow-y: auto;
  326. padding: 8px 0;
  327. border-radius: 8px 8px 0 0;
  328. background: #fff;
  329. .control-list-left {
  330. width: 250rpx;
  331. position: fixed;
  332. height: calc(100% - 90rpx);
  333. overflow-x: hidden;
  334. overflow-y: auto;
  335. .control-list-left-item {
  336. width: 240rpx;
  337. height: 96rpx;
  338. line-height: 96rpx;
  339. background: #f5f7fa;
  340. padding-left: 24rpx;
  341. color: #364d46;
  342. font-family: 'Source Han Sans CN VF';
  343. font-size: 32rpx;
  344. font-weight: 400;
  345. position: relative;
  346. //超出隐藏
  347. overflow: hidden;
  348. text-overflow: ellipsis;
  349. white-space: nowrap;
  350. }
  351. .control-list-left-item-active {
  352. background: #0bbc581a;
  353. color:#0BBC58;
  354. font-family: "Source Han Sans CN VF";
  355. font-size: 32rpx;
  356. font-weight: 700;
  357. }
  358. }
  359. .control-list-right {
  360. width: calc(100% - 250rpx);
  361. margin: 0 32rpx;
  362. margin-left: 280rpx;
  363. .action-container {
  364. display: flex;
  365. justify-content: center;
  366. align-items: center;
  367. margin-bottom: 22rpx;
  368. gap: 22rpx;
  369. .action-button{
  370. flex:1;
  371. height: 80rpx;
  372. line-height: 80rpx;
  373. text-align: center;
  374. border-radius: 8rpx;
  375. background: #0bbc58;
  376. color:#ffffff;
  377. font-family: "Source Han Sans CN VF";
  378. font-size: 28rpx;
  379. font-weight: 600;
  380. }
  381. .action-button-plain{
  382. background: #ffffff;
  383. border:2rpx solid #0bbc58;
  384. color:#0bbc58;
  385. }
  386. }
  387. .control-list-right-item {
  388. height: 96rpx;
  389. display: flex;
  390. padding: 0rpx 16rpx;
  391. align-items: center;
  392. border-radius: 8rpx;
  393. background: #f5f7fa;
  394. margin-bottom: 22rpx;
  395. position: relative;
  396. .control-list-right-item-icon {
  397. display: flex;
  398. align-items: center;
  399. .solenoid-valve {
  400. width: 40rpx;
  401. height: 40rpx;
  402. }
  403. }
  404. .control-list-right-item-title {
  405. margin-left: 8rpx;
  406. }
  407. .control-list-right-item-action {
  408. position: absolute;
  409. right: 16rpx;
  410. }
  411. }
  412. }
  413. }
  414. .slider-container{
  415. position: relative;
  416. margin-top: 10rpx;
  417. .slider-min-value{
  418. position: absolute;
  419. left: 0;
  420. top: -60rpx;
  421. }
  422. .slider{
  423. width: 600rpx;
  424. }
  425. .slider-max-value{
  426. position: absolute;
  427. right: 0;
  428. top: -60rpx;
  429. }
  430. }
  431. .custom-progress{
  432. width: 500rpx;
  433. padding: 0;
  434. &.dragging{
  435. .progress-fill,
  436. .progress-thumb{
  437. transition: none;
  438. }
  439. }
  440. .progress-track{
  441. position: relative;
  442. height: 12rpx;
  443. background-color: #ebedf0;
  444. border-radius: 6rpx;
  445. }
  446. .progress-fill{
  447. position: absolute;
  448. left: 0;
  449. top: 0;
  450. height: 100%;
  451. background-color: #0BBC58;
  452. border-radius: 6rpx;
  453. transition: width 0.2s;
  454. }
  455. .progress-thumb{
  456. position: absolute;
  457. top: 50%;
  458. width: 28rpx;
  459. height: 28rpx;
  460. margin-left: -14rpx;
  461. margin-top: -14rpx;
  462. border-radius: 50%;
  463. background-color: #fff;
  464. box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  465. transition: left 0.2s;
  466. }
  467. }
  468. }
  469. </style>