control.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. <image
  16. :src="borderRadius"
  17. class="borderTopRadius"
  18. v-if="index === activeIndex"
  19. />
  20. {{ item.sfDisplayname }}
  21. <image
  22. :src="borderRadius"
  23. class="borderBottomRadius"
  24. v-if="index === activeIndex"
  25. />
  26. </view>
  27. </view>
  28. <view class="control-list-right">
  29. <view
  30. class="control-list-right-item"
  31. v-for="(item, index) in deviceList"
  32. :key="index"
  33. >
  34. <view class="control-list-right-item-icon">
  35. <image
  36. :src="item.sfType == '3' ? stir : solenoidValve"
  37. class="solenoid-valve"
  38. />
  39. </view>
  40. <view class="control-list-right-item-title">{{
  41. item.sfDisplayname || item.sfName
  42. }}</view>
  43. <view class="control-list-right-item-action">
  44. <u-switch
  45. :value="item.value == 1 ? true : false"
  46. @change="changeSwitch(item)"
  47. activeColor="#14A478"
  48. size="40"
  49. inactiveColor="rgb(230, 230, 230)"
  50. ></u-switch>
  51. </view>
  52. </view>
  53. <u-empty v-if="deviceList.length === 0" text="暂无数据"></u-empty>
  54. </view>
  55. </view>
  56. <u-empty v-else text="暂无数据"></u-empty>
  57. </view>
  58. </template>
  59. <script>
  60. import solenoidValve from './assets/solenoidValve.png';
  61. import stir from './assets/stir.png';
  62. import borderRadius from './assets/borderRadius.png';
  63. export default {
  64. name: 'control',
  65. data() {
  66. return {
  67. activeIndex: 0,
  68. value: false,
  69. solenoidValve,
  70. stir,
  71. borderRadius,
  72. title: '控制面板',
  73. leftList: [],
  74. deviceList: [],
  75. devBid: '',
  76. };
  77. },
  78. methods: {
  79. getChecked(item) {
  80. return item.value == 1 ? true : false;
  81. },
  82. async changeSwitch(item) {
  83. item.value = item.value == 1 ? 0 : 1;
  84. const sfCode = item.sfCode;
  85. const params = {};
  86. params[sfCode] = item.value;
  87. const payload = {
  88. data: params,
  89. };
  90. const data = {
  91. devBid: this.devBid,
  92. data: params,
  93. };
  94. const res = await this.$myRequest({
  95. url: '/api/v2/iot/mobile/device/sf/devctl/',
  96. method: 'post',
  97. data,
  98. header: {
  99. 'Content-Type': 'application/json',
  100. },
  101. });
  102. if (res.code !== '000000') {
  103. item.value = item.value == 1 ? 0 : 1;
  104. }
  105. uni.showToast({
  106. title: res.msg,
  107. icon: 'none',
  108. });
  109. },
  110. controlClick(index) {
  111. this.activeIndex = index;
  112. this.deviceList = this.leftList[this.activeIndex]?.childrenList || [];
  113. },
  114. /*
  115. 0 水源 泵类 负责水源进入管道的总泵或者阀
  116. 1 肥料 泵类 负责肥料进入管道的总阀或者泵
  117. 2 吸肥 泵类 控制肥料桶出肥的阀或者泵,每个肥料桶一个
  118. 3 搅拌 泵类 肥料桶的搅拌电机或者泵 每个肥料桶一个
  119. 4 肥料桶 泵类 肥料桶,每个施肥机有多个或者没有,不一定真实存在,只是逻辑上的概念
  120. 5 电磁阀 无 管道最末端每个田地里控制出水的阀门
  121. 6 传感器 无 水肥机上的 温度,压力,流速,PH EC等监测类要素
  122. 7 灌区 无 逻辑区域,电磁阀的分组
  123. */
  124. async getdeviceSfStatus() {
  125. const res = await this.$myRequest({
  126. url: '/api/v2/iot/mobile/device/sf/status/',
  127. method: 'post',
  128. data: {
  129. devBid: this.devBid,
  130. },
  131. });
  132. this.deviceList = [];
  133. const sfCurrent = [
  134. {
  135. sfDisplayname: '水肥机',
  136. childrenList: [],
  137. },
  138. ];
  139. const irrigatedAreaList = [];
  140. res?.forEach((item) => {
  141. if (item.sfType === '0' || item.sfType === '1' || item.sfType === '2') {
  142. sfCurrent[0].childrenList.push(item);
  143. } else if (item.sfType === '4') {
  144. const childrenList = item?.childrenList || [];
  145. childrenList.forEach((child) => {
  146. if (
  147. child.sfType === '3' ||
  148. child.sfType === '2' ||
  149. child.sfType === '8'
  150. ) {
  151. sfCurrent[0].childrenList.push(child);
  152. }
  153. });
  154. } else if (item.sfType === '7') {
  155. irrigatedAreaList.push(item);
  156. }
  157. });
  158. this.leftList = [...sfCurrent, ...irrigatedAreaList];
  159. this.deviceList = this.leftList[this.activeIndex]?.childrenList || [];
  160. },
  161. },
  162. onLoad(options) {
  163. const { devBid } = options;
  164. this.devBid = devBid;
  165. this.getdeviceSfStatus();
  166. },
  167. };
  168. </script>
  169. <style scoped lang="scss">
  170. uni-page-body {
  171. position: relative;
  172. height: 100%;
  173. }
  174. .control-container {
  175. background: linear-gradient(180deg, #ffffff00 0%, #fff 23.64%, #fff 100%),
  176. linear-gradient(102deg, #bfeadd 6.77%, #b8f1e7 40.15%, #b9eef5 84.02%);
  177. height: 100%;
  178. width: 100%;
  179. overflow-x: hidden;
  180. overflow-y: hidden;
  181. .control-content {
  182. display: flex;
  183. width: 100%;
  184. height: calc(100% - 102rpx);
  185. overflow-x: hidden;
  186. overflow-y: auto;
  187. padding: 8px 0;
  188. border-radius: 8px 8px 0 0;
  189. background: #fff;
  190. .control-list-left {
  191. width: 250rpx;
  192. position: fixed;
  193. height: calc(100% - 90rpx);
  194. overflow-x: hidden;
  195. overflow-y: auto;
  196. .control-list-left-item {
  197. width: 240rpx;
  198. height: 96rpx;
  199. line-height: 96rpx;
  200. background: #f5f7fa;
  201. padding-left: 24rpx;
  202. color: #364d46;
  203. font-family: 'Source Han Sans CN VF';
  204. font-size: 32rpx;
  205. font-weight: 400;
  206. position: relative;
  207. }
  208. .control-list-left-item-active {
  209. background: #ffffff;
  210. border-radius: 0 -16rpx -16rpx 0;
  211. }
  212. .borderTopRadius {
  213. position: absolute;
  214. width: 40rpx;
  215. height: 40rpx;
  216. right: 10rpx;
  217. top: -32rpx;
  218. transform: rotate(90deg);
  219. z-index: 100;
  220. }
  221. .borderBottomRadius {
  222. position: absolute;
  223. z-index: 100;
  224. width: 40rpx;
  225. height: 40rpx;
  226. bottom: -32rpx;
  227. right: 10rpx;
  228. }
  229. }
  230. .control-list-right {
  231. width: calc(100% - 250rpx);
  232. margin: 0 32rpx;
  233. margin-left: 280rpx;
  234. .control-list-right-item {
  235. height: 96rpx;
  236. display: flex;
  237. padding: 0rpx 16rpx;
  238. align-items: center;
  239. border-radius: 8rpx;
  240. background: #f5f7fa;
  241. margin-bottom: 22rpx;
  242. position: relative;
  243. .control-list-right-item-icon {
  244. .solenoid-valve {
  245. width: 40rpx;
  246. height: 40rpx;
  247. }
  248. }
  249. .control-list-right-item-title {
  250. margin-left: 8rpx;
  251. }
  252. .control-list-right-item-action {
  253. position: absolute;
  254. right: 16rpx;
  255. }
  256. }
  257. }
  258. }
  259. }
  260. </style>