index.vue 7.1 KB

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