pay.vue 8.6 KB

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