|
@@ -17,6 +17,9 @@ Page({
|
|
|
goods_id:'', //当前选中挡位的goods_id
|
|
|
card_type: 'sinopec', //油卡类型 (中石化/中石油)
|
|
|
card_no: '', //油卡号
|
|
|
+ cards: [],
|
|
|
+ sinopec: {},
|
|
|
+ petrochina: {},
|
|
|
firstLoad: true,
|
|
|
tabsData: [
|
|
|
{ id: 0, icon: '/image/postage/sinopec.png', title: '中国石化', tips: '选择油卡', card_type: 'sinopec', card_no: '' },
|
|
@@ -28,9 +31,11 @@ Page({
|
|
|
// 页签切换
|
|
|
handlerClickTabItem(e) {
|
|
|
var dataset = e.currentTarget.dataset
|
|
|
+ const { activeindex, cardtype } = dataset
|
|
|
+ const { cards } = this.data
|
|
|
this.setData({
|
|
|
currentIndex: dataset.activeindex,
|
|
|
- card_no: dataset.cardno
|
|
|
+ card_no: this.getValueBykey(cardtype ,cards).card_no
|
|
|
});
|
|
|
},
|
|
|
|
|
@@ -56,47 +61,41 @@ Page({
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
+
|
|
|
let fromSource = recordSource(app, `act=index&op=card_goods`)
|
|
|
this.setData({
|
|
|
fromSource: app.globalData.fromSource,
|
|
|
- card_no: this.data.tabsData[0].card_no
|
|
|
+ // card_no: this.data.tabsData[0].card_no
|
|
|
});
|
|
|
- var self = this;
|
|
|
getReq({
|
|
|
act: 'index',
|
|
|
op: 'card_goods',
|
|
|
page_type: 'oil',
|
|
|
from: fromSource
|
|
|
- }, function (res) {
|
|
|
- self.setData({
|
|
|
+ }, (res) => {
|
|
|
+ this.setData({
|
|
|
firstLoad: false
|
|
|
});
|
|
|
if (res.code == 200) {
|
|
|
if(res.datas && res.datas.goods){
|
|
|
- var datas = res.datas
|
|
|
- self.setData({
|
|
|
- tips: datas.tips,
|
|
|
- goods: datas.goods,
|
|
|
- goods_id: datas.goods[0].goods_id
|
|
|
- });
|
|
|
+ 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 });
|
|
|
}
|
|
|
- }else {
|
|
|
- wx.showToast({
|
|
|
- icon: 'none',
|
|
|
- title: res.message,
|
|
|
- duration: 2000
|
|
|
- })
|
|
|
+ } else {
|
|
|
+ app.showToast(res.message)
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ // 通过键取值
|
|
|
+ getValueBykey(key = '', data = []){
|
|
|
+ return data.filter(val => val.card_type === key)[0]
|
|
|
+ },
|
|
|
|
|
|
// 立即充值
|
|
|
handlerRecharge(){
|
|
|
- // wx.showToast({
|
|
|
- // icon: 'none',
|
|
|
- // title: `goods_id: ${this.data.goods_id}, card_no: ${this.data.card_no}`,
|
|
|
- // duration: 2000
|
|
|
- // })
|
|
|
const { goods_id, card_no, card_type } = this.data
|
|
|
if(!card_no){
|
|
|
app.showToast('卡号不能为空')
|