pay.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view>
  3. <view class="box">
  4. <u-search placeholder="输入车牌号查询" shape="square" v-model="p.carNo" @search="searchFn()" @change="searchFn"
  5. :height="80">
  6. </u-search>
  7. </view>
  8. <view class="list" v-show="list.length>0">
  9. <u-radio-group placement="column" @change="groupChange">
  10. <u-radio :customStyle="{marginBottom: '6px',borderBottom: '1px solid #e5e5e5',paddingBottom:'5px'}"
  11. v-for="(item, index) in list" :key="index" :label="item.carNo" :name="item.businessId">
  12. </u-radio>
  13. </u-radio-group>
  14. </view>
  15. <view class="car-list" v-show="cars.length>0">
  16. <view>停车费:</view>
  17. <view class="item" v-for="item in cars" style="margin: 20rpx 0 0 40rpx;">
  18. <view class="l">{{item.carNo}}:{{item.price}}元</view>
  19. </view>
  20. </view>
  21. <view class="car-list" v-show="item.itemsPrice" style="margin-top:40rpx;">
  22. <view>业务费:{{item.itemsPrice}}元</view>
  23. <view class="item" v-for="item in item.list" style="margin: 20rpx 0 0 40rpx;">
  24. <view class="l">{{item.name}}:{{item.price}}元</view>
  25. </view>
  26. </view>
  27. <view class="item" v-if="total">
  28. <view>
  29. 合计费用:{{total}}元
  30. </view>
  31. <u-radio-group style="margin: 50rpx 0 20rpx 30rpx;" v-model="form.payType" placement="column"
  32. @change="payTypeChange">
  33. <u-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in payTypeList" :key="index"
  34. :label="item.name" :name="item.value">
  35. </u-radio>
  36. </u-radio-group>
  37. <u-button type="primary" @click="confirmPayFn">立即支付</u-button>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. var jweixin = require('@/components/jweixin-module/index.js');
  43. export default {
  44. data() {
  45. return {
  46. p: {
  47. carNo: ''
  48. },
  49. code: '',
  50. selectNo: '',
  51. openid: '',
  52. businessId:'',
  53. state:'',
  54. list: [],
  55. cars: [],
  56. item: {
  57. itemsPrice: '',
  58. businessId: '',
  59. list: []
  60. },
  61. total:0,
  62. payTypeList: [{
  63. name: '微信支付',
  64. value: 3
  65. }],
  66. form: {
  67. partMoney: 0,
  68. payType: 3
  69. },
  70. }
  71. },
  72. onLoad(options) {
  73. this.code = options.code;
  74. this.state=options.state;
  75. this.getOpenidByCode();
  76. },
  77. created() {},
  78. mounted() {
  79. this.getWxConfig();
  80. },
  81. beforeDestroy() {
  82. this.$common.hidingLoading()
  83. },
  84. methods: {
  85. getWxConfig() {
  86. let url = window.location.href;
  87. this.$api.getWxConfig({
  88. url: url
  89. }).then(resp => {
  90. jweixin.config({
  91. //debug: true,
  92. appId: resp.data.appId,
  93. timestamp: resp.data.timestamp, // 必填,生成签名的时间戳
  94. nonceStr: resp.data.noncestr, // 必填,生成签名的随机串
  95. signature: resp.data.sign, // 必填,签名
  96. jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表
  97. });
  98. jweixin.ready(function() {
  99. console.log('111')
  100. });
  101. jweixin.error(function(res) {
  102. console.log(res)
  103. });
  104. })
  105. },
  106. confirmPayFn() {
  107. let p = {
  108. businessId: this.businessId,
  109. carId: this.cars.map(obj=>obj.id).join(','),
  110. money: this.total,
  111. tradeType: "JSAPI",
  112. openid: this.openid
  113. }
  114. this.$api.getPrePay(p).then(resp => {
  115. let data = resp.data;
  116. let that=this;
  117. jweixin.chooseWXPay({
  118. timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  119. nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
  120. package: data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  121. signType: data.signType, // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
  122. paySign: data.paySign, // 支付签名
  123. success: function(res) {
  124. if (res.errMsg === "chooseWXPay:ok") {
  125. that.$common.toast('支付成功')
  126. // wx.closeWindow();
  127. }
  128. }
  129. });
  130. })
  131. },
  132. payTypeChange(value) {
  133. },
  134. getOpenidByCode() {
  135. let storeOpenid = uni.getStorageSync('openid');
  136. this.$api.getOpenidByCode({
  137. code: this.code,
  138. openid: storeOpenid
  139. }).then(resp => {
  140. let openid = resp.data;
  141. this.openid = openid;
  142. if (openid) {
  143. uni.setStorageSync('openid', openid)
  144. }
  145. })
  146. },
  147. groupChange(value) {
  148. this.list = [];
  149. this.businessId=value;
  150. this.$api.getBusinessMoney({
  151. businessId: value,
  152. state:this.state
  153. }).then(resp => {
  154. let data = resp.data;
  155. this.cars = data.carList;
  156. this.total=data.total;
  157. Object.assign(this.item, {
  158. itemsPrice: data.itemsPrice,
  159. businessId: value,
  160. list: data.itemList
  161. })
  162. })
  163. },
  164. searchFn() {
  165. if (!this.p.carNo) {
  166. this.list = [];
  167. } else {
  168. this.$api.searchPartCar(this.p).then(resp => {
  169. this.list = resp.data;
  170. })
  171. }
  172. }
  173. }
  174. }
  175. </script>
  176. <style lang="scss">
  177. page {
  178. background-color: #fff;
  179. }
  180. .box {
  181. display: flex;
  182. flex: 1;
  183. align-items: center;
  184. justify-content: center;
  185. flex-direction: column;
  186. padding: 40rpx 0;
  187. }
  188. .list {
  189. margin-left: 120rpx;
  190. width: 380rpx;
  191. border-radius: 5rpx;
  192. //background-color: rgb(242, 242, 242);
  193. margin-top: -35rpx;
  194. padding: 20rpx;
  195. }
  196. </style>