You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
2.7 KiB
JavaScript

const app = getApp();
const card = require('../../utils/card.js');
Page({
/**
* 页面的初始数据
*/
data: {
totalPoint: "0.0",
couponsList: [],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
this.setData({
totalPoint: app.cardInfo.totalPoint,
})
// 查询优惠券方案
this.cy_couponScheme();
},
/**
*
*/
cy_pointExchange: function(e) {
var index = e.currentTarget.dataset.index;
var map = this.data.list[index];
var url = "detail?json=" + JSON.stringify(map);
wx.navigateTo({
url: url,
})
},
/**
* 查询兑换优惠券
*/
cy_couponScheme: function(e) {
var that = this;
var type = 1;
var params = {
"method": "elec.coupon.exchange.scheme",
"wid": app.memberWid,
"type": type
}
var ignores = [];
app.jsapi.memberApi(app.globalData.appMemberKey, app.globalData.appMemberSecret, app.globalData.serverMemberUrl).ajax(params, ignores,
function(json) {
var result = json.data;
if (result.status == 1) {
that.setData({
list: result.list,
});
} else {
wx.showToast({
title: '暂无积分兑换方案,敬请期待',
icon: "none"
})
}
},
function(error) {
wx.showToast({
title: '暂无积分兑换方案,敬请期待',
icon: "none"
})
}
);
},
/**
*
*/
cy_leadCoupon: function(e) {
var that = this;
var index = e.currentTarget.dataset.index;
var tempCoupon = that.data.couponsList[index];
var schemeId = tempCoupon.id;
var memberId = app.memberId;
var params = {
"method": "elec.coupon.exchange",
"schemeId": schemeId,
"memberId": memberId,
"number": 1,
"shopNo": app.shopNo,
"posNo": app.posNo,
"workerNo": app.workerNo,
"sourceSign": app.sourceSign
};
console.log("参数", params);
var ignores = [];
app.jsapi.memberApi(app.globalData.appMemberKey, app.globalData.appMemberSecret, app.globalData.serverMemberUrl).ajax(params, ignores,
function(json) {
console.log("优惠券兑换方案", json);
var result = json.data;
if (result.status == 1) {
that.setData({
point: 100
});
wx.showToast({
title: '兑换成功',
icon: 'success', //图标,支持"success"、"loading"
})
} else {
wx.showModal({
title: '提示',
content: result.errMessage,
})
}
},
function(error) {
console.log(error);
}
);
},
})