index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <view class='app-container'>
  3. <view class="header">
  4. <view class="info" flex>
  5. <img class="dev-img" :src="info.devicePic" />
  6. <view class="dev" flex column>
  7. <view class="dev-name">{{ info.deviceName }}</view>
  8. <view class="dev-history" @click="getRouter">开通记录<uni-icons type="right" color="#9fa5ad" size="11" /></view>
  9. </view>
  10. </view>
  11. <view class="progress" flex column center>
  12. <progress :percent="percent" activeColor="#FFD5A0" backgroundColor="#746C64" border-radius="20" />
  13. <view class="progress-info" flex between>
  14. <text>已用:{{ this.rateplan.used }}M / 剩余:{{ this.rateplan.left }}M</text>
  15. <text>总量:{{ this.rateplan.total / 1024 }}G</text>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="main">
  20. <view class="title">流量选择</view>
  21. <view flex between>
  22. <view :class="['list', active === index ? 'active' : '']"
  23. :style="{ 'width': `calc(${100 / options.length}% - 5px)` }" v-for="(item, index) in options" :key="index"
  24. flex column between @click="getActive(index)" :data-content-before="item.operators"
  25. :data-content-after="item.tagName">
  26. <view class="flow">{{ item.name }}</view>
  27. <view class="discount icon">{{ item.goodDiscountedPrice }}</view>
  28. <view class="price icon">{{ item.goodPrice }}</view>
  29. </view>
  30. </view>
  31. <view class="explain" flex column>
  32. <text>说明:</text>
  33. <text>1、当前流量包购买后,将充值至猫王音响赠送的SIM卡内</text>
  34. <text>2、流量包购买后当日生效</text>
  35. <text>3、如在有效期内流量未使用完毕,流量将被清零</text>
  36. </view>
  37. </view>
  38. <view class="footer">
  39. <view class="warning">
  40. 开通后仅支持当前绑定的猫王音响上通过移动数据模式使用,不支持蓝牙模式
  41. </view>
  42. <button @click="getWechatPay">立即购买</button>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import { openId, wechatPay, detail, options } from "@/api/pay"
  48. export default {
  49. data() {
  50. return {
  51. openId: '',
  52. // 流量信息
  53. info: {},
  54. rateplan: {},
  55. // 已用流量
  56. percent: 0,
  57. // 下单表单
  58. form: {},
  59. // 流量选择
  60. options: [],
  61. // 选择
  62. active: 0,
  63. state: ''
  64. }
  65. },
  66. onLoad(e) {
  67. this.state = e.state
  68. this.getOpenId(e)
  69. this.getDetail(e)
  70. this.getOptions(e)
  71. },
  72. methods: {
  73. // 获取openId
  74. getOpenId(e) {
  75. openId(e.code).then(res => {
  76. if (res.code === 0) {
  77. this.openId = res.data.openid
  78. }
  79. })
  80. },
  81. // 流量信息
  82. getDetail(e) {
  83. detail({ state: e.state }).then(res => {
  84. if (res.code === 0) {
  85. this.info = res.data
  86. this.rateplan = res.data.rateplan
  87. this.percent = this.rateplan.used / this.rateplan.total * 100
  88. }
  89. })
  90. },
  91. // 流量套餐
  92. getOptions(e) {
  93. options({ state: e.state }).then(res => {
  94. this.options = res.data
  95. res.data.map(i => document.documentElement.style.setProperty('——operators', i.operators))
  96. })
  97. },
  98. // 选择套餐
  99. getActive(index) {
  100. this.active = index
  101. },
  102. // 下单
  103. getWechatPay() {
  104. wechatPay(this.openId).then(res => {
  105. if (res.code === 0) {
  106. this.form = JSON.parse(res.data)
  107. if (typeof WeixinJSBridge == 'undefined') {
  108. if (document.addEventListener) {
  109. document.addEventListener('WeixinJSBridge', this.onBridgeReady(), false)
  110. } else if (document.attachEvent) {
  111. document.attachEvent('WeixinJSBridge', this.onBridgeReady())
  112. document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady())
  113. }
  114. } else {
  115. this.onBridgeReady()
  116. }
  117. }
  118. })
  119. },
  120. // 调起支付
  121. onBridgeReady() {
  122. WeixinJSBridge.invoke('getBrandWCPayRequest', this.form, function (res) {
  123. if (res.err_msg == "get_brand_wcpay_request:ok") {
  124. // 支付成功刷新页面
  125. }
  126. })
  127. },
  128. // 开通记录
  129. getRouter() {
  130. console.log(1);
  131. uni.navigateTo({
  132. url: `/pages/pay/detail?state=${this.state}`,
  133. })
  134. }
  135. }
  136. }
  137. </script>
  138. <style lang="scss" scoped>
  139. .app-container {
  140. padding: 0;
  141. }
  142. .header {
  143. width: 100%;
  144. height: 368rpx;
  145. background: url('../../static/pay/bg.png') no-repeat 100% / 100%;
  146. .info {
  147. .dev-img {
  148. width: 120rpx;
  149. height: 120rpx;
  150. border-radius: 50%;
  151. margin: 64rpx 0 0 64rpx;
  152. }
  153. .dev {
  154. margin-top: 88rpx;
  155. margin-left: 24rpx;
  156. .dev-name {
  157. font-size: 32rpx;
  158. }
  159. .dev-history {
  160. color: #9fa5ad;
  161. font-size: 22rpx;
  162. }
  163. }
  164. }
  165. .progress {
  166. width: 100%;
  167. margin-top: 48rpx;
  168. ::v-deep uni-progress,
  169. .progress-info {
  170. width: 590rpx;
  171. .uni-progress-bar,
  172. .uni-progress-inner-bar {
  173. border-radius: 18rpx;
  174. }
  175. }
  176. .progress-info {
  177. font-size: 20rpx;
  178. color: #9fa5ad;
  179. margin-top: 8rpx;
  180. }
  181. }
  182. }
  183. .main {
  184. padding: 0 32rpx;
  185. .active {
  186. background-color: rgba(199, 170, 134, 0.12);
  187. }
  188. .list {
  189. height: 268rpx;
  190. border: 1px solid #C7AA86;
  191. border-radius: 16rpx;
  192. padding: 48rpx 0;
  193. color: #FFD5A0;
  194. position: relative;
  195. margin: 24rpx 0;
  196. .flow {
  197. font-size: 32rpx;
  198. }
  199. .discount {
  200. font-size: 48rpx;
  201. }
  202. .price {
  203. font-size: 24rpx;
  204. text-decoration: line-through;
  205. opacity: 0.5;
  206. }
  207. .icon::before {
  208. content: '¥';
  209. font-size: 24rpx;
  210. }
  211. }
  212. .list::before {
  213. content: attr(data-content-before);
  214. position: absolute;
  215. left: -1px;
  216. top: -1px;
  217. background-color: #FFD5A0;
  218. color: #765626;
  219. font-size: 22rpx;
  220. border-radius: 16rpx 0 16rpx 0;
  221. padding: 0 16rpx;
  222. }
  223. .list::after {
  224. content: attr(data-content-after);
  225. position: absolute;
  226. left: 0px;
  227. bottom: -1px;
  228. background-color: #FFD5A0;
  229. color: #765626;
  230. font-size: 22rpx;
  231. width: 100%;
  232. text-align: center;
  233. border-radius: 0 0 16rpx 16rpx;
  234. }
  235. .explain {
  236. font-size: 24rpx;
  237. opacity: 0.5;
  238. }
  239. }
  240. .footer {
  241. position: fixed;
  242. bottom: 0;
  243. left: 0;
  244. background: #181818;
  245. .warning {
  246. font-size: 22rpx;
  247. background-color: #2A2A2A;
  248. padding: 16rpx 32rpx;
  249. }
  250. button {
  251. width: calc(100% - 64rpx);
  252. height: 92rpx;
  253. line-height: 92rpx;
  254. background: linear-gradient(90deg, #F3CF97 0%, #F6E5C4 100%);
  255. border-radius: 23px;
  256. color: #7C541A;
  257. font-size: 32rpx;
  258. font-weight: bold;
  259. margin: 32rpx auto;
  260. }
  261. }
  262. </style>