支付
This commit is contained in:
parent
3c7c403983
commit
09b93532f1
39
common/server/mall.js
Normal file
39
common/server/mall.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
import RequestManager from '../request';
|
||||
import common from '../common';
|
||||
|
||||
/**
|
||||
* 获取钻石商品列表
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export const getDiamondList = async () => {
|
||||
const res = await RequestManager.get('/get_diamond_list');
|
||||
if (res.status == 1) {
|
||||
return res.data;
|
||||
} else {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 创建钻石订单
|
||||
* @param {String} productId
|
||||
* @returns
|
||||
*/
|
||||
export const createOrderProducts = async (productId) => {
|
||||
const res = await RequestManager.get('/createOrderProducts', { product_id: productId });
|
||||
if (res.status == 1) {
|
||||
return res.data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单状态
|
||||
* @returns
|
||||
*/
|
||||
export const getDiamondOrderLog = async (order_num) => {
|
||||
const res = await RequestManager.get('/get_diamond_order_log', { order_num });
|
||||
return res;
|
||||
}
|
||||
18
common/server/user.js
Normal file
18
common/server/user.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
import RequestManager from '../request';
|
||||
import common from '../common';
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export const getUserInfo = async () => {
|
||||
const res = await RequestManager.get('/userInfo');
|
||||
if (res.status == 1) {
|
||||
res.data.money = common.removeTrailingZeros(res.data.money);
|
||||
res.data.integral = common.removeTrailingZeros(res.data.integral);
|
||||
res.data.money2 = common.removeTrailingZeros(res.data.money2);
|
||||
return res.data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<image :src="$img1('my/ic_diamond.png')" style="width: 167.25rpx; height: 213rpx;" mode=""></image>
|
||||
|
||||
<text style="color: black; font-size: 64rpx;">0</text>
|
||||
<text style="color: black; font-size: 64rpx;">{{userInfo.money}}</text>
|
||||
|
||||
<text style="color: #A6A6A6; font-size: 24rpx;">我的钻石</text>
|
||||
</view>
|
||||
|
|
@ -20,7 +20,9 @@
|
|||
<view class="grid-container">
|
||||
<view class="grid-item" @click="goodsClick(index)" v-for="(item, index) in dataList" :key="index"
|
||||
style="">
|
||||
<image :src="currentIndex==index? $img1(item.goodUrlS):$img1(item.goodUrl)">
|
||||
<image v-show="currentIndex==index" :src="item.select_image">
|
||||
</image>
|
||||
<image v-show="currentIndex!=index" :src="item.image">
|
||||
</image>
|
||||
</view>
|
||||
</view>
|
||||
|
|
@ -32,7 +34,7 @@
|
|||
<image :src="$img1('my/ic_alipay.png')" style="width: 320rpx; height: 96rpx;" mode=""></image>
|
||||
</view>
|
||||
|
||||
<view class="center" style="width: 686rpx; height: 92rpx; margin: 46rpx auto 0; background-color: #333333; border-radius: 16rpx;">
|
||||
<view class="center" style="width: 686rpx; height: 92rpx; margin: 46rpx auto 0; background-color: #333333; border-radius: 16rpx;" @click="pay">
|
||||
<text style="color: #CDEF27; font-size: 24rpx;">确认支付</text>
|
||||
</view>
|
||||
|
||||
|
|
@ -41,39 +43,85 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { getUserInfo } from '@/common/server/user';
|
||||
import {getDiamondList,createOrderProducts,getDiamondOrderLog} from '@/common/server/mall';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
currentIndex: 0,
|
||||
dataList: [{
|
||||
goodUrl: "my/ic_goods.png",
|
||||
goodUrlS: "my/ic_goods_s.png",
|
||||
price: "2百"
|
||||
}, {
|
||||
goodUrl: "my/ic_goods.png",
|
||||
goodUrlS: "my/ic_goods_s.png",
|
||||
price: "2百"
|
||||
}, {
|
||||
goodUrl: "my/ic_goods.png",
|
||||
goodUrlS: "my/ic_goods_s.png",
|
||||
price: "2百"
|
||||
}, {
|
||||
goodUrl: "my/ic_goods.png",
|
||||
goodUrlS: "my/ic_goods_s.png",
|
||||
price: "2百"
|
||||
}, {
|
||||
goodUrl: "my/ic_goods.png",
|
||||
goodUrlS: "my/ic_goods_s.png",
|
||||
price: "2百"
|
||||
}, ]
|
||||
dataList: [],
|
||||
userInfo:{
|
||||
money:0
|
||||
},
|
||||
order_num:"",
|
||||
}
|
||||
},
|
||||
onLoad(options){
|
||||
this.load();
|
||||
this.$platform.getOrderNo().then(order_num => {
|
||||
console.log("order_num", order_num);
|
||||
if (order_num != null && order_num != "") {
|
||||
this.getPrizeLog(order_num);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
||||
|
||||
/**
|
||||
* 加载
|
||||
*/
|
||||
async load(){
|
||||
const res= await getUserInfo();
|
||||
if(res!=null){
|
||||
this.userInfo=res;
|
||||
}
|
||||
const diamondList= await getDiamondList();
|
||||
if(diamondList!=null){
|
||||
console.log(diamondList);
|
||||
|
||||
this.dataList=diamondList;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
goodsClick(index) {
|
||||
this.currentIndex = index;
|
||||
},
|
||||
/**
|
||||
* 支付
|
||||
*/
|
||||
async pay(){
|
||||
let pro= this.dataList[this.currentIndex];
|
||||
console.log(pro);
|
||||
const res= await createOrderProducts(pro.products_id);
|
||||
console.log(res);
|
||||
this.order_num= res.order_num;
|
||||
const status = await this.$platform.pay({ data: res.res });
|
||||
if (status == 'success') {
|
||||
this.getPrizeLog(res.order_num);
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 获取订单记录
|
||||
* @param order_num 获取购买记录
|
||||
*/
|
||||
getPrizeLog(order_num) {
|
||||
if (!order_num) {
|
||||
return
|
||||
}
|
||||
let that = this;
|
||||
setTimeout(async () => {
|
||||
const res=await getDiamondOrderLog(order_num);
|
||||
console.log(res);
|
||||
if(res.status==1){
|
||||
that.$c.msg("购买成功!");
|
||||
await that.load();
|
||||
}else{
|
||||
that.getPrizeLog(order_num);
|
||||
}
|
||||
|
||||
}, 500)
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user