pay.vue 11 KB

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