|
@@ -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 })
|
|
|
}
|
|
|
}
|