pay.vue 11 KB

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