兑换结果、兑换记录

This commit is contained in:
yulixing 2019-08-23 17:27:19 +08:00
parent e778b96292
commit b916c1dc51
4 changed files with 284 additions and 148 deletions

View File

@ -49,11 +49,26 @@
"scene": null "scene": null
}, },
{ {
"id": -1, "id": 2,
"name": "exchange-result", "name": "exchange-result",
"pathName": "pages/exchange-result", "pathName": "pages/exchange-result",
"query": "", "query": "",
"scene": null "scene": 1037,
"referrerInfo": {
"appId": "4562388888889",
"extraData": "{ \t\"accountId\": \"6001_1004_oQmL74u7TBo94aGpKIGNCZD9rKew\", \t\"sessionId\": \"1566525470_1563178315_f37bcfd5c3b82fd28d00d18273e7f1a5_53c8e916459a621c1e5021fba99c9212\", \t\"gameId\": \"8002\", \t\"channelId\": \"6001\", \"recordId\": \"5d5fa7ea6f8cb82bc0195750\" }"
}
},
{
"id": 3,
"name": "pages/exchange-record",
"pathName": "pages/exchange-record",
"query": "",
"scene": 1037,
"referrerInfo": {
"appId": "12344",
"extraData": "{ \t\"accountId\": \"6007_1004_D1A9357FB5975B61CDCB43B1AEE6C5D0\", \t\"sessionId\": \"1566525470_1563178315_f37bcfd5c3b82fd28d00d18273e7f1a5_53c8e916459a621c1e5021fba99c9212\", \t\"gameId\": \"8002\", \t\"channelId\": \"6001\", \"recordId\": \"5d5e81eedfd349387cace22c\" }"
}
} }
] ]
} }

View File

@ -1,8 +1,8 @@
<style lang="less"> <style lang="less">
@import "style/zanui/index.wxss"; @import 'style/zanui/index.wxss';
@import "style/font.wxss"; @import 'style/font.wxss';
@import "style/btn.wxss"; @import 'style/btn.wxss';
.container { .container {
height: 100%; height: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -11,18 +11,18 @@
box-sizing: border-box; box-sizing: border-box;
width: 749rpx; width: 749rpx;
overflow-x: hidden; overflow-x: hidden;
} }
.hidden{ .hidden {
display: none!important; display: none !important;
} }
</style> </style>
<script> <script>
import wepy from 'wepy' import wepy from 'wepy'
import 'wepy-async-function' import 'wepy-async-function'
import jcEvent from './common/jc-event'; import jcEvent from './common/jc-event'
let sdkManage = require('./jcfw/SDKManage'); let sdkManage = require('./jcfw/SDKManage')
export default class extends wepy.app { export default class extends wepy.app {
config = { config = {
@ -31,72 +31,72 @@ export default class extends wepy.app {
'pages/product', 'pages/product',
'pages/buyvip', 'pages/buyvip',
'pages/detail', 'pages/detail',
'pages/exchange-result' 'pages/exchange-result',
'pages/exchange-record',
], ],
window: { window: {
backgroundTextStyle: 'light', backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff', navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'WeChat', navigationBarTitleText: 'WeChat',
navigationBarTextStyle: 'black' navigationBarTextStyle: 'black',
} },
} }
globalData = { globalData = {
userInfo: null, userInfo: null,
gameToken: null, gameToken: null,
dataType: 'game' dataType: 'game',
} }
constructor () { constructor() {
super() super()
this.use('requestfix'); this.use('requestfix')
this.use('promisify'); this.use('promisify')
sdkManage.init(); sdkManage.init()
sdkManage.Login(() => { sdkManage.Login(() => {
jcEvent.emit(jcEvent.events.NEED_UPDATE_CFG, {}); jcEvent.emit(jcEvent.events.NEED_UPDATE_CFG, {})
console.log('finish parse jcfw'); console.log('finish parse jcfw')
}); })
//全局拦截器 //全局拦截器
this.intercept('request', { this.intercept('request', {
config(p) { config(p) {
let token = this.globalData.gameToken; let token = this.globalData.gameToken
if (token) { if (token) {
p.header['Authorization'] = `JWT ${token}`; p.header['Authorization'] = `JWT ${token}`
} }
(p.data) || (p.data = {}); p.data || (p.data = {})
(p.data.data_type) || (p.data.data_type = this.globalData.dataType); p.data.data_type || (p.data.data_type = this.globalData.dataType)
return p; return p
}, },
success(response) { success(response) {
if (response.data.errcode === 0) { if (response.data.errcode === 0) {
return response.data; return response.data
} else if (response.statusCode === '404') { } else if (response.statusCode === '404') {
wepy.showToast({ title: '404 请求接口不存在' }); wepy.showToast({title: '404 请求接口不存在'})
} }
return response; return response
}, },
fail(response) { fail(response) {
wepy.showModal({ wepy.showModal({
title: '提示', title: '提示',
content: `服务器错误,请稍候再试! ${response.errMsg}` content: `服务器错误,请稍候再试! ${response.errMsg}`,
}); })
return response; return response
} },
}); })
} }
onLaunch() { onLaunch() {}
}
onShow(options) { onShow(options) {
console.log('app.onShow'); console.log('app.onShow')
console.log(options); console.log(options)
if (options.scene === 1037) { if (options.scene === 1037) {
let params = options.query; let params = options.query
this.globalData.gameToken = params.token; let extraData = options.referrerInfo.extraData
this.globalData.dataType = params.dataType; this.globalData.gameToken = params.token
this.globalData.dataType = params.dataType
this.globalData.extraData = extraData
} }
} }
} }
</script> </script>

View File

@ -1,9 +1,88 @@
<style lang="less"> <style lang="less">
.container {
.records {
width: 100%;
padding: 24rpx;
.record {
display: flex;
align-items: center;
justify-content: space-between;
height: 180rpx;
margin: 24rpx;
border: 1px solid #f0f0f0;
.item-img-wrap {
height: 100%;
width: 180rpx;
.item-img {
width: 100%;
height: 100%;
}
}
.item-desc {
flex: 1;
box-sizing: border-box;
height: 100%;
margin-left: 36rpx;
padding-top: 24rpx;
.item-title,
.code {
display: block;
line-height: 1.2;
}
.code {
margin-top: 36rpx;
font-size: 28rpx;
color: #666;
max-width: 240rpx;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
}
.btn-copy {
width: 180rpx;
height: 100%;
border-left: 1px solid #f0f0f0;
line-height: 180rpx;
text-align: center;
}
}
}
}
</style> </style>
<template> <template>
<view class="container"> <view class="container">
<view class="records">
<repeat
for="{{records}}"
key="index"
index="index"
item="item"
>
<view class="record">
<view class="item-img-wrap">
<image
mode="cover"
src="{{item.gift_info.gift_url}}"
class="item-img"
></image>
</view>
<view class="item-desc">
<text class="item-title">{{item.gift_info.gift_name}}</text>
<text class="code">{{item.code}}</text>
</view>
<view
class="btn-copy"
@tap="copy"
data-index="{{index}}"
>复制</view>
</view>
</repeat>
</view>
<view class="tip" wx:if="{{records.length === 0}}">暂无兑换记录</view>
</view> </view>
</template> </template>
@ -11,27 +90,42 @@
import wepy from 'wepy' import wepy from 'wepy'
import http from '../utils/http' import http from '../utils/http'
export default class ExchangeResult extends wepy.page { export default class ExchangeRecord extends wepy.page {
config = { config = {
navigationBarTitleText: '兑换结果', navigationBarTitleText: '兑换记录',
} }
data = { data = {
status: 1, records: [],
} }
methods = { methods = {
copy(e) {
var self = this
wx.setClipboardData({
data: self.records[e.target.dataset.index].code,
success: function(res) {
wx.showToast({
title: '复制成功!',
})
},
})
},
} }
onShow() { async onShow() {
const extraData = wepy.$instance.globalData.extraData
console.log('!!!!!!!!!!!!!!!!!!!!!')
console.log(extraData)
// TODO: 链接替换
const res = await http.get(
`/api/gift/records?accountId=${
extraData.accountId
}&gameId=${extraData.gameId}&channelId=${extraData.channelId}`
)
this.records = res.result
this.$apply()
console.log(this.records)
} }
} }
</script> </script>

View File

@ -1,94 +1,85 @@
<style lang="less"> <style lang="less">
.container { .container {
padding: 200rpx 100rpx 0; padding-top: 100rpx;
.result { .title {
font-size: 64rpx; font-size: 72rpx;
margin-bottom: 32rpx;
.txt {
display: block;
width: 100%;
margin-bottom: 48rpx;
text-align: center;
}
&.success {
.txt {
color: #f44;
} }
.item { .item {
border: 1px solid #f0f0f0; margin: 50rpx 0 0;
height: 200rpx;
margin: 32rpx 0;
overflow: hidden;
.item-img {
width: 200rpx;
height: 100%;
margin-right: 32rpx;
float: left;
}
.item-desc {
font-size: 36rpx;
.text {
display: block;
line-height: 100rpx;
}
.item-info {
color: #f44;
}
}
}
.code-wrap {
box-sizing: border-box;
width: 500rpx;
padding: 20rpx 32rpx;
margin: 64rpx;
border: 1px solid #f0f0f0; border: 1px solid #f0f0f0;
text-align: center; text-align: center;
font-size: 32rpx; font-size: 0;
} .item-img {
}
&.fail {
.txt {
color: #666;
}
.fail-img {
width: 300rpx; width: 300rpx;
height: 300rpx; height: 300rpx;
} }
.item-desc {
font-size: 32rpx;
margin: 12rpx 0;
.item-title {
display: block;
max-width: 100%;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
} }
} }
}
.code-wrap {
box-sizing: border-box;
width: 100%;
padding: 50rpx;
.btn-view { .code,
color: #1989fa; .tip {
display: block;
font-size: 48rpx;
text-align: center;
}
.code {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.tip {
margin-top: 24rpx;
color: #666;
font-size: 28rpx; font-size: 28rpx;
text-decoration: underline; }
}
.btn-view {
margin-top: 100rpx;
font-size: 28rpx;
color: #1989fa;
} }
} }
</style> </style>
<template> <template>
<view class="container"> <view class="container">
<text class="title">兑换成功</text>
<view class="result success">
<text class="txt">兑换成功</text>
<view class="item"> <view class="item">
<image <image
mode="cover" mode="cover"
src="http://iph.href.lu/300x300" src="{{gift_record.gift_info.gift_url}}"
class="item-img" class="item-img"
></image> ></image>
<view class="item-desc"> <view class="item-desc">
<text class="text item-title">5元话费券</text> <text class="item-title">{{gift_record.gift_info.gift_name}}</text>
<text class="text item-info">¥5.00</text> </view>
</view>
<view
class="code-wrap"
@longtap="copy"
>
<text class="code">{{gift_record.code}}</text>
<text class="tip">长按复制兑换券</text>
</view>
<text
class="btn-view"
@tap="viewRecords"
>兑换记录</text>
</view> </view>
</view>
<view class="code-wrap">
<text class="code">xde23dacaf2</text>
</view>
</view>
<text class="btn-view">兑换记录</text>
</view>
</template> </template>
<script> <script>
@ -101,13 +92,49 @@ export default class ExchangeResult extends wepy.page {
} }
data = { data = {
status: 0,
gift_record: {
gift_info: {
gift_id: '',
gift_name: '',
gift_url: '',
},
_id: '',
user_id: '',
game_id: '',
platform_id: '',
gift_id: '',
code: '',
},
} }
methods = {} methods = {
copy(e) {
onShow(options) { var self = this
console.log(options.refrence) wx.setClipboardData({
data: self.gift_record.code,
success: function(res) {
wx.showToast({
title: '复制成功!',
})
},
})
},
viewRecords() {
wx.navigateTo({
url: '/pages/exchange-record',
})
},
}
async onShow() {
const extraData = wepy.$instance.globalData.extraData
const res = await http.get(
'/api/gift/record?recordId=' + extraData.recordId
)
if (res.errcode === 0) {
this.gift_record = res.result
this.$apply()
}
} }
} }
</script> </script>