Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
feat(currency): #457 积分充值功能
Browse files Browse the repository at this point in the history
目前只支持支付宝充值
  • Loading branch information
mutoe committed Jul 25, 2018
1 parent f1b167e commit f6e8ad8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
11 changes: 7 additions & 4 deletions src/api/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ export function getCurrencyOrders(params) {
* @param {Object} data
* @param {string} data.type 充值方式
* @param {number} data.amount 充值金额(单位:RMB分)
* @param {Object|Array} [data.extra] 拓展信息字段
* @param {number} data.from 来自哪个端 h5固定为2
* @returns
*/
export function postCurrencyRecharge(data) {
return api.post("/currency/recharge", data, {
validateStatus: s => s === 201
});
const url = "/currencyRecharge/orders";
return api.post(
url,
{ ...data, from: 2 },
{ validateStatus: s => s === 201 }
);
}

/**
Expand Down
27 changes: 14 additions & 13 deletions src/page/currency/CurrencyRecharge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ import { mapState } from "vuex";
import PopupDialog from "@/components/PopupDialog.vue";
const supportTypes = [
{ key: "alipay_wap", title: "支付宝支付" },
{ key: "wx_wap", title: "微信支付" },
{ key: "alipay_wap", title: "支付宝支付", type: "AlipayWapOrder" },
// 尚未实现 { key: "wx_wap", title: "微信支付", type: "WechatWapOrder" },
{ key: "balance", title: "钱包余额支付" }
];
Expand Down Expand Up @@ -115,7 +115,7 @@ export default {
return rule.replace(/\n/g, "<br>");
},
rechargeTypeText() {
const type = supportTypes.filter(t => t.key === this.form.type).pop();
const type = supportTypes.filter(t => t.type === this.form.type).pop();
return type && type.title;
},
form() {
Expand Down Expand Up @@ -146,7 +146,7 @@ export default {
if (this.recharge.type.includes(item.key)) {
actions.push({
text: item.title,
method: () => selectType(item.key)
method: () => selectType(item.type)
});
}
});
Expand Down Expand Up @@ -174,19 +174,20 @@ export default {
let result;
if (type === "balance") {
result = await this.$store.dispatch("currency/currency2wallet", amount);
this.loading = false;
if (!result.errors) {
this.$store.dispatch("fetchUserInfo");
this.$Message.success("充值成功!");
this.goBack();
} else {
this.$Message.error(result.errors);
}
} else {
result = await this.$store.dispatch("currency/requestRecharge", {
const url = await this.$store.dispatch("currency/requestRecharge", {
amount,
type
});
}
this.loading = false;
if (!result.errors) {
this.$store.dispatch("fetchUserInfo");
this.$Message.success("充值成功!");
this.goBack();
} else {
this.$Message.error(result.errors);
location.href = url;
}
},
popupRule() {
Expand Down
4 changes: 2 additions & 2 deletions src/stores/module/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ const actions = {
/**
* 发起充值请求
* @author mutoe <[email protected]>
* @returns {Promise<Object>}
* @returns {Promise<string>} url
*/
async requestRecharge(state, payload) {
const { data = {} } = await api.postCurrencyRecharge(payload);
const { data = "" } = await api.postCurrencyRecharge(payload);
return data;
},

Expand Down

0 comments on commit f6e8ad8

Please sign in to comment.