管灌系统农户端微信小程序(嘉峪关应用)
zuoxiao
2024-08-12 19804e37592d2250c551fcf5df1d87cdf551f1d1
添加识别二维码切换地址的功能
7个文件已修改
268 ■■■■ 已修改文件
pages/home/home.js 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/home/home.wxml 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/home/home.wxss 39 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/waterIntake/waterIntake.js 79 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/waterIntake/waterIntake.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/waterIntake/waterIntake.wxml 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/waterIntake/waterIntake.wxss 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/home/home.js
@@ -26,6 +26,8 @@
    confirmBtn: {
      content: '确认'
    },
    errorDialogTitle: "关阀错误",
    showForceConfirm: false //是否强制开阀
  },
  openValve: function (e) {
@@ -192,7 +194,16 @@
    });
  },
  closeDialog() {
    console.log("closeDialog");
    this.setData({
      showConfirm: false,
      showErrorDialog: false,
      showForceConfirm: false
    });
  },
  cancelDialog(){
    this.setData({
      showForceConfirm: false,
      showConfirm: false
    });
  },
@@ -236,7 +247,8 @@
      wx.hideLoading();
      this.setData({
        showErrorDialog: true,
        errorData: error.msg
        errorData: error.msg,
        errorDialogTitle: "关阀错误"
      })
      // 处理错误响应
      console.error('请求失败:', error);
@@ -320,18 +332,65 @@
      showErrorDialog: false
    })
  },
  /**
   * 扫码开阀
   */
  scenCode() {
    const that = this;
    wx.scanCode({
      success(res) {
        console.log(res.result); // 当且仅当扫码为非微信二维码时,会返回result  
        // 如果扫码结果为URL,会自动尝试打开
        // 如果扫码结果为微信小程序的码,会直接跳转到对应的小程序页面
        // 如果扫码结果为公众号二维码,则会在手机上打开微信并跳转到对应的公众号
        wx.showLoading({
          title: '正在开阀请稍候...', // 加载提示文字
          mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false
        });
        const app = getApp();
        const data = {
          intakeName: res.result, //取水口ID
          // vcId: vcId, //虚拟卡ID
          operator: app.globalData.sessionId //操作员
        };
        post({
          url: "wx/valve/open_wx",
          data: data,
          timeout: 180000
        }).then(response => {
          // 处理成功响应
          console.log('请求成功:', response);
          // 加载完成后隐藏加载动画
          wx.hideLoading();
          //完成后回到首页
          wx.reLaunch({
            url: '/pages/home/home?param=true' // 首页的路径,根据实际情况填写
          });
        }).catch(error => {
          // 加载完成后隐藏加载动画
          wx.hideLoading();
          // 处理错误响应
          console.error('请求失败:', error);
          if (error.code==="1003") {
            that.setData({
              showForceConfirm:true
            })
          } else {
            that.setData({
              showErrorDialog: true,
              errorData: error.msg,
              errorDialogTitle: "开阀错误"
            })
          }
        });
      },
      fail(err) {
        console.error(err);
      }
    })
  },
  confirmForceDialog(){
    console.log("confirmForceDialog");
  }
})
pages/home/home.wxml
@@ -12,7 +12,11 @@
        <text class="unbind" bind:tap="feedBack">解绑</text>
        <text class="head-bottom" bind:tap="feedBack">联系客服</text>
      </view>
      <image class="scen-code" src="/images/scen_code.svg" bind:tap="scenCode"/>
      <view class="scen-view" bind:tap="scenCode">
        <image class="scen-code" src="/images/scen_code.svg" />
        <text>扫码开阀</text>
      </view>
    </view>
  </view>
@@ -67,7 +71,8 @@
    </view>
  </scroll-view>
  <t-dialog class="dialog" visible="{{showConfirm}}" content="确认关闭{{waterIntakeName}}吗?" confirm-btn="{{ { content: '确认', variant: 'base', theme: 'danger' } }}" close-on-overlay-click="false" cancel-btn="取消"  bind:confirm="confirmDialog" bind:cancel="closeDialog" />
  <t-dialog class="error-dialog"  title="关阀错误" visible="{{showErrorDialog}}" content="{{errorData}}" confirm-btn="{{ confirmBtn }}" bind:confirm="closeDialog" />
  <t-dialog class="dialog" visible="{{showConfirm}}" content="确认关闭{{waterIntakeName}}吗?" confirm-btn="{{ { content: '确认', variant: 'base', theme: 'danger' } }}" close-on-overlay-click="false" cancel-btn="取消" bind:confirm="confirmDialog" bind:cancel="cancelDialog" />
  <t-dialog class="error-dialog" title="{{errorDialogTitle}}" visible="{{showErrorDialog}}" content="{{errorData}}" confirm-btn="{{ confirmBtn }}" bind:confirm="closeDialog" />
  <t-dialog visible="{{showForceConfirm}}" content="当前虚拟卡被占用,是否强制开阀?" confirm-btn="{{ { content: '强制开阀', variant: 'base', theme: 'danger' } }}" cancel-btn="取消" bind:confirm="confirmForceDialog" bind:cancel="cancelDialog" />
</view>
pages/home/home.wxss
@@ -217,9 +217,14 @@
  padding-left: 25rpx;
  padding-right: 25rpx;
  padding-top: 15rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 15rpx;
}
.refresh-button:active{
  background-color: #7c7c7c; /* Change to a darker color when pressed */
}
.refresh-view {
  text-align: center;
  padding: 30rpx;
@@ -311,6 +316,10 @@
  justify-content: center;
}
.item-button:active {
  background-color: #7c7c7c; /* Change to a darker color when pressed */
}
.divider {
  width: 100%;
  margin-top: 2rpx;
@@ -318,16 +327,30 @@
}
.error-dialog{
  --td-dialog-title-color:red;
  --td-dialog-title-font-size:40rpx;
.error-dialog {
  --td-dialog-title-color: red;
  --td-dialog-title-font-size: 40rpx;
}
.scen-code{
.scen-view {
  position: absolute;
  /* 添加这行 */
  top: 15rpx;
  /* 根据需要调整距离顶部的距离 */
  right: 30rpx;
  /* 根据需要调整距离右侧的距离 */
  display: flex;
  align-items: center;
  /* 垂直方向居中 */
  justify-content: space-between;
}
.scen-code {
  width: 40rpx;
  height: 40rpx;
  position: absolute; /* 添加这行 */
  top: 15rpx; /* 根据需要调整距离顶部的距离 */
  right: 30rpx; /* 根据需要调整距离右侧的距离 */
}
.scen-view text {
  font-size: 30rpx;
  color: #ffffff;
}
pages/waterIntake/waterIntake.js
@@ -9,6 +9,11 @@
    searchQuery: "",
    commonWaterPoints: [], // 常用取水口数据
    allWaterPoints: [], // 所有取水口数据
    searchData: [{
      intakeNum: "1111111"
    }, {
      intakeNum: "2222222"
    }],
    isRefreshing_all: false,
    isRefreshing_common: false,
    showConfirm: false,
@@ -19,6 +24,9 @@
    confirmBtn: {
      content: '确认'
    },
    showForceConfirm: false,
    forceIntakeId: "", //强制开阀的取水口id
    inputValue:""
  },
  // 切换 Tabs
@@ -39,7 +47,9 @@
      this.getallWaterPoints(query)
      // 在这里进行搜索操作,更新 allWaterPoints 数据
    } else {
      this.getallWaterPoints(query)
      this.setData({
        allWaterPoints: []
      })
    }
  },
@@ -48,9 +58,11 @@
   * @param {} event 
   */
  choseCard(event) {
    //显示二次确认弹窗
    this.setData({
      showConfirm: true,
      choseItem: event.currentTarget.dataset.item
      choseItem: event.currentTarget.dataset.item,
      allWaterPoints: []
    })
    //  console.log(intakeId);
    //   wx.navigateTo({
@@ -59,7 +71,16 @@
  },
  //开泵通信
  postOpenValva(intakeId) {
  /**
   *
   * @param {*} intakeId 取水口id
   * @param {*} isforce 是否强制开阀
   */
  postOpenValva(intakeId, isforce) {
    this.setData({
      inputValue:""
    })
    console.log("intakeId:" + intakeId + "   isforce:" + isforce)
    wx.showLoading({
      title: '正在开阀请稍候...', // 加载提示文字
      mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false
@@ -68,7 +89,8 @@
    const data = {
      intakeId: intakeId, //取水口ID
      // vcId: vcId, //虚拟卡ID
      operator: app.globalData.sessionId //操作员
      operator: app.globalData.sessionId, //操作员
      forceOpen: !!isforce // 使用逻辑非操作符 !! 来确保 isForce 是布尔值
    };
    post({
      url: "wx/valve/open_wx",
@@ -90,12 +112,17 @@
      wx.hideLoading();
      // 处理错误响应
      console.error('请求失败:', error);
      this.setData({
        showErrorDialog: true,
        errorData: error.msg
      })
      if (error.code === "10005") {
        this.setData({
          forceIntakeId: intakeId,
          showForceConfirm: true
        })
      } else {
        this.setData({
          showErrorDialog: true,
          errorData: error.msg
        })
      }
    });
  },
@@ -110,7 +137,6 @@
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getallWaterPoints();
    this.getcommonWaterPoints();
  },
@@ -152,7 +178,7 @@
  },
  /**
   * 获取所有取水口
   *在所有取水口搜索
   */
  getallWaterPoints: function (intakeNum) {
    let params = {
@@ -169,9 +195,17 @@
          isRefreshing_all: false
        });
        if (data.success && data.code === "0001") {
          this.setData({
            allWaterPoints: data.content.obj
          });
          if (!data.content) {
            wx.showToast({
              title: '没有搜索到取水口',
              icon: 'error',
            })
          }else{
            this.setData({
              allWaterPoints:[data.content]
            });
          }
        } else {
          wx.showToast({
            title: data.msg,
@@ -250,5 +284,20 @@
    this.setData({
      showErrorDialog: false
    })
  },
  cancelDialog() {
    this.setData({
      showForceConfirm: false
    });
  },
  //强制开阀
  confirmForceDialog() {
    this.postOpenValva(this.data.forceIntakeId, true);
  },
  closeSearch(){
    this.setData({
      allWaterPoints:[],
      inputValue:""
    })
  }
})
pages/waterIntake/waterIntake.json
@@ -6,7 +6,7 @@
    "t-button": "tdesign-miniprogram/button/button",
    "t-dialog": "tdesign-miniprogram/dialog/dialog"
  },
  "navigationBarTitleText": "取水口",
  "navigationBarTitleText": "常用取水口",
  "navigationBarTextStyle": "white"
  
}
pages/waterIntake/waterIntake.wxml
@@ -1,41 +1,23 @@
<view class="container">
  <!-- 顶部 Tabs -->
  <view class="tabs">
    <view class="tab" bindtap="switchTab" data-tab="0" id="tab0">
      常用取水口
      <view class="indicator" wx:if="{{currentTab === 0}}"></view>
    </view>
    <view class="tab" bindtap="switchTab" data-tab="1" id="tab1">
      所有取水口
      <view class="indicator" wx:if="{{currentTab === 1}}"></view>
    </view>
  </view>
  <!-- 常用取水口 -->
  <scroll-view class="list-container" wx:if="{{currentTab === 0}}" scroll-y="true" refresher-enabled="true" refresher-threshold="50" bindrefresherrefresh="onPullDownRefresh_common" refresher-triggered="{{isRefreshing_common}}">
    <block wx:for="{{commonWaterPoints}}" wx:key="index">
      <view class="item">
        <view class="item-left">
          <text>{{item.intakeNum}}</text>
          <image class="item-img" src="{{item.isOnLine ? '/images/wifi_no.svg' : '/images/wifi_off.svg'}}" />
        </view>
        <text  class="item-button" bindtap="choseCard" data-item="{{item}}">开阀</text>
      </view>
    </block>
    <view wx:if="{{commonWaterPoints.length === 0}}" class="noMore-View">
      <image class="noMore-img" src="/images/no_more.svg" />
      <text class="noMore-text">没有数据</text>
    </view>
  </scroll-view>
  <!-- 所有取水口 -->
  <view class="all-waterIntake" wx:if="{{currentTab === 1}}">
  <view class="all-waterIntake" wx:if="{{currentTab === 0}}">
    <view class="search-container">
      <input class="search-input" placeholder="请输入取水口编码后点击搜索" bindinput="onInput" />
      <input class="search-input" value="{{inputValue}}" placeholder="请输入取水口编码后点击搜索" bindinput="onInput" />
      <t-button class="search-button" theme="primary" size="large" icon="search" shape="square" aria-label="搜索" bindtap="onSearch" style="background-color: #1890FF; border: none; height: 80rpx;"></t-button>
    </view>
    <scroll-view class="list-container" scroll-y="true" refresher-enabled="true" refresher-threshold="50" bindrefresherrefresh="onPullDownRefresh_all" refresher-triggered="{{isRefreshing_all}}">
    <view class="search-results" wx:if="{{allWaterPoints.length > 0}}" bindtap="closeSearch">
      <block wx:for="{{allWaterPoints}}" wx:key="index">
        <view class="result-item" bindtap="choseCard"  data-item="{{item}}">
          <text>{{item.intakeNum}}</text>
        </view>
      </block>
    </view>
    <scroll-view class="list-container" scroll-y="true" refresher-enabled="true" refresher-threshold="50" bindrefresherrefresh="onPullDownRefresh_common" refresher-triggered="{{isRefreshing_common}}">
      <block wx:for="{{commonWaterPoints}}" wx:key="index">
        <view class="item">
          <view class="item-left">
            <text>{{item.intakeNum}}</text>
@@ -44,7 +26,7 @@
          <text  class="item-button" bindtap="choseCard" data-item="{{item}}">开阀</text>
        </view>
      </block>
      <view wx:if="{{allWaterPoints.length === 0}}" class="noMore-View">
      <view wx:if="{{commonWaterPoints.length === 0}}" class="noMore-View">
        <image class="noMore-img" src="/images/no_more.svg" />
        <text class="noMore-text">没有数据</text>
      </view>
@@ -54,4 +36,8 @@
  <t-dialog class="dialog" visible="{{showConfirm}}" content="确认打开{{choseItem.intakeNum}}吗?" confirm-btn="{{ { content: '确认', variant: 'base', theme: 'danger' } }}" close-on-overlay-click="false" cancel-btn="取消"  bind:confirm="confirmDialog" bind:cancel="closeDialog" />
  <t-dialog class="error-dialog"  title="开阀错误" visible="{{showErrorDialog}}" content="{{errorData}}" confirm-btn="{{ confirmBtn }}" bind:confirm="closeErrorDialog" />
  <t-dialog visible="{{showForceConfirm}}" content="当前虚拟卡被占用,是否强制开阀?" confirm-btn="{{ { content: '强制开阀', variant: 'base', theme: 'danger' } }}" cancel-btn="取消" bind:confirm="confirmForceDialog" bind:cancel="cancelDialog" />
</view>
pages/waterIntake/waterIntake.wxss
@@ -68,7 +68,9 @@
  align-items: center;
  justify-content: center;
}
.item-button:active {
  background-color: #7c7c7c; /* Change to a darker color when pressed */
}
.indicator {
  width: 100%;
  height: 3px;
@@ -143,4 +145,20 @@
.error-dialog{
  --td-dialog-title-color:red;
  --td-dialog-title-font-size:45rpx;
}
.search-results {
  position: absolute;
  top: 100rpx; /* 根据搜索框的高度调整 */
  left: 30rpx;
  right: 30rpx;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.90); /* 设置白色背景 */
  z-index: 1;
  overflow-y: auto;
}
.result-item {
  padding: 20rpx;
  border-bottom: 1px solid #eaeaea;
}