pay.vue 11 KB

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