Ver código fonte

完善功能

eli 2 anos atrás
pai
commit
997607625c

+ 7 - 4
pages/bill/index.js

@@ -3,22 +3,25 @@ const httpUtils = require('../../utils/http.js')
 const ui = require('../../utils/ui.js')
 Page({
   data: {
-   list: [],
-   deviceid: '',
+    list: [],
+    deviceid: '',
     roomName: '',
     deviceCode: ''
   },
   deviceid: '',
   roomName: '',
   deviceCode: '',
+  balance: '',
   onLoad(options) {
     this.deviceid = options.deviceid
     this.roomName = options.roomName
     this.deviceCode = options.deviceCode
+    this.balance = options.balance
     this.setData({
       deviceid: options.deviceid,
       roomName: options.roomName,
-      deviceCode: options.deviceCode
+      deviceCode: options.deviceCode,
+      balance: options.balance
     })
     this.getList(options.deviceid)
   },
@@ -30,7 +33,7 @@ Page({
   },
   toRecharge(){
     wx.navigateTo({
-      url: '/pages/recharge/index?deviceid=' + this.deviceid
+      url: '/pages/recharge/index?deviceid=' + this.deviceid + '&roomName=' + this.roomName + '&deviceCode=' + this.deviceCode + '&balance=' + this.balance
     })
   },
   getList(id){

+ 20 - 80
pages/index/index.js

@@ -2,72 +2,33 @@ const app = getApp()
 const httpUtils = require('../../utils/http.js')
 const ui = require('../../utils/ui.js')
 Page({
-  data: {},
-  onLoad() {},
-  getPhoneNumber(e) {
-    let that = this
-    console.log("11111111111111111")
-    console.log(e)
-    let iv = e.detail.iv 
-    let encryptedData = e.detail.encryptedData
-    if(e.detail.errMsg == 'getPhoneNumber:fail user deny'){
-      wx.showToast({
-        title: '请您授权手机号,以便提供更好服务',
-        icon:'none',
-        duration:5000
+  data: {
+    tab: 1
+  },
+  onShow(){
+    if(wx.getStorageSync('token')){
+      this.setData({
+        tab: 2
+      })
+    }else{
+      this.setData({
+        tab: 1
       })
-    }else {
-      // wx.login({
-      //   success (res) {
-      //     if (res.code) {
-      //       console.log("2222222222222222")
-      //       console.log(res)
-      //       let code = res.code
-      //       // 调userinfo接口
-      //       let obj = {
-      //         url: '/api/erp/we/userInfo',
-      //         data: {
-      //           code: code
-      //         }
-      //       }
-            // httpUtils.request(obj).then(res1=>{
-            //   console.log("33333333333333")
-            //   console.log(res1)
-              //phoneinfo接口请求
-              let obj2 = {
-                url: '/api/erp/we/phoneInfo',
-                data: {
-                  encryptedData: encryptedData,
-                  iv: iv,
-                  code: wx.getStorageSync('code')
-                }
-              }
-              httpUtils.request(obj2).then(res2=>{
-                console.log("444444444444444444")
-                console.log(res2)
-                wx.setStorageSync('token', res2.data.data.token)
-                wx.setStorageSync('phone', res2.data.data.phone)
-                // 弹框提示
-                ui.showToast("登陆成功!")
-                wx.switchTab({
-                  url: '/pages/list/index',
-                })
-              }).catch(err=>{
-                console.log('ERROR')
-              });
-      //       }).catch(err=>{
-      //         console.log('ERROR')
-      //       });
-      //     }
-      //   }
-      // })
     }
   },
+  toOut(){
+    wx.removeStorageSync('token')
+    wx.removeStorageSync('phone')
+    wx.removeStorageSync('openId')
+    wx.removeStorageSync('code')
+    this.setData({
+      tab: 1
+    })
+  },
   toLogin(){
     wx.login({
       success (res) {
         if (res.code) {
-          console.log("code",res)
           let code = res.code
           wx.setStorageSync('code', res.code)
           // 调userinfo接口
@@ -83,27 +44,6 @@ Page({
             wx.navigateTo({
               url: '/pages/submitPhone/index',
             })
-            // wx.setStorageSync('token', res2.data.data.token)
-            // phoneinfo接口请求
-            // let obj = {
-            //   url: '/api/erp/we/phoneInfo',
-            //   data: {
-            //     encryptedData: 'B',
-            //     iv: '1',
-            //     code: code
-            //   }
-            // }
-            // httpUtils.request(obj).then(res2=>{
-            //   wx.setStorageSync('token', res2.data.data.token)
-            //   // wx.setStorageSync('phone', res2.data.data.phone)
-            //   // 弹框提示
-            //   ui.showToast("登陆成功!")
-            //   wx.navigateTo({
-            //     url: '/pages/submitPhone/index',
-            //   })
-            // }).catch(err=>{
-            //   console.log('ERROR')
-            // });
           }).catch(err=>{
             console.log('ERROR')
           });

+ 4 - 6
pages/index/index.wxml

@@ -1,9 +1,7 @@
 <view class="container">
   <view class="title">电费充值系统</view>
-  <view class="btn_box" bindtap="toLogin">微信授权登陆</view>
-  <!-- <input type="text" placeholder="请输入手机号码"/>
-  <button>提交</button> -->
-  <!-- <button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">授权手机号码</button> -->
-
-  
+  <image class="img-style" src="/utils/images/home-img1.jpeg"></image>
+  <image class="img-style" src="/utils/images/home-img2.jpeg"></image>
+  <view  class="btn_box" wx-if="{{tab == 1}}" bindtap="toLogin">微信授权登陆</view>
+  <view class="btn_box" wx-if="{{tab == 2}}" bindtap="toOut">更换账号登陆</view>
 </view>

+ 11 - 2
pages/index/index.wxss

@@ -1,9 +1,18 @@
+.container{
+  padding: 0;
+}
 .title{
   text-align: center;
-  margin-top: 30px;
   font-size: 18px;
   font-weight: bold;
   color: #222;
+  margin-top: 30px;
+}
+.img-style{
+  width: 100%;
+  height: 150px;
+  display: block;
+  margin-bottom: 10px;
 }
 .btn_box{
   width: 90%;
@@ -16,5 +25,5 @@
   border-radius: 3px;
   line-height: 35px;
   position: absolute;
-  bottom: 100px;
+  bottom: 50px;
 }

+ 10 - 3
pages/list/index.js

@@ -5,16 +5,23 @@ Page({
   data: {
    list: []
   },
-  onLoad() {
-    this.getList()
+  onShow(){
+    if(wx.getStorageSync('token')){
+      this.getList()
+    }else{
+      wx.switchTab({
+        url: '/pages/index/index',
+      })
+    }
   },
   toUrl(e){
     console.log(e)
     let deviceid = e.currentTarget.dataset.deviceid
     let roomName = e.currentTarget.dataset.roomname
     let deviceCode = e.currentTarget.dataset.devicecode
+    let balance = e.currentTarget.dataset.balance
     wx.navigateTo({
-      url: '/pages/bill/index?deviceid=' + deviceid + '&roomName=' + roomName + '&deviceCode=' + deviceCode
+      url: '/pages/bill/index?deviceid=' + deviceid + '&roomName=' + roomName + '&deviceCode=' + deviceCode + '&balance=' + balance
     })
   },
   getList(){

+ 1 - 1
pages/list/index.wxml

@@ -1,5 +1,5 @@
 <view class="container_list">
-  <view class="list" bindtap="toUrl" wx:for="{{list}}" wx:key="index" data-deviceId="{{item.deviceId}}" data-roomName="{{item.roomName}}" data-deviceCode="{{item.deviceCode}}">
+  <view class="list" bindtap="toUrl" wx:for="{{list}}" wx:key="index" data-deviceId="{{item.deviceId}}" data-roomName="{{item.roomName}}" data-deviceCode="{{item.deviceCode}}" data-balance = "{{item.balance}}">
     <view class="list-left">
       <view class="list-inner">
         <p class="house">{{index + 1}}.{{item.roomName}}</p>

+ 51 - 11
pages/recharge/index.js

@@ -4,11 +4,32 @@ const ui = require('../../utils/ui.js')
 Page({
   data: {
     tab: 1,
-    money: 100
+    money: 100,
+    deviceid: '',
+    roomName: '',
+    deviceCode: '',
+    balance: ''
   },
   deviceid: '',
+  roomName: '',
+  deviceCode: '',
+  balance: '',
   onLoad(options) {
+    this.setData({
+      deviceid: options.deviceid,
+      roomName: options.roomName,
+      deviceCode: options.deviceCode,
+      balance: options.balance
+    })
     this.deviceid = options.deviceid
+    this.roomName = options.roomName
+    this.deviceCode = options.deviceCode
+    this.balance = options.balance
+  },
+  getInputName(e){
+    this.setData({
+      money: e.detail.value
+    })
   },
   changeTab(e){
     console.log(e)
@@ -30,34 +51,53 @@ Page({
     }
   },
   toRecharge(){
+    let that = this
     let obj = {
       url: '/api/erp/we/wePhoneCharge',
       data: {
-        deviceId: this.deviceid,
-        deposit: 1,
+        deviceId: that.deviceid,
+        deposit: that.data.money,
         token: wx.getStorageSync('token'),
       }
     }
     httpUtils.request(obj).then(res=>{
       console.log("pay",res)
       let payInfo = res.data.data
-
       // 调取后端接口后微信下单
       wx.requestPayment({
-        timeStamp: payInfo.timeStamp,
-        nonceStr: payInfo.nonceStr,
-        package: payInfo.package,
-        signType: payInfo.signType,
-        paySign: payInfo.paySign,
+        timeStamp:payInfo.timeStamp,
+        nonceStr:payInfo.nonceStr,
+        package:payInfo.package,
+        signType:payInfo.signType,
+        paySign:payInfo.paySign,
         success (res1) {
           console.log("支付",res1)
+          if(res1.errMsg == 'requestPayment:ok'){
+            wx.showToast({
+              title: '支付成功!',
+              icon: 'success',
+              duration: 2000
+            })
+            wx.navigateTo({
+              url: '/pages/record/index?deviceid=' + that.deviceid + '&roomName=' + that.roomName + '&deviceCode=' + that.deviceCode
+            })
+          }
         },
         fail (res1) { 
-
+          wx.showToast({
+            title: '支付失败!',
+            icon: 'error',
+            duration: 2000
+          })
         }
       })
     }).catch(err=>{
-      console.log('ERROR')
+      console.log(err)
+      wx.showToast({
+        title: "创建订单失败!",
+        icon: 'error',
+        duration: 2000
+      })
     });
   }
 })

+ 4 - 4
pages/recharge/index.wxml

@@ -1,13 +1,13 @@
 <view class="container_bill">
   <view class="bill_top">
-    <p class="top_style">房号:二区1栋3楼201</p>
-    <p class="top_style">表号:1325346576</p>
+    <p class="top_style">房号:{{roomName}}</p>
+    <p class="top_style">表号:{{deviceCode}}</p>
   </view>
   <view class="bill_top">
-    <p class="top_style">余额:100</p>
+    <p class="top_style">余额:{{balance}}</p>
   </view>
   <view class="input_box">
-    <input class="input_style" type="text"/>
+    <input class="input_style" bindinput='getInputName' type="number" placeholder="请输入充值金额"/>
   </view>
   <view class="money_num">
     <view class="num_inner {{ tab == 1? 'blue_style':'' }}" data-info="{{1}}" bindtap="changeTab">100</view>

+ 10 - 7
pages/submitPhone/index.js

@@ -2,13 +2,16 @@ const app = getApp()
 const httpUtils = require('../../utils/http.js')
 const ui = require('../../utils/ui.js')
 Page({
-  data: {},
-  onLoad() {},
-  
-  formSubmit(e) {
-    console.log(e)
-    let phoneNumber= e.detail.value.phoneNumber;
-    console.log("phoneNumber",phoneNumber)
+  data: {
+    phone: ''
+  },
+  getInputName(e){
+    this.setData({
+      phone: e.detail.value
+    })
+  },
+  toSubmit() {
+    let phoneNumber = this.data.phone;
     let obj = {
       url: '/api/erp/we/phoneInfo',   
       data: {

+ 2 - 7
pages/submitPhone/index.wxml

@@ -1,9 +1,4 @@
 <view class="container">
-  <!-- <view> 手机号码:</view>
-  <input type="text" name="name" placeholder="请输入手机号码"/>
-  <button bindtap="toSubmit">提交</button> -->
-  <form bindsubmit="formSubmit">
-    <input type="text" name="phoneNumber" placeholder="请输入手机号码" />
-    <button formType="submit">提交</button>
-  </form>
+    <input class="input_style" type="number" bindinput='getInputName' placeholder="请输入手机号码" />
+    <view class="btn_box" bindtap="toSubmit">提交</view>
 </view>

+ 25 - 0
pages/submitPhone/index.wxss

@@ -0,0 +1,25 @@
+.container{
+  width: 100%;
+}
+.input_style{
+  width: 300px;
+  height: 35px;
+  margin: 0 auto;
+  background: #efefef;
+  border-radius: 3px;
+  box-sizing: border-box;
+  padding: 2px 5px;
+  margin-top: 10px;
+  margin-bottom: 100px;
+}
+.btn_box{
+  width: 300px;
+  margin: 0 auto;
+  background: #1296db;
+  color: #ffffff;
+  font-size: 14px;
+  text-align: center;
+  height: 35px;
+  border-radius: 3px;
+  line-height: 35px;
+}

BIN
utils/images/home-img1.jpeg


BIN
utils/images/home-img2.jpeg