pay.vue 12 KB

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