pay.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <view>
  3. <view class="box">
  4. <view class="top" style="padding-top: 50rpx;">
  5. <text class="title">支付</text>
  6. </view>
  7. <u-search placeholder="输入车牌号查询"
  8. shape="square" v-model="p.carNo"
  9. @search="searchFn()" @change="searchFn"
  10. :height="80" style="margin: 30rpx;">
  11. </u-search>
  12. </view>
  13. <view class="list" v-show="list.length>0">
  14. <u-radio-group placement="column" @change="groupChange">
  15. <u-radio :customStyle="{marginBottom: '6px',borderBottom: '1px solid #e5e5e5',paddingBottom:'5px'}"
  16. v-for="(item, index) in list" :key="index" :label="item.carNo" :name="item.businessId">
  17. </u-radio>
  18. </u-radio-group>
  19. </view>
  20. <view class="car-list" v-show="cars.length>0">
  21. <view class="card">
  22. <view class="title">
  23. 停车费:
  24. </view>
  25. <view v-for="(tingcheItem,index) in cars" :key="index">
  26. <label class="c-item">
  27. <view class="c">{{tingcheItem.carNo}}</view>
  28. <view class="r">{{tingcheItem.price}}元</view>
  29. </label>
  30. </view>
  31. </view>
  32. <view class="card" v-if="item.itemsPrice">
  33. <view class="title">
  34. 业务费:{{item.itemsPrice}}元
  35. </view>
  36. <view v-for="(yewuItem,index) in item.list" :key="index">
  37. <label class="c-item">
  38. <view class="c">{{yewuItem.name}}</view>
  39. <view class="r">{{yewuItem.price}}元</view>
  40. </label>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="bottom bgc-f bottom-safety" v-if="total>0">
  45. <!-- <u-radio-group style="margin: 50rpx 0 20rpx 30rpx;" v-model="form.payType" placement="column"
  46. @change="payTypeChange">
  47. <u-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in payTypeList" :key="index"
  48. :label="item.name" :name="item.value">
  49. </u-radio>
  50. </u-radio-group> -->
  51. <view class="box">
  52. <view class="l">
  53. <text class="t1">金额:</text>
  54. <text class="t2">¥{{total}}元</text>
  55. </view>
  56. <view class="r">
  57. <view class="btn" @click="confirmPayFn()">立即支付</view>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. var jweixin = require('@/components/jweixin-module/index.js');
  65. export default {
  66. data() {
  67. return {
  68. p: {
  69. carNo: ''
  70. },
  71. code: '',
  72. selectNo: '',
  73. openid: '',
  74. businessId: '',
  75. state: '',
  76. list: [],
  77. cars: [],
  78. item: {
  79. itemsPrice: '',
  80. businessId: '',
  81. list: []
  82. },
  83. total: 0,
  84. payTypeList: [{
  85. name: '微信支付',
  86. value: 3
  87. }],
  88. form: {
  89. partMoney: 0,
  90. payType: 3
  91. },
  92. }
  93. },
  94. onLoad(options) {
  95. this.code = options.code;
  96. this.state = options.state;
  97. this.getOpenidByCode();
  98. },
  99. created() {},
  100. mounted() {
  101. this.getWxConfig();
  102. },
  103. beforeDestroy() {
  104. this.$common.hidingLoading()
  105. },
  106. methods: {
  107. getWxConfig() {
  108. let url = window.location.href;
  109. this.$api.getWxConfig({
  110. url: url
  111. }).then(resp => {
  112. jweixin.config({
  113. //debug: true,
  114. appId: resp.data.appId,
  115. timestamp: resp.data.timestamp, // 必填,生成签名的时间戳
  116. nonceStr: resp.data.noncestr, // 必填,生成签名的随机串
  117. signature: resp.data.sign, // 必填,签名
  118. jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表
  119. });
  120. jweixin.ready(function() {
  121. });
  122. jweixin.error(function(res) {
  123. console.log(res)
  124. });
  125. })
  126. },
  127. confirmPayFn() {
  128. let businessId = this.state == 'STATE' ? this.businessId : null;
  129. let carId = this.state == 'STATE' ? null : this.cars.map(obj => obj.id).join(',')
  130. let p = {
  131. businessId: businessId,
  132. carId: carId,
  133. money: this.total,
  134. tradeType: "JSAPI",
  135. openid: this.openid
  136. }
  137. this.$api.getPrePay(this.$common.removeNull(p)).then(resp => {
  138. let data = resp.data;
  139. let that = this;
  140. jweixin.chooseWXPay({
  141. timestamp: data
  142. .timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  143. nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
  144. package: data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  145. signType: data.signType, // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
  146. paySign: data.paySign, // 支付签名
  147. success: function(res) {
  148. if (res.errMsg === "chooseWXPay:ok") {
  149. that.$common.toast('支付成功')
  150. that.cars=[];
  151. that.item.list=[];
  152. that.total=0
  153. // wx.closeWindow();
  154. }
  155. }
  156. });
  157. })
  158. },
  159. payTypeChange(value) {
  160. },
  161. getOpenidByCode() {
  162. let storeOpenid = uni.getStorageSync('openid');
  163. this.$api.getOpenidByCode({
  164. code: this.code,
  165. openid: storeOpenid
  166. }).then(resp => {
  167. let openid = resp.data;
  168. this.openid = openid;
  169. if (openid) {
  170. uni.setStorageSync('openid', openid)
  171. }
  172. })
  173. },
  174. groupChange(value) {
  175. this.list = [];
  176. this.businessId = value;
  177. this.$api.getBusinessMoney({
  178. businessId: value,
  179. state: this.state
  180. }).then(resp => {
  181. let data = resp.data;
  182. this.cars = data.carList;
  183. this.total = data.total;
  184. Object.assign(this.item, {
  185. itemsPrice: data.itemsPrice,
  186. businessId: value,
  187. list: data.itemList
  188. })
  189. if(data.total==0){
  190. this.$common.toast('您无需缴费');
  191. this.p.carNo=''
  192. }
  193. })
  194. },
  195. searchFn() {
  196. if (!this.p.carNo) {
  197. this.list = [];
  198. } else {
  199. this.$api.searchPartCar(this.p).then(resp => {
  200. this.list = resp.data;
  201. })
  202. }
  203. }
  204. }
  205. }
  206. </script>
  207. <style lang="scss">
  208. page {
  209. background-color: #fff;
  210. }
  211. .card {
  212. .title {
  213. padding: 30rpx;
  214. box-sizing: border-box;
  215. font-size: 34rpx;
  216. font-weight: bold;
  217. }
  218. }
  219. .content {
  220. display: flex;
  221. flex-direction: column;
  222. padding: 30rpx;
  223. box-sizing: border-box;
  224. color: #999;
  225. }
  226. .c-item {
  227. display: flex;
  228. align-items: center;
  229. margin: 15rpx 30rpx;
  230. padding: 40rpx 30rpx;
  231. border-radius: 10rpx;
  232. background-color: #fff;
  233. border: 1rpx solid #f5f5f5;
  234. .l {}
  235. .c {
  236. font-size: 30rpx;
  237. color: #191919;
  238. font-weight: bold;
  239. margin-left: 20rpx;
  240. }
  241. .r {
  242. font-size: 30rpx;
  243. color: #ff4200;
  244. font-weight: bold;
  245. margin-left: auto;
  246. }
  247. }
  248. .bottom {
  249. min-height: 100rpx;
  250. position: fixed;
  251. left: 0;
  252. right: 0;
  253. bottom: 0;
  254. .box {
  255. display: flex;
  256. width: 100%;
  257. min-height: 100rpx;
  258. align-items: center;
  259. .l {
  260. padding-left: 30rpx;
  261. flex: 2;
  262. .t1 {
  263. color: #333;
  264. }
  265. .t2 {
  266. color: #ff4200;
  267. font-size: 38rpx;
  268. font-weight: bold;
  269. }
  270. }
  271. .r {
  272. flex: 1;
  273. .btn {
  274. background-color: #ff4200;
  275. min-height: 100rpx;
  276. display: flex;
  277. color: #fff;
  278. font-size: 30rpx;
  279. align-items: center;
  280. justify-content: center;
  281. }
  282. }
  283. }
  284. }
  285. @import '@/common/common.scss'
  286. </style>