Explorar o código

feat: 灌溉自动控制逻辑调整

allen hai 3 meses
pai
achega
390c246be1

+ 36 - 11
pages/cb/shuifeizs/automation.vue

@@ -66,6 +66,8 @@ export default {
     return {
       activeIndex: 0,
       devBid: '',
+      devName: '',
+      devStatus: '',
       irrigatedAreaList: [],
       alreadyList: [],
       formData: {
@@ -98,8 +100,22 @@ export default {
   },
   onLoad(options) {
     this.devBid = options.devBid;
-    this.getdeviceSfStatus();
-    this.getAlreadyList();
+    this.devName = options.devName;
+    this.devStatus = options.devStatus;
+
+    // 检测是否有运行中的任务
+    this.getRunStatus().then((hasRunningTask) => {
+      if (hasRunningTask) {
+        setTimeout(() => {
+          uni.redirectTo({
+            url: `/pages/cb/shuifeizs/rotationflow?devBid=${this.devBid}&devName=${this.devName}&devStatus=${this.devStatus}`,
+          });
+        }, 1000);
+      } else {
+        this.getdeviceSfStatus();
+        this.getAlreadyList();
+      }
+    });
   },
   methods: {
     async getAlreadyList() {
@@ -110,6 +126,8 @@ export default {
           devBid: this.devBid,
         },
       });
+
+      console.log(res, '-------------------- get already list');
       res.forEach((item) => {
         item.isChecked = false;
       });
@@ -126,6 +144,8 @@ export default {
       this.dataList = [];
       this.irrigatedAreaList = [];
       this.alreadyfertilizerBucketList = [];
+
+      console.log('get device sf status', res);
       res.forEach((item) => {
         if (item.sfType === '7') {
           this.irrigatedAreaList.push(item);
@@ -138,14 +158,19 @@ export default {
     },
     // 获取运行状态
     async getRunStatus() {
-      const res = await this.$myRequest({
-        url: '/api/v2/iot/mobile/device/sf/zsrf/run/status/',
-        method: 'post',
-        data: {
-          devBid: this.devBid,
-        },
-      });
-      if (res.code === '000000') {
+      try {
+        const res = await this.$myRequest({
+          url: '/api/v2/iot/mobile/device/sf/zsrf/task/run/status/',
+          method: 'post',
+          data: {
+            devBid: this.devBid,
+          },
+        });
+        console.log(res, 'resresresres');
+
+        return Promise.resolve(res.status && res.status / 1 === 1);
+      } catch (error) {
+        return Promise.resolve(false);
       }
     },
     // iot/mobile/device/sf/zsrf/task/ctl/
@@ -169,7 +194,7 @@ export default {
         });
         setTimeout(() => {
           uni.redirectTo({
-            url: `/pages/cb/shuifeizs/rotationflow?devBid=${this.devBid}`,
+            url: `/pages/cb/shuifeizs/rotationflow?devBid=${this.devBid}&devName=${this.devName}&devStatus=${this.devStatus}`,
           });
         }, 1000);
       } else {

+ 4 - 3
pages/cb/shuifeizs/detail.vue

@@ -150,13 +150,14 @@ export default {
           devBid: this.devBid,
         },
       });
-      const data = JSON.stringify(res?.data || {});
+      const data = JSON.stringify(res || {});
+
       if (data == '{}') {
         this.isRun = true;
-        this.deviceList[1].url = `/pages/cb/shuifeizs/automation?devBid=${this.devBid}`;
+        this.deviceList[1].url = `/pages/cb/shuifeizs/automation?devBid=${this.devBid}&devName=${this.devName}&devStatus=${this.devStatus}`;
       } else {
         this.isRun = false;
-        this.deviceList[1].url = `/pages/cb/shuifeizs/rotationflow?devBid=${this.devBid}`;
+        this.deviceList[1].url = `/pages/cb/shuifeizs/rotationflow?devBid=${this.devBid}&devName=${this.devName}&devStatus=${this.devStatus}`;
       }
     },
     async getdeviceSfStatus() {

+ 43 - 12
pages/cb/shuifeizs/rotationflow.vue

@@ -9,8 +9,10 @@
         <image :src="rotate" class="rotate-rotate" />
         <image :src="water" class="rotate-water" />
         <view class="rotationflow-time">
-          <view class="rotationflow-time-title">{{ currentFq.name }}</view>
-          <view class="rotationflow-time-content"> {{ time }}</view>
+          <view class="rotationflow-time-title" style="font-size: 28px">{{
+            currentFq.name
+          }}</view>
+          <!-- <view class="rotationflow-time-content"> {{ time }}</view> -->
           <view class="rotationflow-time-label">{{ label }}</view>
         </view>
       </view>
@@ -31,17 +33,17 @@
       <view class="rotationflow-content-top">
         <view
           :class="
-            tktype == '0'
+            tktype == '1'
               ? 'rotationflow-content-top-title'
               : 'rotationflow-content-top-title-rever'
           "
         >
-          {{ tktype == '0' ? '灌溉' : '水肥' }}
+          {{ tktype == '1' ? '灌溉' : '水肥' }}
         </view>
         <view class="rotationflow-content-top-desc">已选灌区</view>
       </view>
       <view class="rotationflow-content-list">
-        <view class="rotationflow-content-list-wrapper" v-if="tktype == 0">
+        <view class="rotationflow-content-list-wrapper" v-if="tktype == 1">
           <view class="rotationflow-content-num">
             <view class="rotationflow-content-num-title"
               >轮灌次数:{{ currentFq.lgcs || 0 }}</view
@@ -61,7 +63,7 @@
             > </view
           ><view class="rotationflow-content-num">
             <view class="rotationflow-content-num-title"
-              >轮灌次数:{{ currentFq.lgjg || 0 }} 分钟</view
+              >轮灌间隔:{{ currentFq.lgjg || 0 }} 分钟</view
             >
             <view class="rotationflow-content-num-title"
               >肥后水:{{ currentFq.fhcx || 0 }} 分钟</view
@@ -76,7 +78,7 @@
         <view
           class="rotationflow-content-list-item"
           v-for="(item, index) in fqList"
-          :class="index === 0 ? 'haveYet' : index === 1 ? 'currentYet' : ''"
+          :class="item.value === '2' ? 'haveYet' : ''"
           :key="index"
         >
           <view
@@ -126,6 +128,8 @@ export default {
       fqList: [],
       currentFq: {},
       label: '灌溉中.',
+      devName: '',
+      devStatus: '',
     };
   },
   components: {},
@@ -183,19 +187,40 @@ export default {
           devBid: this.devBid,
         },
       });
-      const data = res.data || {};
+
+      console.log(res, 'resresresres 12222222222222222222');
+      const data = res || {};
+      if (data.status === undefined || data.status / 1 !== 1) {
+        clearInterval(this.timer);
+        clearInterval(this.taskTimer);
+        uni.showLoading({
+          title: '灌溉任务已结束',
+        });
+
+        setTimeout(() => {
+          uni.hideLoading();
+          uni.redirectTo({
+            url: `/pages/cb/shuifeizs/detail?devBid=${this.devBid}&devName=${this.devName}&devStatus=${this.devStatus}`,
+          });
+        }, 1000);
+        return;
+      }
+
       this.list = data?.sensorList || [];
+
+      console.log(this.list, '-------------------- run status ----------');
       this.tktype = data?.tktype;
       this.lgjg = data?.lgjg || 0;
       this.lgcs = data?.lgcs || 0;
       this.fqList = data?.fqList || [];
+      // value 0 未灌溉 1 灌溉中 2 灌溉完成
       this.fqList.forEach((item) => {
         if (item.value === '1') {
           this.currentFq = item;
         }
       });
       this.formartTime(this.currentFq.lgjg);
-      this.setTime(this.currentFq.lgjg);
+      // this.setTime(this.currentFq.lgjg);
     },
     rotationflowEnd() {
       const payload = {
@@ -225,7 +250,7 @@ export default {
         });
         setTimeout(() => {
           uni.navigateTo({
-            url: `/pages/cb/shuifeizs/detail?devBid=${this.devBid}`,
+            url: `/pages/cb/shuifeizs/detail?devBid=${this.devBid}&devName=${this.devName}&devStatus=${this.devStatus}`,
           });
         }, 1000);
       } else {
@@ -237,10 +262,12 @@ export default {
     },
   },
   onLoad(options) {
-    const { devBid } = options;
+    const { devBid, devName, devStatus } = options;
     this.devBid = devBid;
+    this.devName = devName;
+    this.devStatus = devStatus;
     this.getRunStatus();
-    setInterval(() => {
+    this.labelTimer = setInterval(() => {
       if (this.label === '灌溉中.') {
         this.label = '灌溉中..';
       } else if (this.label === '灌溉中..') {
@@ -249,6 +276,10 @@ export default {
         this.label = '灌溉中.';
       }
     }, 500);
+
+    this.taskTimer = setInterval(() => {
+      this.getRunStatus();
+    }, 30000);
   },
   onUnload() {
     clearInterval(this.timer);