pay.vue 12 KB

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