pay.vue 8.9 KB

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