Pay.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template id='Pay'>
  2. <div>
  3. <van-nav-bar title="电量充值" left-arrow @click-left="back">
  4. <span @click="go" class="iconfont" slot="right">&#xe646;</span>
  5. </van-nav-bar>
  6. <div class="fyycontent fyypay">
  7. <van-cell-group>
  8. <van-cell>
  9. <span class="iconfont color-red fyy-icon">&#xe640;</span>
  10. <span v-html="area.name"></span>
  11. <span class="m-left10" v-html="building.name"></span>
  12. <span class="m-left10" v-html="room.name">601</span>
  13. </van-cell>
  14. <div class="fyyinput">
  15. <input type="text" placeholder="请输入要充值的电量度数" v-model="kwh"/>
  16. <span class="input-right">度</span>
  17. </div>
  18. <p class="fyy-h6">价格标准:<span v-html="price"></span>元/度</p>
  19. </van-cell-group>
  20. <van-cell-group>
  21. <van-cell>
  22. <span class="iconfont color-red fyy-icon">&#xe648;</span>
  23. 选择支付方式
  24. </van-cell>
  25. <van-radio-group v-model="payType" class="fyyradio-pay">
  26. <van-cell-group>
  27. <van-cell clickable @click="payType = '1'">
  28. <img src="@/assets/img/zhifubao.png" />
  29. <van-radio slot="right-icon" name="1" />
  30. </van-cell>
  31. <van-cell clickable @click="payType = '2'">
  32. <img src="@/assets/img/weixin.png" />
  33. <van-radio slot="right-icon" name="2" />
  34. </van-cell>
  35. </van-cell-group>
  36. </van-radio-group>
  37. </van-cell-group>
  38. </div>
  39. <div class="fyyfooter">
  40. <p class="fyy-h5">
  41. 核计:
  42. <span class="fyy-h3 color-red" v-html="total"></span>元
  43. </p>
  44. <router-link to="/Pay">
  45. <van-button type="bigred">支付</van-button>
  46. </router-link>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import remoteApi from '@/api/remoteApi'
  52. import wx from 'weixin-js-sdk'
  53. import hex_sha1 from 'hex-sha1'
  54. export default {
  55. data() {
  56. return {
  57. area:{},
  58. building:{},
  59. room:{},
  60. price:0,
  61. roomId : null,
  62. kwh : 0,
  63. payType: '1'
  64. }
  65. },
  66. methods: {
  67. go() {
  68. this.$router.push("/Paylist")
  69. },
  70. back() {
  71. this.$router.push("/")
  72. }
  73. },
  74. computed: {
  75. total (){
  76. return (this.kwh* this.price).toFixed(2);
  77. }
  78. },
  79. created () {
  80. var appId = 'wxe598c699aa68cffe'
  81. var timestamp = (new Date()).getTime()
  82. var fullStr = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'
  83. var nonceStr = ''
  84. for(var i=0;i<10;i++){
  85. nonceStr += fullStr.charAt(Math.floor(Math.random()*fullStr.length))
  86. }
  87. var url = window.location.href.split('#')[0]
  88. //服务器端通过access_token获取 https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi
  89. var ticket = 'sM4AOVdWfPE4DxkXGEs8VAMadDORtDxQLtMKXqk9xSQE7OmFwIWBf7X3rxflmFXgENu66LRawd1bYAjz89QM2w'
  90. //注意这里noncestr中的s是小写
  91. var plainText = `noncestr=${nonceStr}&jsapi_ticket=${ticket}&timestamp=${timestamp}&url=${url}`
  92. console.log(`plainText="${plainText}"`)
  93. var signature = hex_sha1(plainText)
  94. console.log(`signature=${signature}`)
  95. wx.config({
  96. debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印
  97. appId: appId, // 必填,公众号的唯一标识
  98. timestamp: timestamp, // 必填,生成签名的时间戳
  99. nonceStr: nonceStr, // 必填,生成签名的随机串
  100. signature: signature,// 必填,签名
  101. jsApiList: ['checkJsApi','chooseWXPay'] // 必填,需要使用的JS接口列表
  102. });
  103. wx.ready(function(){
  104. });
  105. wx.error((error)=>{
  106. console.log(error)
  107. });
  108. },
  109. mounted () {
  110. var roomId = this.$route.query.roomId;
  111. this.$toast.loading({
  112. message: '加载中...',
  113. forbidClick: true,
  114. loadingType: 'spinner',
  115. duration: 10000
  116. });
  117. var self = this;
  118. remoteApi.queryRoomDetail(roomId).then((resp)=>{
  119. console.log(resp);
  120. this.$toast.clear();
  121. if(resp.result){
  122. self.$toast.success('查询成功!')
  123. var jsonData = resp.data
  124. self.area = jsonData.area
  125. self.building = jsonData.building
  126. self.room = jsonData.room
  127. self.price = parseFloat(jsonData.price)
  128. }
  129. else {
  130. self.$toast.fail(resp.message)
  131. }
  132. });
  133. }
  134. }
  135. </script>
  136. <style scoped>
  137. </style>