pay.vue 12 KB

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