control.vue 7.1 KB

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