浏览代码

油卡充值逻辑完善

xiaohuangmao 4 年之前
父节点
当前提交
cb677bc1dc
共有 8 个文件被更改,包括 76 次插入41 次删除
  1. 4 0
      app.js
  2. 1 1
      app.json
  3. 1 1
      pages/auth/auth.wxml
  4. 28 5
      pages/myhome/myhome.js
  5. 7 6
      pages/myhome/myhome.wxml
  6. 3 1
      pages/myhome/myhome.wxss
  7. 31 26
      pages/postage/postage.js
  8. 1 1
      pages/postage/postage.wxml

+ 4 - 0
app.js

@@ -54,4 +54,8 @@ App({
     clearRecord() {
         this.globalData.record = null
     },
+    getValueByKey(key = '', data = []){
+        if(!data.length) return {}
+        return data.filter(val => val.card_type === key)[0] || {}
+    },
 })

+ 1 - 1
app.json

@@ -1,10 +1,10 @@
 {
   "pages": [
     "pages/postage/postage",
+    "pages/myhome/myhome",
     "pages/postageManage/postageManage",
     "pages/postageDetail/postageDetail",
     "pages/index/index",
-    "pages/myhome/myhome",
     "pages/address/address",
     "pages/phoneCharges/phoneCharges",
     "pages/discover/discover",

+ 1 - 1
pages/auth/auth.wxml

@@ -1,2 +1,2 @@
 <!--pages/auth.wxml-->
-<auth bind:getAuth="getAuth"></auth>
+<auth wx:if="!userinfo" bind:getAuth="getAuth"></auth>

+ 28 - 5
pages/myhome/myhome.js

@@ -1,13 +1,17 @@
 // pages/myhome/myhome.js
+const config = require('../../config.js')
+const getReq = config.getReq
+let appInstance = getApp();
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-    personInfo: {
-      avtor: '/image/myhome/avtor.jpg', nickname: '燕子', weixin: 'xiaoyanzi', money: 500, postage: '31451345315', phone: '13122223333'
-    }
+    memberInfo: {},
+    sinopec:{},
+    petrochina:{},
+    phone: {}
   },
 
   handleMore(e) {
@@ -21,7 +25,7 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-
+    
   },
 
   /**
@@ -35,7 +39,26 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function () {
-
+    getReq({
+      act: 'member_info',
+      op: 'index',
+      page_type: 'oil'
+    }, (res) => {
+      this.setData({
+        firstLoad: false
+      });
+      if (res.code == 200) {
+        if(res.datas) {
+          const { cards, sub_titles } = res.datas
+          const phone = appInstance.getValueByKey('phone', cards)
+          const petrochina = appInstance.getValueByKey('petrochina', cards)
+          const sinopec = appInstance.getValueByKey('sinopec', cards)
+          this.setData({ memberInfo: {...res.datas}, phone, petrochina, sinopec })
+        }
+      } else {
+        appInstance.showToast(res.message)
+      }
+    })
   },
 
   /**

+ 7 - 6
pages/myhome/myhome.wxml

@@ -2,11 +2,11 @@
 <view class="myhome-wrp">
   <view class="topbg"></view>
   <view class="header">
-    <image src="{{personInfo.avtor}}" class="avtor"></image>
+    <image src="{{memberInfo.member_avatar}}" class="avtor"></image>
     <view class="info">
-      <text class="nickname">{{personInfo.nickname}}</text>
-      <text class="weixin">微信号: {{personInfo.weixin}}</text>
-      <text class="other">已经为您节省 <text class="money">{{personInfo.money}}</text> 元</text>
+      <text class="nickname">{{memberInfo.member_nickname}}</text>
+      <!-- <text class="weixin">微信号: {{memberInfo.weixin}}</text> -->
+      <text class="other">余额还剩 <text class="money">{{memberInfo.vip_left_amount}}</text> 元</text>
     </view>
   </view>
 
@@ -17,7 +17,8 @@
       <image src="/image/myhome/arrow-right.png" class="more"></image>
     </view>
     <view class="card-body">
-      <view class="card-item bg-orange">{{personInfo.postage}}</view>
+      <view wx:if="{{petrochina.card_type==='petrochina'}}" class="card-item bg-orange">{{petrochina.card_no}}</view>
+      <view wx:if="{{sinopec.card_type==='sinopec'}}" class="card-item bg-orange">{{sinopec.card_no}}</view>
     </view>
   </view>
 
@@ -28,7 +29,7 @@
       <image src="/image/myhome/arrow-right.png" class="more"></image>
     </view>
     <view class="card-body">
-      <view class="card-item bg-blue">{{personInfo.phone}}</view>
+      <view wx:if="{{phone.card_type==='phone'}}" class="card-item bg-blue">{{phone.card_no}}</view>
     </view>
   </view>
 </view>

+ 3 - 1
pages/myhome/myhome.wxss

@@ -32,6 +32,7 @@
 .header .info{
   display: flex;
   flex-direction: column;
+  justify-content: center;
   flex: 1;
 }
 
@@ -91,10 +92,11 @@
   height: 50rpx;
 }
 .card-body{
-  padding: 20rpx 20rpx 40rpx;
+  padding: 0 20rpx 20rpx;
 }
 .card-item{
   padding: 30rpx;
+  margin: 20rpx 0;
   border-radius: 15rpx;
   color: #fff;
 }

+ 31 - 26
pages/postage/postage.js

@@ -3,7 +3,7 @@ const config = require('../../config.js')
 const getReq = config.getReq
 const buyVGoods = config.buyVGoods
 
-let app = getApp();
+let appInstance = getApp();
 Page({
 
   /**
@@ -15,12 +15,12 @@ Page({
     tips:'',      //顶部tips
     goods:[],     //挡位数据
     goods_id:'',  //当前选中挡位的goods_id
-
-    // card_type: 'sinopec', //油卡类型 (中石化/中石油)
-    // card_no: '',          //油卡号
-    // cards: [],
+    card_type: 'sinopec', //油卡类型 (中石化/中石油)
+    card_no: '',          //油卡号
+    cards: [],
     sinopec: {},
     petrochina: {},    
+    phone: {},
     firstLoad: true,
 
     tabsData: [
@@ -35,9 +35,17 @@ Page({
     var dataset = e.currentTarget.dataset
     const { activeindex, cardtype } = dataset
     const { cards } = this.data
+    const card = appInstance.getValueByKey(cardtype ,cards)
+    const { card_no, card_type } = card
+    if(card_type === 'sinopec'){
+      this.setData({ sinopec: { ...this.data.sinopec, card_no } })
+    }else if(card_type === 'petrochina'){
+      this.setData({ petrochina: { ...this.data.petrochina, card_no } })
+    }
     this.setData({
-      currentIndex: dataset.activeindex,
-      card_no: this.getValueBykey(cardtype ,cards).card_no
+      currentIndex: activeindex,
+      card_no,
+      card_type
     });
   },
 
@@ -63,9 +71,9 @@ Page({
    */
   onLoad: function (options) 
   {    
-    let fromSource = recordSource(app, `act=index&op=card_goods`)
+    let fromSource = recordSource(appInstance, `act=index&op=card_goods`)
     this.setData({
-      fromSource: app.globalData.fromSource,
+      fromSource: appInstance.globalData.fromSource,
       // card_no: this.data.tabsData[0].card_no
     });
 
@@ -82,31 +90,23 @@ Page({
         if(res.datas && res.datas.goods){
           const datas = res.datas
           const { tips = '', goods = [], cards = [], } = datas
-          const sinopec = this.getValueBykey('sinopec', cards)
-          const petrochina = this.getValueBykey('petrochina', cards)          
-          this.setData({ tips, goods, cards, sinopec, petrochina, card_no: sinopec.card_no, goods_id: datas.goods[0].goods_id });
+          const phone = appInstance.getValueByKey('phone', cards)
+          const petrochina = appInstance.getValueByKey('petrochina', cards)
+          const sinopec = appInstance.getValueByKey('sinopec', cards)   
+          this.setData({ tips, goods, cards, sinopec, petrochina, phone, card_no: sinopec.card_no, goods_id: datas.goods[0].goods_id });
         }
       } else {
-        app.showToast(res.message)
+        appInstance.showToast(res.message)
       }
     })
   },
-  // 通过键取值
-  getValueBykey(key = '', data = [])
-  {
-    if(!data.length) {
-      return {};
-    }
-    else {
-      return data.filter(val => val.card_type === key);
-    }
-  },
 
   // 立即充值
   handlerRecharge(){
+    console.table(this.data)
     const { goods_id, card_no, card_type } = this.data
     if(!card_no){
-      app.showToast('卡号不能为空')
+      appInstance.showToast('卡号不能为空')
       return
     }
     buyVGoods(goods_id,1,{ card_no,card_type }, (res) => {
@@ -129,10 +129,15 @@ Page({
    */
   onShow: function () {
     if(!this.data.firstLoad) {
-      const record = app.globalData.record || {}
+      const record = appInstance.globalData.record || {}
       const { card_no = '', card_type = '' } = record
-      app.setFromSource(this.data.fromSource)
+      appInstance.setFromSource(this.data.fromSource)
       if (record) {
+        if(card_type === 'sinopec'){
+          this.setData({ sinopec: { ...this.data.sinopec, card_no } })
+        }else if(card_type === 'petrochina'){
+          this.setData({ petrochina: { ...this.data.petrochina, card_no } })
+        }
         this.setData({ card_no, card_type })
       }
     }

+ 1 - 1
pages/postage/postage.wxml

@@ -6,7 +6,7 @@
       <view class="tabs-title-item {{currentIndex == index ? 'active' : ''}}" wx:for="{{tabsData}}" wx:key="index" 
       bindtap="handlerClickTabItem" data-activeindex="{{index}}" data-cardType="{{item.card_type}}">
         <image class="tabs-title-item__icon" src="{{item.icon}}"></image>
-        <text class="tabs-title-item__text">{{item.title}}</text>
+        <text class="tabs-title-item__text">{{ item.title}}</text>
       </view>
     </view>
     <view class="tabs-content" wx:for="{{tabsData}}" wx:key="index"  style='display:{{currentIndex !== index ? "none" : "block"}}'>