control.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. uni.showToast({
  104. title: res.msg,
  105. icon: 'none',
  106. });
  107. }
  108. },
  109. controlClick(index) {
  110. this.activeIndex = index;
  111. this.deviceList = this.leftList[this.activeIndex]?.childrenList || [];
  112. },
  113. /*
  114. 0 水源 泵类 负责水源进入管道的总泵或者阀
  115. 1 肥料 泵类 负责肥料进入管道的总阀或者泵
  116. 2 吸肥 泵类 控制肥料桶出肥的阀或者泵,每个肥料桶一个
  117. 3 搅拌 泵类 肥料桶的搅拌电机或者泵 每个肥料桶一个
  118. 4 肥料桶 泵类 肥料桶,每个施肥机有多个或者没有,不一定真实存在,只是逻辑上的概念
  119. 5 电磁阀 无 管道最末端每个田地里控制出水的阀门
  120. 6 传感器 无 水肥机上的 温度,压力,流速,PH EC等监测类要素
  121. 7 灌区 无 逻辑区域,电磁阀的分组
  122. */
  123. async getdeviceSfStatus() {
  124. const res = await this.$myRequest({
  125. url: '/api/v2/iot/mobile/device/sf/status/',
  126. method: 'post',
  127. data: {
  128. devBid: this.devBid,
  129. },
  130. });
  131. this.deviceList = [];
  132. const sfCurrent = [
  133. {
  134. sfDisplayname: '水肥机',
  135. childrenList: [],
  136. },
  137. ];
  138. const irrigatedAreaList = [];
  139. res?.forEach((item) => {
  140. if (item.sfType === '0' || item.sfType === '1' || item.sfType === '2') {
  141. sfCurrent[0].childrenList.push(item);
  142. } else if (item.sfType === '4') {
  143. const childrenList = item?.childrenList || [];
  144. childrenList.forEach((child) => {
  145. if (
  146. child.sfType === '3' ||
  147. child.sfType === '2' ||
  148. child.sfType === '8'
  149. ) {
  150. sfCurrent[0].childrenList.push(child);
  151. }
  152. });
  153. } else if (item.sfType === '7') {
  154. irrigatedAreaList.push(item);
  155. }
  156. });
  157. this.leftList = [...sfCurrent, ...irrigatedAreaList];
  158. this.deviceList = this.leftList[this.activeIndex]?.childrenList || [];
  159. },
  160. },
  161. onLoad(options) {
  162. const { devBid } = options;
  163. this.devBid = devBid;
  164. this.getdeviceSfStatus();
  165. },
  166. };
  167. </script>
  168. <style scoped lang="scss">
  169. uni-page-body {
  170. position: relative;
  171. height: 100%;
  172. }
  173. .control-container {
  174. background: linear-gradient(180deg, #ffffff00 0%, #fff 23.64%, #fff 100%),
  175. linear-gradient(102deg, #bfeadd 6.77%, #b8f1e7 40.15%, #b9eef5 84.02%);
  176. height: 100%;
  177. width: 100%;
  178. overflow-x: hidden;
  179. overflow-y: hidden;
  180. .control-content {
  181. display: flex;
  182. width: 100%;
  183. height: calc(100% - 102rpx);
  184. overflow-x: hidden;
  185. overflow-y: auto;
  186. padding: 8px 0;
  187. border-radius: 8px 8px 0 0;
  188. background: #fff;
  189. .control-list-left {
  190. width: 250rpx;
  191. position: fixed;
  192. height: calc(100% - 90rpx);
  193. overflow-x: hidden;
  194. overflow-y: auto;
  195. .control-list-left-item {
  196. width: 240rpx;
  197. height: 96rpx;
  198. line-height: 96rpx;
  199. background: #f5f7fa;
  200. padding-left: 24rpx;
  201. color: #364d46;
  202. font-family: 'Source Han Sans CN VF';
  203. font-size: 32rpx;
  204. font-weight: 400;
  205. position: relative;
  206. }
  207. .control-list-left-item-active {
  208. background: #ffffff;
  209. border-radius: 0 -16rpx -16rpx 0;
  210. }
  211. .borderTopRadius {
  212. position: absolute;
  213. width: 30rpx;
  214. height: 30rpx;
  215. right: -4rpx;
  216. top: -20rpx;
  217. transform: rotate(90deg);
  218. z-index: 100;
  219. }
  220. .borderBottomRadius {
  221. position: absolute;
  222. width: 40rpx;
  223. height: 40rpx;
  224. right: -0rpx;
  225. bottom: -30rpx;
  226. z-index: 100;
  227. }
  228. }
  229. .control-list-right {
  230. width: calc(100% - 250rpx);
  231. margin: 0 32rpx;
  232. margin-left: 280rpx;
  233. .control-list-right-item {
  234. height: 96rpx;
  235. display: flex;
  236. padding: 0rpx 16rpx;
  237. align-items: center;
  238. border-radius: 8rpx;
  239. background: #f5f7fa;
  240. margin-bottom: 22rpx;
  241. position: relative;
  242. .control-list-right-item-icon {
  243. .solenoid-valve {
  244. width: 40rpx;
  245. height: 40rpx;
  246. }
  247. }
  248. .control-list-right-item-title {
  249. margin-left: 8rpx;
  250. }
  251. .control-list-right-item-action {
  252. position: absolute;
  253. right: 16rpx;
  254. }
  255. }
  256. }
  257. }
  258. }
  259. </style>