credit.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <!-- pages/credit/credit.wxml -->
  3. <view class="container">
  4. <view class="credit-container">
  5. <view class="credit-item flex-row flex-between">
  6. <view class="item-titie">物联网卡号码:</view>
  7. <view class="item-value">{{ simInfo.cardno }}</view>
  8. </view>
  9. <view class="credit-item flex-row flex-between">
  10. <view class="item-titie">ICCID:</view>
  11. <view class="item-value">{{ simInfo.iccid }}</view>
  12. </view>
  13. <view class="credit-item flex-row flex-between">
  14. <view class="item-titie">设备名称:</view>
  15. <view class="item-value">{{ simInfo.name }}</view>
  16. </view>
  17. <view class="credit-item flex-row flex-between">
  18. <view class="item-titie">到期时间:</view>
  19. <view class="item-value">{{ simInfo.validdate }}</view>
  20. </view>
  21. <view class="credit-item flex-row flex-between">
  22. <view class="item-titie">年费:</view>
  23. <view class="item-value">{{ simInfo.price / 100 }}元</view>
  24. </view>
  25. <view class="credit-item" @tap="bindCredit">
  26. <button class="credit-btn">充值</button>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. // pages/credit/credit.js
  33. var config = require('../../common/config.js');
  34. var http = require('../../common/http.js');
  35. var common = require('../../common/common.js');
  36. var storage = require('../../common/storage.js');
  37. var user = require('../../common/user.js');
  38. export default {
  39. data() {
  40. return {
  41. macid: '',
  42. simInfo: {
  43. cardno: '',
  44. iccid: '',
  45. name: '',
  46. validdate: '',
  47. price: 0
  48. }
  49. };
  50. }
  51. /**
  52. * 生命周期函数--监听页面加载
  53. */,
  54. onLoad: function (options) {
  55. if (!options.macid) {
  56. uni.navigateBack({
  57. delta: 1
  58. });
  59. }
  60. this.setData({
  61. macid: options.macid
  62. });
  63. this.loadSimInfo();
  64. },
  65. /**
  66. * 生命周期函数--监听页面初次渲染完成
  67. */
  68. onReady: function () {},
  69. /**
  70. * 生命周期函数--监听页面显示
  71. */
  72. onShow: function () {},
  73. /**
  74. * 生命周期函数--监听页面隐藏
  75. */
  76. onHide: function () {},
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload: function () {},
  81. /**
  82. * 页面相关事件处理函数--监听用户下拉动作
  83. */
  84. onPullDownRefresh: function () {},
  85. /**
  86. * 页面上拉触底事件的处理函数
  87. */
  88. onReachBottom: function () {},
  89. /**
  90. * 用户点击右上角分享
  91. */
  92. onShareAppMessage: function () {},
  93. methods: {
  94. loadSimInfo: function () {
  95. common.loading();
  96. http.postApi(
  97. config.API_SIM_INFO,
  98. {
  99. macid: this.macid
  100. },
  101. (resp) => {
  102. uni.hideLoading();
  103. if (resp.data.code === 200) {
  104. const simInfo = resp.data.data.info;
  105. if (!simInfo) {
  106. common.simpleToast('无SIM信息');
  107. setTimeout(function () {
  108. uni.navigateBack({
  109. delta: 1
  110. });
  111. }, 1500);
  112. }
  113. this.setData({
  114. simInfo: resp.data.data.info
  115. });
  116. } else {
  117. if (resp.data.code === 12005) {
  118. common.simpleToast(resp.data.msg + ':' + resp.data.data.msg.resultmsg);
  119. setTimeout(function () {
  120. uni.navigateBack({
  121. delta: 1
  122. });
  123. }, 1500);
  124. } else {
  125. common.simpleToast(resp.data.msg);
  126. setTimeout(function () {
  127. uni.navigateBack({
  128. delta: 1
  129. });
  130. }, 1500);
  131. }
  132. }
  133. }
  134. );
  135. },
  136. bindCredit() {
  137. common.loading();
  138. http.postApi(
  139. config.API_SIM_CREDIT,
  140. {
  141. macid: this.macid,
  142. type: 'jsapi'
  143. },
  144. (resp) => {
  145. uni.hideLoading();
  146. if (resp.data.code === 200) {
  147. var payParams = JSON.parse(resp.data.data.payParams);
  148. var order_sn = resp.data.data.order_sn;
  149. user.wxPay(order_sn, payParams, function (isSuccess) {
  150. if (isSuccess) {
  151. common.simpleToast('支付成功');
  152. setTimeout(function () {
  153. uni.navigateBack({
  154. delta: 1
  155. });
  156. }, 1500);
  157. }
  158. });
  159. } else {
  160. common.simpleToast(resp.data.msg);
  161. }
  162. }
  163. );
  164. }
  165. }
  166. };
  167. </script>
  168. <style>
  169. @import './credit.css';
  170. </style>