pay.vue 10 KB

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