handleMonthly.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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" @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 class="subtitle">前三个月每天首次一分钱<br/>长期八折优惠</view>
  63. </view>
  64. <view class="pay-way-item pay-way-item-jh" @click="wechatPay">
  65. <image src="../../static/img/juhe-icon.png" mode=""></image>
  66. <view class="title">聚合支付</view>
  67. </view>
  68. </view>
  69. <button class="pay-way-close-btn" @click="payWayPop = false">关闭</button>
  70. </view>
  71. </u-modal>
  72. <u-toast ref="uToast" />
  73. </view>
  74. </template>
  75. <script>
  76. import getUrlParams from "../../utils/getUrlParams.js";
  77. import {
  78. monthlyWxPay
  79. } from '@/common/http.api.js'
  80. export default {
  81. data() {
  82. return {
  83. startTime:'',
  84. endTime:'',
  85. payUrl:'',
  86. monthId: '',
  87. vehicleNo:'',
  88. monthEndTime:'',
  89. monthStartTime:'',
  90. lastActiveDate:null,
  91. roadNo:null,
  92. carLicenseList: [],
  93. isShowCarLicense: false,
  94. form: {
  95. energyType:[],
  96. monthAmount: [],
  97. carLicense: {},
  98. month: 1,
  99. dateRange:""
  100. },
  101. label:"",
  102. payWayPop: false,
  103. jumpUrl: undefined,
  104. monthlyContent: ''
  105. }
  106. },
  107. onLoad (page) {
  108. this.getSysterms(0)
  109. if (page.roadNo) {
  110. this.roadNo = page.roadNo;
  111. this.getMonthInfo(this.roadNo);
  112. }
  113. if (page.vehicleNo) {
  114. this.vehicleNo = page.vehicleNo
  115. }
  116. const baseUrl = window.location.href.split('#')[0]
  117. let jumpUrl = baseUrl + '#' + '/pages/center/monthly/monthly'
  118. this.jumpUrl = jumpUrl
  119. },
  120. mounted(){
  121. // console.log(this.lastActiveDate)
  122. // this.form.dateRange=this.getMonthRange(new Date(this.lastActiveDate),1)
  123. },
  124. methods: {
  125. /**
  126. * 获取几个月的日期范围
  127. * {date} Date 起始日期,往后推一天
  128. * {monthNum} Number 往后月数
  129. * */
  130. getMonthRange (date, monthNum) {
  131. let Date1 = this.lastActiveDate;
  132. // Date1 = Date1.valueOf() + 24 * 60 * 60 * 1000
  133. Date1 = new Date(Date1)
  134. const year = Date1.getFullYear()
  135. const month = Date1.getMonth()+1
  136. const day = Date1.getDate()
  137. const hours = Date1.getHours();
  138. const minutes = Date1.getMinutes();
  139. const seconds = Date1.getSeconds();
  140. let days = new Date(year, month, 0)
  141. days = days.getDate() //获取当前日期中的月的天数
  142. let year2 = year;
  143. let month2 = parseInt(month) + parseInt(monthNum)
  144. if (month2 > 12) {
  145. year2 = parseInt(year2) + parseInt((parseInt(month2) / 12 == 0 ? 1 : parseInt(month2) / 12))
  146. month2 = parseInt(month2) % 12;
  147. }
  148. let day2 = day;
  149. let days2 = new Date(year2, month2, 0)
  150. days2 = days2.getDate()
  151. if (day2 > days2) {
  152. day2 = days2
  153. }
  154. if (month2 < 10) {
  155. month2 = '0' + month2;
  156. }
  157. const t1 = year + '.' + (month > 9 ? month : '0' + month) + '.' + (day > 9 ? day : '0' + day)
  158. const t2 = year2 + '.' + month2 + '.' + (day2 > 9 ? day2 : '0' + day2)
  159. this.startTime=t1
  160. this.endTime=t2
  161. this.monthStartTime=year + '-' + (month > 9 ? month : '0' + month) + '-' + (day > 9 ? day : '0' + day) + ' ' + hours + ':' + minutes + ':' +seconds
  162. this.monthEndTime=year2 + '-' + month2 + '-' + day2 + ' ' + hours + ':' + minutes + ':' +seconds
  163. return t1 + '-' + t2
  164. },
  165. /**
  166. * 月操作 减1
  167. * */
  168. reduceMonthNum () {
  169. if (this.form.month > 1) {
  170. this.form.month -= 1
  171. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  172. }
  173. },
  174. /**
  175. * 月操作 加1
  176. * */
  177. addMonthNum () {
  178. if(this.form.month >=24){
  179. this.$refs.uToast.show({
  180. title: '最多24月',
  181. type: 'warning',
  182. })
  183. return
  184. }
  185. this.form.month += 1
  186. this.form.dateRange = this.getMonthRange(new Date, this.form.month)
  187. },
  188. carLicenseListConfirm (item) {
  189. console.log('this.carLicenseList',this.carLicenseList);
  190. console.log('item',item);
  191. this.form.carLicense = item[0]
  192. },
  193. getMonthInfo(roadNo){
  194. this.$u.api.monthInfo({roadNo: this.roadNo})
  195. .then(res => {
  196. if (res.code === 200){
  197. this.lastActiveDate = res.data.lastActiveDate;
  198. this.form.monthAmount=res.data.monthAmount;
  199. this.carLicenseList = [];
  200. let vehicleNoItem = null
  201. res.data.vehicleList.forEach(item => {
  202. const obj = {
  203. value: item.energyType,
  204. label: item.vehicleNo,
  205. energyType:item.energyType
  206. }
  207. if (this.vehicleNo == item.vehicleNo) {
  208. vehicleNoItem = obj
  209. }
  210. this.carLicenseList.push(obj)
  211. });
  212. // 判断是否url存在车牌号,存在则选中项默认选中
  213. if (vehicleNoItem) {
  214. this.form.carLicense = vehicleNoItem
  215. } else {
  216. this.form.carLicense = this.carLicenseList[0]
  217. }
  218. }
  219. })
  220. },
  221. submit(roadNo){
  222. this.$u.api.createMonth({
  223. roadNo:this.roadNo,
  224. vehicleNo:this.form.carLicense.label,
  225. energyType:this.form.carLicense.energyType,
  226. monthStartTime:this.monthStartTime,
  227. monthEndTime:this.monthEndTime,
  228. monthCount:this.form.month})
  229. .then(res => {
  230. console.log("createMonth",res)
  231. if(res.code === 200){
  232. this.monthId = res.data.monthId
  233. console.log(this.monthId)
  234. this.payWayPop = true
  235. }else{
  236. this.$refs.uToast.show({
  237. title: res.msg,
  238. type: 'warning',
  239. });
  240. }
  241. }).catch(err=>{
  242. });
  243. },
  244. gyBankPay() {
  245. this.$u.api.monthPay({
  246. monthId: this.monthId,
  247. jumpUrl: this.jumpUrl
  248. }).then(res => {
  249. if(res.code === 200){
  250. window.location.href = res.data.url
  251. } else {
  252. this.$refs.uToast.show({
  253. title: res.msg,
  254. type: 'error',
  255. });
  256. }
  257. })
  258. },
  259. /**
  260. * 微信支付
  261. * 判断vuex中是否存在openId
  262. * 存在直接调起微信支付
  263. * 不存在则通过微信登录去获取用户的code
  264. * 完成后通过code去获取用户的openId等信息
  265. * 最后再调起微信支付
  266. * */
  267. wechatPay() {
  268. // const openId = this.$store.state.vuex_wxinfo.openId
  269. // if (openId) {
  270. // this.getWXPay()
  271. // } else {
  272. // this.getCode()
  273. // }
  274. this.getWXPayByJava()
  275. },
  276. /**
  277. * 调起微信支付接口
  278. * @param {Array} list 需要支付的订单组合数组
  279. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  280. * */
  281. async getWXPay(){
  282. // 支付成功跳转到包月页面
  283. let params = {
  284. monthId: this.monthId,
  285. openid: this.$store.state.vuex_wxinfo.openId
  286. };
  287. await this.$wxApi.config();
  288. this.$pay.wechatPay(params, '/client/monthpay/wechat', this.jumpUrl).then(res =>{
  289. switch (Number(res.code)) {
  290. case 0: // 成功
  291. //#ifdef H5
  292. window.location.reload();
  293. //#endif
  294. break;
  295. case 1: // 取消
  296. this.$refs.uToast.show({
  297. title: '已取消支付',
  298. type: 'info',
  299. });
  300. break;
  301. case 2: // 支付失败
  302. this.$refs.uToast.show({
  303. title: '支付失败,请检查!',
  304. type: 'error',
  305. });
  306. break;
  307. }
  308. });
  309. },
  310. /**
  311. * 直接通过后台获取贵阳银行微信支付地址
  312. * @param {Array} list 需要支付的订单组合数组
  313. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  314. * */
  315. getWXPayByJava(orderList, deviceNo) {
  316. const jumpUrl = window.location.href.split('#')[0] + '#/pages/center/monthly/monthly'
  317. // 支付成功跳转到包月页面
  318. let params = {
  319. monthId: this.monthId,
  320. openid: '',
  321. jumpUrl: jumpUrl
  322. };
  323. this.$u.api.monthlyWxPay(params)
  324. .then(res => {
  325. if (res.code === 200) {
  326. location.href = res.data.qrCodeUrl
  327. } else {
  328. this.$refs.uToast.show({
  329. title: res.msg,
  330. type: 'error',
  331. });
  332. }
  333. })
  334. .catch(err => {
  335. this.$refs.uToast.show({
  336. title: '无法调起微信支付!',
  337. type: 'error',
  338. });
  339. })
  340. },
  341. /**
  342. * 获取code
  343. * 1 微信登录获取code
  344. * 2 url中截取
  345. * */
  346. getCode () {
  347. // 获取页面完整url
  348. const local = window.location.href
  349. // 获取url后面的参数
  350. const locationLocaturl = window.location.search;
  351. // 截取url中的code
  352. this.code = getUrlParams(locationLocaturl, "code");
  353. // 如果没有code,则去请求
  354. if (this.code == null || this.code === '') {
  355. 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`
  356. } else {
  357. // 把code传给后台获取用户信息
  358. this.handleGetWXInfo(this.code)
  359. }
  360. },
  361. /**
  362. * 通过code获取openId等用户信息
  363. * 拿到用户信息后再调起微信支付
  364. * */
  365. handleGetWXInfo (code) {
  366. let _this = this
  367. this.$u.api.getWXInfo(code).then((res) => {
  368. if (res.code === 200 ) {
  369. this.$u.vuex('vuex_wxinfo', res.data);
  370. this.getWXPay(this.currentItem)
  371. }
  372. }).catch((err) => {
  373. this.$refs.uToast.show({
  374. title: err.msg,
  375. type: 'error',
  376. });
  377. })
  378. },
  379. /**
  380. * 获取包月说明
  381. * */
  382. getSysterms(termsType) {
  383. this.$u.api.getSysterms({
  384. termsType: termsType
  385. })
  386. .then(res => {
  387. if (res.code === 200) {
  388. this.monthlyContent = res.data?.content
  389. } else {
  390. this.$refs.uToast.show({
  391. title: res.msg,
  392. type: 'error',
  393. })
  394. }
  395. })
  396. .catch(err => {
  397. this.$refs.uToast.show({
  398. title: '系统错误!',
  399. type: 'error',
  400. })
  401. })
  402. }
  403. },
  404. computed:{
  405. dateRange:function(){
  406. return this.getMonthRange(this.lastActiveDate,this.form.month)
  407. },
  408. },
  409. filters:{
  410. verifyStatusFilter(value) {
  411. if (value === 0) {
  412. return '';
  413. } else if(value === 1){
  414. return '汽油车';
  415. } else if(value === 2){
  416. return '新能源';
  417. } else {
  418. return '';
  419. }
  420. },
  421. }
  422. }
  423. </script>
  424. <style lang="scss" scoped>
  425. @import './handleMonthly.scss';
  426. @import '../paymentMethod/paymentMethod.scss'
  427. </style>