pay.vue 11 KB

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