controls.vue 13 KB

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