pay.vue 6.9 KB

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