pay.vue 11 KB

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