pay.vue 12 KB

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