123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- <template>
- <view class='app-container'>
- <view class="header">
- <view class="info" flex>
- <img class="dev-img" :src="info.devicePic" />
- <view class="dev" flex column>
- <view class="dev-name">{{ info.deviceName }}</view>
- <view class="dev-history" @click="getRouter">开通记录<uni-icons type="right" color="#9fa5ad" size="11" /></view>
- </view>
- </view>
- <view class="progress" flex column center>
- <progress :percent="percent" activeColor="#FFD5A0" backgroundColor="#746C64" border-radius="20" />
- <view class="progress-info" flex between>
- <text>已用:{{ this.rateplan.used }}M / 剩余:{{ this.rateplan.left }}M</text>
- <text>总量:{{ this.rateplan.total / 1024 }}G</text>
- </view>
- </view>
- </view>
- <view class="main">
- <view class="title">流量选择</view>
- <view flex between>
- <view :class="['list', active === index ? 'active' : '']"
- :style="{ 'width': `calc(${100 / options.length}% - 5px)` }" v-for="(item, index) in options" :key="index"
- flex column between @click="getActive(index)" :data-content-before="item.operators"
- :data-content-after="item.tagName">
- <view class="flow">{{ item.name }}</view>
- <view class="discount icon">{{ item.goodDiscountedPrice }}</view>
- <view class="price icon">{{ item.goodPrice }}</view>
- </view>
- </view>
- <view class="explain" flex column>
- <text>说明:</text>
- <text>1、当前流量包购买后,将充值至猫王音响赠送的SIM卡内</text>
- <text>2、流量包购买后当日生效</text>
- <text>3、如在有效期内流量未使用完毕,流量将被清零</text>
- </view>
- </view>
- <view class="footer">
- <view class="warning">
- 开通后仅支持当前绑定的猫王音响上通过移动数据模式使用,不支持蓝牙模式
- </view>
- <button @click="getWechatPay">立即购买</button>
- </view>
- </view>
- </template>
- <script>
- import { openId, wechatPay, detail, options } from "@/api/pay"
- export default {
- data() {
- return {
- openId: '',
- // 流量信息
- info: {},
- rateplan: {},
- // 已用流量
- percent: 0,
- // 下单表单
- form: {},
- // 流量选择
- options: [],
- // 选择
- active: 0,
- state: ''
- }
- },
- onLoad(e) {
- this.state = e.state
- this.getOpenId(e)
- this.getDetail(e)
- this.getOptions(e)
- },
- methods: {
- // 获取openId
- getOpenId(e) {
- openId(e.code).then(res => {
- if (res.code === 0) {
- this.openId = res.data.openid
- }
- })
- },
- // 流量信息
- getDetail(e) {
- detail({ state: e.state }).then(res => {
- if (res.code === 0) {
- this.info = res.data
- this.rateplan = res.data.rateplan
- this.percent = this.rateplan.used / this.rateplan.total * 100
- }
- })
- },
- // 流量套餐
- getOptions(e) {
- options({ state: e.state }).then(res => {
- this.options = res.data
- res.data.map(i => document.documentElement.style.setProperty('——operators', i.operators))
- })
- },
- // 选择套餐
- getActive(index) {
- this.active = index
- },
- // 下单
- getWechatPay() {
- wechatPay(this.openId).then(res => {
- if (res.code === 0) {
- this.form = JSON.parse(res.data)
- if (typeof WeixinJSBridge == 'undefined') {
- if (document.addEventListener) {
- document.addEventListener('WeixinJSBridge', this.onBridgeReady(), false)
- } else if (document.attachEvent) {
- document.attachEvent('WeixinJSBridge', this.onBridgeReady())
- document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady())
- }
- } else {
- this.onBridgeReady()
- }
- }
- })
- },
- // 调起支付
- onBridgeReady() {
- WeixinJSBridge.invoke('getBrandWCPayRequest', this.form, function (res) {
- if (res.err_msg == "get_brand_wcpay_request:ok") {
- // 支付成功刷新页面
- }
- })
- },
- // 开通记录
- getRouter() {
- console.log(1);
- uni.navigateTo({
- url: `/pages/pay/detail?state=${this.state}`,
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .app-container {
- padding: 0;
- }
- .header {
- width: 100%;
- height: 368rpx;
- background: url('../../static/pay/bg.png') no-repeat 100% / 100%;
- .info {
- .dev-img {
- width: 120rpx;
- height: 120rpx;
- border-radius: 50%;
- margin: 64rpx 0 0 64rpx;
- }
- .dev {
- margin-top: 88rpx;
- margin-left: 24rpx;
- .dev-name {
- font-size: 32rpx;
- }
- .dev-history {
- color: #9fa5ad;
- font-size: 22rpx;
- }
- }
- }
- .progress {
- width: 100%;
- margin-top: 48rpx;
- ::v-deep uni-progress,
- .progress-info {
- width: 590rpx;
- .uni-progress-bar,
- .uni-progress-inner-bar {
- border-radius: 18rpx;
- }
- }
- .progress-info {
- font-size: 20rpx;
- color: #9fa5ad;
- margin-top: 8rpx;
- }
- }
- }
- .main {
- padding: 0 32rpx;
- .active {
- background-color: rgba(199, 170, 134, 0.12);
- }
- .list {
- height: 268rpx;
- border: 1px solid #C7AA86;
- border-radius: 16rpx;
- padding: 48rpx 0;
- color: #FFD5A0;
- position: relative;
- margin: 24rpx 0;
- .flow {
- font-size: 32rpx;
- }
- .discount {
- font-size: 48rpx;
- }
- .price {
- font-size: 24rpx;
- text-decoration: line-through;
- opacity: 0.5;
- }
- .icon::before {
- content: '¥';
- font-size: 24rpx;
- }
- }
- .list::before {
- content: attr(data-content-before);
- position: absolute;
- left: -1px;
- top: -1px;
- background-color: #FFD5A0;
- color: #765626;
- font-size: 22rpx;
- border-radius: 16rpx 0 16rpx 0;
- padding: 0 16rpx;
- }
- .list::after {
- content: attr(data-content-after);
- position: absolute;
- left: 0px;
- bottom: -1px;
- background-color: #FFD5A0;
- color: #765626;
- font-size: 22rpx;
- width: 100%;
- text-align: center;
- border-radius: 0 0 16rpx 16rpx;
- }
- .explain {
- font-size: 24rpx;
- opacity: 0.5;
- }
- }
- .footer {
- position: fixed;
- bottom: 0;
- left: 0;
- background: #181818;
- .warning {
- font-size: 22rpx;
- background-color: #2A2A2A;
- padding: 16rpx 32rpx;
- }
- button {
- width: calc(100% - 64rpx);
- height: 92rpx;
- line-height: 92rpx;
- background: linear-gradient(90deg, #F3CF97 0%, #F6E5C4 100%);
- border-radius: 23px;
- color: #7C541A;
- font-size: 32rpx;
- font-weight: bold;
- margin: 32rpx auto;
- }
- }
- </style>
|