pay.vue 9.0 KB

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