Browse Source

feature 代码提交

xiahan 4 months ago
parent
commit
b6ee1431ef

+ 69 - 3
app.js

@@ -1,20 +1,86 @@
 // app.js
+const utils = require('/utils/util.js')
+const baseIp= "http://localhost:9747"
 App({
-  onLaunch() {
+  onLaunch(options) {
     // 展示本地存储能力
     const logs = wx.getStorageSync('logs') || []
     logs.unshift(Date.now())
     wx.setStorageSync('logs', logs)
-
     // 登录
     wx.login({
       success: res => {
         // 发送 res.code 到后台换取 openId, sessionKey, unionId
+        if(res.code){
+          const _this = this
+          // 登录
+          wx.showLoading({
+            title: '登陆中...',
+            mask: true,
+          });
+          wx.request({
+            method: 'POST',
+            url: _this.globalData.interfaceUrls.loginUrl,
+            data: {
+              wxCode: res.code,
+              dsKey: options.query.deskey
+            },
+            success(res) {
+              wx.hideLoading()
+              if (!res.data.code || res.data.code!= "200") {
+                utils.simleInfoWithBack('登录失败,请稍后再试')
+                return
+              }
+              _this.globalData.launchPara=options.query.deskey;
+              const resData = res.data.data
+              if (resData) {
+                _this.globalData.userWxInfo = {
+                  openid: resData.openid,
+                  session_key: resData.session_key,
+                  token: resData.token,
+                  // 当前用户所关联的户号信息
+                  bindAccountInfo: resData.swUserManagementVos,
+                  // 当前用户所对应的水务公司
+                  currentDsKey:""
+                }
+                wx.navigateTo({
+                  url: '/pages/FirstBangDing/FirstBangDing',
+                })
+                _this.globalData.waterCompanys=resData.waterCompany;
+                if (!resData.swUserManagementVos || resData.swUserManagementVos.length == 0) {
+                  wx.navigateTo({
+                    url: '/pages/FirstBangDing/FirstBangDing',
+                  })
+                } else {
+                  // _this.globalData.userBindInfo = groupArr
+                }
+              } else {
+                utils.simleInfo('登录失败,请稍后再试')
+              }
+            },
+            fail: error => {
+              wx.hideLoading()
+              utils.simleInfo('登录失败,请稍后再试')
+            }
+          })
+        }else{
+          utils.simleInfo('登录失败,请稍后再试')
+        }
       }
     })
   },
   globalData: {
-    userInfo: null,
+    // 当前用户信息
+    userWxInfo: null,
+    // 系统中存在的水务公司
+    waterCompanys: [],
+    // 小程序启动时带的参数
+    launchPara: null,
+    // 系统接口地址
+    interfaceUrls: {
+      loginUrl: baseIp+ '/wechat/login', // 登录+获取绑定列表
+      accoundBind: baseIp+ '/wechat/account/bind', // 账号绑定
+    },
     // 统一管理图片路径
     images: {
       logo: '/static_file/logo.png',

+ 64 - 26
pages/huhaobangding/huhaobangding.js

@@ -1,5 +1,5 @@
 const app = getApp()
-
+const utils = require("../../utils/util.js")
 Page({
   data: {
     selectedTag: '',
@@ -7,13 +7,16 @@ Page({
     customTagLength: 0,
     showDrawer: false,
     showPreview: false,
-    
+    // 是否可以切换水务公司
+    isChange: true,
+
     // 新增数据
     waterCompany: '',
-    waterCompanyList: ['北京水务集团', '上海水务集团', '广州水务集团', '深圳水务集团', '杭州水务集团'],
+    waterCompanyList: app.globalData.waterCompanys,
+    //当前用户的默认水务公司的下标
     waterCompanyIndex: [0],
+    waterCompanyId: app.globalData.launchPara,
     showWaterCompanyPicker: false,
-    tempWaterCompanyIndex: [0],
     
     huHao: '',
     huMing: '',
@@ -102,9 +105,10 @@ Page({
 
   // 显示水站公司选择器
   showWaterCompanyPicker: function() {
+    
     this.setData({
       showWaterCompanyPicker: true,
-      tempWaterCompanyIndex: this.data.waterCompanyIndex
+      waterCompanyIndex: this.data.waterCompanyIndex
     });
   },
 
@@ -117,17 +121,19 @@ Page({
 
   // 水站公司选择变化
   onWaterCompanyChange: function(e) {
+    
     this.setData({
-      tempWaterCompanyIndex: e.detail.value
+      waterCompanyIndex: e.detail.value
     });
   },
 
   // 确认水站公司选择
-  confirmWaterCompany: function() {
-    const index = this.data.tempWaterCompanyIndex[0];
+  confirmWaterCompany: function(e) {
+    
+    const index = this.data.waterCompanyIndex[0];
     this.setData({
-      waterCompanyIndex: this.data.tempWaterCompanyIndex,
-      waterCompany: this.data.waterCompanyList[index],
+      waterCompanyIndex: this.data.waterCompanyIndex,
+      waterCompany: this.data.waterCompanyList[index].name,
       showWaterCompanyPicker: false
     });
   },
@@ -183,22 +189,48 @@ Page({
     wx.showLoading({
       title: '绑定中...',
     });
-
-    // 模拟API调用
-    setTimeout(() => {
-      wx.hideLoading();
-      wx.showToast({
-        title: '绑定成功',
-        icon: 'success',
-        duration: 2000,
-        success: () => {
-          // 绑定成功后跳转
-          setTimeout(() => {
-            wx.navigateBack();
-          }, 2000);
+    // 调用绑定接口
+    wx.request({
+      url: app.globalData.interfaceUrls.accoundBind,
+      method: 'POST',
+      data: {
+        bindWaterCompany: this.data.waterCompanyList[this.data.waterCompanyIndex[0]].id,
+        accountNum: this.data.huHao,
+        accountName: this.data.huMing,
+        groupType: groupInfo,
+        openId: app.globalData.userWxInfo.openId,
+        defaultAccount: 0,
+        otherDsKey: (app.globalData.bindAccountInfo||[]).map(data=>data.dsKey)
+      },
+      header: {
+        'content-type': 'application/json', // 默认值
+        'token':app.globalData.userWxInfo.token,
+        'source':"wc",
+        '!SAAS_LOGIN_TOKEN_!':this.data.waterCompanyList[this.data.waterCompanyIndex[0]].id
+      },
+      success (res) {
+        wx.hideLoading();
+        let apiReturnData=res.data
+        if(apiReturnData.code=='200'){
+          wx.hideLoading();
+          utils.simleInfo('绑定成功')
+          setTimeout(function(){
+            wx.switchTab({
+              url: '/pages/homepage/homepage',
+            })
+          },2000)
+        }else{
+          wx.showToast({
+            title: apiReturnData.msg,
+            icon: 'error',
+            duration: 2000
+          })
         }
-      });
-    }, 1500);
+      },fail(error) {
+        wx.hideLoading()
+        utils.simleInfo('登录失败,请稍后再试')
+      }
+    })
   },
 
   onLoad: function() {
@@ -207,12 +239,18 @@ Page({
       wx.setNavigationBarTitle({
         title: '户号绑定'
       });
-      
       wx.setNavigationBarColor({
         frontColor: '#ffffff',
         backgroundColor: '#0066FF'
       });
     }, 100);
+    if(app.globalData.launchPara){
+      this.setData({
+        waterCompanyIndex:[app.globalData.waterCompanys.findIndex(data=>data.id==app.globalData.launchPara)],
+        waterCompany: app.globalData.waterCompanys.filter(data=>data.id==app.globalData.launchPara)[0].name,
+        isChange:false,
+      });
+    }
   },
 
   // 添加返回方法

+ 14 - 5
pages/huhaobangding/huhaobangding.wxml

@@ -9,10 +9,19 @@
   <view class="form-group1">
     <view class="form-item">
       <text class="label">水站公司<text class="required">*</text></text>
-      <view class="picker-container" bindtap="showWaterCompanyPicker">
-        <text class="picker-text">{{waterCompany || '请选择水站公司'}}</text>
-        <view class="arrow-right"></view>
+      <block wx:if="{{isChange}}">
+        <view class="picker-container" bindtap="showWaterCompanyPicker">
+          <text style="color: black;" class="picker-text">{{waterCompany || '请选择水站公司'}}</text>
+          <view class="arrow-right">
+        </view>
       </view>
+      </block>
+      <block wx:else>
+        <view class="picker-container" >
+          <text style="color: black;" class="picker-text">{{waterCompany || '请选择水站公司'}}</text>
+        </view>
+      </block>
+    
     </view>
   </view>
 
@@ -73,8 +82,8 @@
     <view class="picker-confirm" bindtap="confirmWaterCompany">确定</view>
   </view>
   <picker-view class="water-company-picker" indicator-style="height: 50px;" value="{{waterCompanyIndex}}" bindchange="onWaterCompanyChange">
-    <picker-view-column>
-      <view wx:for="{{waterCompanyList}}" wx:key="index" class="picker-item">{{item}}</view>
+    <picker-view-column> 
+      <view wx:for="{{waterCompanyList}}" wx:key="index" class="picker-item">{{item.name}}</view>
     </picker-view-column>
   </picker-view>
 </view>

+ 4 - 4
pages/lijijiaofei/lijijiaofei.wxml

@@ -31,7 +31,7 @@
           <text class="amount-value">{{amount}}</text>
           <text class="amount-unit">元</text>
         </view>
-        
+
         <!-- 余额显示 -->
         <view class="balance-info">
           <text class="balance-label">应缴金额:</text>
@@ -39,7 +39,7 @@
           <text class="balance-label margin-left">余额:</text>
           <text class="balance-value">{{balance}} </text><text class="balance-unit">元</text>
         </view>
-        
+
         <view class="quick-amount">
           <view class="amount-btn {{selectedAmount == 10 ? 'selected' : ''}}" bindtap="selectAmount" data-amount="10">10元</view>
           <view class="amount-btn {{selectedAmount == 30 ? 'selected' : ''}}" bindtap="selectAmount" data-amount="30">30元</view>
@@ -49,7 +49,7 @@
           <view class="amount-btn {{selectedAmount == 500 ? 'selected' : ''}}" bindtap="selectAmount" data-amount="500">500元</view>
           <view class="custom-input-container {{customAmount || inputFocus ? 'selected' : ''}}">
             <text class="yuan-symbol">¥</text>
-            <input class="custom-amount-input" type="digit" bindinput="onCustomAmountInput" 
+            <input class="custom-amount-input" type="digit" bindinput="onCustomAmountInput"
                    value="{{customAmount}}" placeholder="自定义金额"
                    bindfocus="onInputFocus" bindblur="onInputBlur"/>
           </view>
@@ -90,4 +90,4 @@
         <view class="key" bindtap="inputNumber" data-number=".">.</view>
       </view>
     </view>
-</view> 
+</view>

+ 14 - 2
project.private.config.json

@@ -3,7 +3,7 @@
   "projectname": "zhsw_wechat",
   "setting": {
     "compileHotReLoad": true,
-    "urlCheck": true,
+    "urlCheck": false,
     "coverView": true,
     "lazyloadPlaceholderEnable": false,
     "skylineRenderEnable": false,
@@ -20,5 +20,17 @@
     "bigPackageSizeSupport": false
   },
   "libVersion": "3.7.9",
-  "condition": {}
+  "condition": {
+    "miniprogram": {
+      "list": [
+        {
+          "name": "pages/homepage/homepage",
+          "pathName": "pages/homepage/homepage",
+          "query": "deskey=zhsw00001",
+          "launchMode": "default",
+          "scene": null
+        }
+      ]
+    }
+  }
 }

+ 23 - 2
utils/util.js

@@ -13,7 +13,28 @@ const formatNumber = n => {
   n = n.toString()
   return n[1] ? n : `0${n}`
 }
-
+const simleInfo = msg => {
+  wx.showModal({
+    title: '提示',
+    content: msg,
+    showCancel: false,
+    success(res) {
+    }
+  })
+}
+const simleInfoWithBack = msg => {
+  wx.showModal({
+    title: '提示',
+    content: msg,
+    showCancel: false,
+    success(res) {
+      wx.navigateBack({})
+    }
+  })
+}
 module.exports = {
-  formatTime
+  simleInfo: simleInfo,
+  simleInfoWithBack: simleInfoWithBack,
+  formatNumber: formatNumber,
+  formatTime: formatTime,
 }