pay.vue 13 KB

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