handleMonthly.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <template>
  2. <view class="handle-monthly">
  3. <view class="handle-monthly-item">
  4. <view>车牌选择</view>
  5. <view class="choose-license" @click="isShowCarLicense = true">
  6. <view>{{form.carLicense.label}}</view>
  7. <u-icon name="arrow-down" color="#7B7B7B" size="30"></u-icon>
  8. </view>
  9. </view>
  10. <u-select v-model="isShowCarLicense" :list="carLicenseList" :default-value="carLicenseDefaultValue" @confirm="carLicenseListConfirm"></u-select>
  11. <view class="handle-monthly-item">
  12. <view>车辆信息</view>
  13. <view>{{form.carLicense.value | verifyStatusFilter}}</view>
  14. </view>
  15. <view class="handle-monthly-item">
  16. <view>包月金额</view>
  17. <view class="handle-monthly-money">{{form.monthAmount}}元</view>
  18. </view>
  19. <view class="handle-monthly-item">
  20. <view>包月时长</view>
  21. <view class="handle-monthly-time-long">
  22. <button @click="reduceMonthNum()">-</button>
  23. <view>{{form.month}}个月</view>
  24. <button @click="addMonthNum()">+</button>
  25. </view>
  26. </view>
  27. <view class="handle-monthly-item">
  28. <view>有效期限</view>
  29. <view>{{dateRange}}</view>
  30. </view>
  31. <view class="handle-monthly-explain">
  32. <!-- <view>包月说明</view>
  33. <view>1、停车不足30分钟,免费;</view>
  34. <view>2、停车 超过20分钟,按2元/小时收费;</view>
  35. <view>3、月卡会员在有效期内停车免费</view> -->
  36. <u-parse :html="monthlyContent"></u-parse>
  37. </view>
  38. <view class="handle-monthly-confirm-button">
  39. <button type="default"@click="submit(roadNo)">确认包月</button>
  40. </view>
  41. <u-modal
  42. v-model="payWayPop"
  43. :title-style="{color: '#404040'}"
  44. title="缴费方式"
  45. :show-confirm-button="false"
  46. :show-cancel-button="false">
  47. <view class="slot-content">
  48. <!-- <view class="pay-way">
  49. <view class="pay-way-item" @click="gyBankPay">
  50. <image src="../../static/img/gy-bank-pay-icon.png" mode=""></image>
  51. <view>贵州银行</view>
  52. </view>
  53. <view class="pay-way-item" @click="wechatPay">
  54. <image src="../../static/img/wechat-pay-icon.png" mode=""></image>
  55. <view>微信支付</view>
  56. </view>
  57. </view> -->
  58. <view class="pay-way-new">
  59. <view class="pay-way-item pay-way-item-hy" @click="gyBankPay">
  60. <image src="../../static/img/guiyang-bank-icon.png" mode=""></image>
  61. <view class="title">贵州银行</view>
  62. </view>
  63. <view class="pay-way-item pay-way-item-jh" @click="juhePay">
  64. <image src="../../static/img/juhe-icon.png" mode=""></image>
  65. <view class="title">聚合支付</view>
  66. </view>
  67. </view>
  68. <view class="pay-way-subtitle">
  69. <view class="pay-way-subtitle-item">前三个月每天首次一分钱,长期八折优惠</view>
  70. <view class="pay-way-subtitle-item">&nbsp;</view>
  71. </view>
  72. <button class="pay-way-close-btn" @click="payWayPop = false">关闭</button>
  73. </view>
  74. </u-modal>
  75. <u-toast ref="uToast" />
  76. </view>
  77. </template>
  78. <script>
  79. import getUrlParams from "../../utils/getUrlParams.js";
  80. import {
  81. getEnvIsWx
  82. } from '@/utils/judgEnvironment.js';
  83. import $wxPay from '@/utils/wxPay.js'
  84. import {
  85. monthlyWxPay
  86. } from '@/common/http.api.js'
  87. export default {
  88. data() {
  89. return {
  90. startTime:'',
  91. endTime:'',
  92. payUrl:'',
  93. monthId: '',
  94. vehicleNo:'',
  95. monthEndTime:'',
  96. monthStartTime:'',
  97. lastActiveDate:null,
  98. roadNo:null,
  99. carLicenseList: [],
  100. isShowCarLicense: false,
  101. form: {
  102. energyType:[],
  103. monthAmount: [],
  104. carLicense: {},
  105. month: 1,
  106. dateRange:""
  107. },
  108. label:"",
  109. payWayPop: false,
  110. jumpUrl: undefined,
  111. monthlyContent: '',
  112. carLicenseDefaultValue: [0],
  113. wxEnv: false
  114. }
  115. },
  116. onLoad(page) {
  117. this.wxEnv = getEnvIsWx();
  118. this.getSysterms(0)
  119. if (page.vehicleNo && page.vehicleNo) {
  120. this.roadNo = page.roadNo;
  121. this.vehicleNo = page.vehicleNo
  122. this.getMonthInfo(this.roadNo, this.vehicleNo);
  123. } else if (page.roadNo) {
  124. this.roadNo = page.roadNo;
  125. this.getMonthInfo(this.roadNo);
  126. }
  127. const baseUrl = window.location.href.split('#')[0]
  128. let jumpUrl = baseUrl + '#/pages/center/monthly/monthly'
  129. this.jumpUrl = jumpUrl
  130. },
  131. mounted(){
  132. // console.log(this.lastActiveDate)
  133. // this.form.dateRange=this.getMonthRange(new Date(this.lastActiveDate),1)
  134. },
  135. methods: {
  136. /**
  137. * 获取几个月的日期范围
  138. * {date} Date 起始日期,往后推一天
  139. * {monthNum} Number 往后月数
  140. * */
  141. getMonthRange (date, monthNum) {
  142. let Date1 = this.lastActiveDate;
  143. // Date1 = Date1.valueOf() + 24 * 60 * 60 * 1000
  144. Date1 = new Date(Date1)
  145. const year = Date1.getFullYear()
  146. const month = Date1.getMonth()+1
  147. const day = Date1.getDate()
  148. const hours = Date1.getHours();
  149. const minutes = Date1.getMinutes();
  150. const seconds = Date1.getSeconds();
  151. let days = new Date(year, month, 0)
  152. days = days.getDate() //获取当前日期中的月的天数
  153. let year2 = year;
  154. let month2 = parseInt(month) + parseInt(monthNum)
  155. if (month2 > 12) {
  156. year2 = parseInt(year2) + parseInt((parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12))
  157. month2 = parseInt(month2) % 12;
  158. }
  159. let day2 = day;
  160. let days2 = new Date(year2, month2, 0)
  161. days2 = days2.getDate()
  162. if (day2 > days2) {
  163. day2 = days2
  164. }
  165. if (month2 < 10) {
  166. month2 = '0' + month2;
  167. }
  168. const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day)
  169. const t2 = year2 + '.' + month2 + '.' + (day2 > 9 ? day2 : '0' + day2)
  170. this.startTime=t1
  171. this.endTime=t2
  172. this.monthStartTime=year + '-' + (month > 9 ? month : '0' + month) + '-' + (day > 9 ? day : '0' + day) + ' ' + hours + ':' + minutes + ':' +seconds
  173. this.monthEndTime=year2 + '-' + month2 + '-' + day2 + ' ' + hours + ':' + minutes + ':' +seconds
  174. return t1 + '-' + t2
  175. },
  176. /**
  177. * 月操作 减1
  178. * */
  179. reduceMonthNum () {
  180. if (this.form.month > 1) {
  181. this.form.month -= 1
  182. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  183. }
  184. },
  185. /**
  186. * 月操作 加1
  187. * */
  188. addMonthNum () {
  189. if(this.form.month >=24){
  190. this.$refs.uToast.show({
  191. title: '最多24月',
  192. type: 'warning',
  193. })
  194. return
  195. }
  196. this.form.month += 1
  197. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  198. },
  199. carLicenseListConfirm (item) {
  200. this.form.carLicense = item[0]
  201. this.vehicleNo = item[0].label
  202. this.getMonthInfo(this.roadNo, this.vehicleNo)
  203. },
  204. getMonthInfo(roadNo, vehicleNo){
  205. this.$u.api.monthInfo({roadNo: roadNo, vehicleNo: vehicleNo})
  206. .then(res => {
  207. if (res.code === 200){
  208. this.lastActiveDate = res.data.lastActiveDate;
  209. this.form.monthAmount=res.data.monthAmount;
  210. this.carLicenseList = [];
  211. let vehicleNoItem = null
  212. res.data.vehicleList.forEach((item, index) => {
  213. const obj = {
  214. value: item.energyType,
  215. label: item.vehicleNo,
  216. energyType:item.energyType
  217. }
  218. if (this.vehicleNo == item.vehicleNo) {
  219. vehicleNoItem = obj
  220. this.carLicenseDefaultValue = [index]
  221. }
  222. this.carLicenseList.push(obj)
  223. });
  224. // 判断是否url存在车牌号,存在则选中项默认选中
  225. if (vehicleNoItem) {
  226. this.form.carLicense = vehicleNoItem
  227. } else {
  228. this.form.carLicense = this.carLicenseList[0]
  229. }
  230. }
  231. })
  232. },
  233. submit(roadNo){
  234. this.$u.api.createMonth({
  235. roadNo:this.roadNo,
  236. vehicleNo:this.form.carLicense.label,
  237. energyType:this.form.carLicense.energyType,
  238. monthStartTime:this.monthStartTime,
  239. monthEndTime:this.monthEndTime,
  240. monthCount:this.form.month})
  241. .then(res => {
  242. console.log("createMonth",res)
  243. if(res.code === 200){
  244. this.monthId = res.data.monthId
  245. console.log(this.monthId)
  246. this.payWayPop = true
  247. }else{
  248. this.$refs.uToast.show({
  249. title: res.msg,
  250. type: 'error',
  251. });
  252. }
  253. }).catch(err=>{
  254. this.$refs.uToast.show({
  255. title: '程序错误!',
  256. type: 'error',
  257. });
  258. });
  259. },
  260. gyBankPay() {
  261. console.log(this.jumpUrl)
  262. this.$u.api.monthPay({
  263. monthId: this.monthId,
  264. jumpUrl: this.jumpUrl
  265. }).then(res => {
  266. if(res.code === 200){
  267. window.location.href = res.data.url
  268. } else {
  269. this.$refs.uToast.show({
  270. title: res.msg,
  271. type: 'error',
  272. });
  273. }
  274. })
  275. },
  276. /**
  277. * 微信支付
  278. * 判断vuex中是否存在openId
  279. * 存在直接调起微信支付
  280. * 不存在则通过微信登录去获取用户的code
  281. * 完成后通过code去获取用户的openId等信息
  282. * 最后再调起微信支付
  283. * */
  284. juhePay() {
  285. // const openId = this.$store.state.vuex_wxinfo.openId
  286. // if (openId) {
  287. // this.getWXPay()
  288. // } else {
  289. // this.getCode()
  290. // }
  291. this.getWXPayByJava()
  292. },
  293. /**
  294. * 微信支付
  295. */
  296. wechatPay() {
  297. this.$u.api.wechatPayApi({
  298. orderList: this.curOrderList,
  299. openid: this.vuex_wxinfo.openId
  300. }).then(res => {
  301. if (res.code === 200) {
  302. $wxPay.wexinPay(res.data.wx).then(res1 => {
  303. switch (Number(res1.code)) {
  304. case 0: // 成功
  305. //#ifdef H5
  306. window.location.reload();
  307. //#endif
  308. break;
  309. case 1: // 取消
  310. this.$refs.uToast.show({
  311. title: '已取消支付',
  312. type: 'info'
  313. });
  314. break;
  315. case 2: // 支付失败
  316. this.$refs.uToast.show({
  317. title: '支付失败,请检查!',
  318. type: 'error'
  319. });
  320. break;
  321. }
  322. })
  323. }
  324. })
  325. },
  326. /**
  327. * 调起微信支付接口
  328. * @param {Array} list 需要支付的订单组合数组
  329. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  330. * */
  331. async getWXPay(){
  332. // 支付成功跳转到包月页面
  333. let params = {
  334. monthId: this.monthId,
  335. openid: this.$store.state.vuex_wxinfo.openId
  336. };
  337. await this.$wxApi.config();
  338. this.$pay.wechatPay(params, '/client/monthpay/wechat', this.jumpUrl).then(res =>{
  339. switch (Number(res.code)) {
  340. case 0: // 成功
  341. //#ifdef H5
  342. window.location.reload();
  343. //#endif
  344. break;
  345. case 1: // 取消
  346. this.$refs.uToast.show({
  347. title: '已取消支付',
  348. type: 'info',
  349. });
  350. break;
  351. case 2: // 支付失败
  352. this.$refs.uToast.show({
  353. title: '支付失败,请检查!',
  354. type: 'error',
  355. });
  356. break;
  357. }
  358. });
  359. },
  360. /**
  361. * 直接通过后台获取贵阳银行微信支付地址
  362. * @param {Array} list 需要支付的订单组合数组
  363. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  364. * */
  365. getWXPayByJava(orderList, deviceNo) {
  366. // 支付成功跳转到包月页面
  367. let params = {
  368. monthId: this.monthId,
  369. openid: '',
  370. jumpUrl: this.jumpUrl
  371. };
  372. this.$u.api.monthlyWxPay(params)
  373. .then(res => {
  374. if (res.code === 200) {
  375. // if (getEnvIsWx()) {
  376. // location.href = res.data.qrCodeUrl + '&jump_url=' + encodeURIComponent(this.jumpUrl)
  377. // } else {
  378. // location.href = res.data.qrCodeUrl
  379. // }
  380. localStorage.setItem('jumpUrl', this.jumpUrl)
  381. location.href = res.data.qrCodeUrl
  382. } else {
  383. this.$refs.uToast.show({
  384. title: res.msg,
  385. type: 'error',
  386. });
  387. }
  388. })
  389. .catch(err => {
  390. this.$refs.uToast.show({
  391. title: '无法调起微信支付!',
  392. type: 'error',
  393. });
  394. })
  395. },
  396. /**
  397. * 获取code
  398. * 1 微信登录获取code
  399. * 2 url中截取
  400. * */
  401. getCode () {
  402. // 获取页面完整url
  403. const local = window.location.href
  404. // 获取url后面的参数
  405. const locationLocaturl = window.location.search;
  406. // 截取url中的code
  407. this.code = getUrlParams(locationLocaturl, "code");
  408. // 如果没有code,则去请求
  409. if (this.code == null || this.code === '') {
  410. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.config.wxAppid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_userinfo&#wechat_redirect`
  411. } else {
  412. // 把code传给后台获取用户信息
  413. this.handleGetWXInfo(this.code)
  414. }
  415. },
  416. /**
  417. * 通过code获取openId等用户信息
  418. * 拿到用户信息后再调起微信支付
  419. * */
  420. handleGetWXInfo (code) {
  421. let _this = this
  422. this.$u.api.getWXInfo(code).then((res) => {
  423. if (res.code === 200 ) {
  424. this.$u.vuex('vuex_wxinfo', res.data);
  425. this.getWXPay(this.currentItem)
  426. }
  427. }).catch((err) => {
  428. this.$refs.uToast.show({
  429. title: err.msg,
  430. type: 'error',
  431. });
  432. })
  433. },
  434. /**
  435. * 获取包月说明
  436. * */
  437. getSysterms(termsType) {
  438. this.$u.api.getSysterms({
  439. termsType: termsType
  440. })
  441. .then(res => {
  442. if (res.code === 200) {
  443. this.monthlyContent = res.data?.content
  444. } else {
  445. this.$refs.uToast.show({
  446. title: res.msg,
  447. type: 'error',
  448. })
  449. }
  450. })
  451. .catch(err => {
  452. this.$refs.uToast.show({
  453. title: '系统错误!',
  454. type: 'error',
  455. })
  456. })
  457. }
  458. },
  459. computed:{
  460. dateRange:function(){
  461. return this.getMonthRange(this.lastActiveDate,this.form.month)
  462. },
  463. },
  464. filters:{
  465. verifyStatusFilter(value) {
  466. if (value === 0) {
  467. return '';
  468. } else if(value === 1){
  469. return '汽油车';
  470. } else if(value === 2){
  471. return '新能源';
  472. } else {
  473. return '';
  474. }
  475. },
  476. }
  477. }
  478. </script>
  479. <style lang="scss" scoped>
  480. @import './handleMonthly.scss';
  481. @import '../paymentMethod/paymentMethod.scss'
  482. </style>