credit.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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">{{$t('物联网卡号码')}}:</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">{{$t('设备名称')}}:</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">{{$t('到期时间')}}:</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">{{$t('年费')}}:</view>
  23. <view class="item-value">{{ simInfo.price / 100 + $t('元') }}</view>
  24. </view>
  25. <view class="credit-item" @tap="bindCredit">
  26. <button class="credit-btn">{{$t('充值')}}</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. uni.setNavigationBarTitle({
  56. title: this.$t('物联网卡充值')
  57. });
  58. if (!options.macid) {
  59. uni.navigateBack({
  60. delta: 1
  61. });
  62. }
  63. this.setData({
  64. macid: options.macid
  65. });
  66. this.loadSimInfo();
  67. },
  68. /**
  69. * 生命周期函数--监听页面初次渲染完成
  70. */
  71. onReady: function () {},
  72. /**
  73. * 生命周期函数--监听页面显示
  74. */
  75. onShow: function () {
  76. uni.setNavigationBarTitle({
  77. title: this.$t('物联网卡充值')
  78. });
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide: function () {},
  84. /**
  85. * 生命周期函数--监听页面卸载
  86. */
  87. onUnload: function () {},
  88. /**
  89. * 页面相关事件处理函数--监听用户下拉动作
  90. */
  91. onPullDownRefresh: function () {},
  92. /**
  93. * 页面上拉触底事件的处理函数
  94. */
  95. onReachBottom: function () {},
  96. /**
  97. * 用户点击右上角分享
  98. */
  99. onShareAppMessage: function () {},
  100. methods: {
  101. loadSimInfo: function () {
  102. common.loading(this);
  103. const me = this
  104. http.postApi(
  105. config.API_SIM_INFO,
  106. {
  107. macid: this.macid
  108. },
  109. (resp) => {
  110. uni.hideLoading();
  111. if (resp.data.code === 200) {
  112. const simInfo = resp.data.data.info;
  113. if (!simInfo) {
  114. common.simpleToast(me,me.$t('无SIM信息'));
  115. setTimeout(function () {
  116. uni.navigateBack({
  117. delta: 1
  118. });
  119. }, 1500);
  120. }
  121. this.setData({
  122. simInfo: resp.data.data.info
  123. });
  124. } else {
  125. if (resp.data.code === 12005) {
  126. common.simpleToast(me,resp.data.msg + ':' + resp.data.data.msg.resultmsg);
  127. setTimeout(function () {
  128. uni.navigateBack({
  129. delta: 1
  130. });
  131. }, 1500);
  132. } else {
  133. common.simpleToast(me,resp.data.msg);
  134. setTimeout(function () {
  135. uni.navigateBack({
  136. delta: 1
  137. });
  138. }, 1500);
  139. }
  140. }
  141. }
  142. );
  143. },
  144. bindCredit() {
  145. common.loading(this);
  146. const me = this
  147. http.postApi(
  148. config.API_SIM_CREDIT,
  149. {
  150. macid: this.macid,
  151. type: 'jsapi'
  152. },
  153. (resp) => {
  154. uni.hideLoading();
  155. if (resp.data.code === 200) {
  156. var payParams = JSON.parse(resp.data.data.payParams);
  157. var order_sn = resp.data.data.order_sn;
  158. user.wxPay(order_sn, payParams, function (isSuccess) {
  159. if (isSuccess) {
  160. common.simpleToast(me.$t('支付成功'));
  161. setTimeout(function () {
  162. uni.navigateBack({
  163. delta: 1
  164. });
  165. }, 1500);
  166. }
  167. });
  168. } else {
  169. common.simpleToast(me,resp.data.msg);
  170. }
  171. }
  172. );
  173. }
  174. }
  175. };
  176. </script>
  177. <style>
  178. @import './credit.css';
  179. </style>