pay.vue 12 KB

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