control.vue 7.3 KB

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