handleMonthly.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. this.form.carLicense = item[0]
  190. },
  191. getMonthInfo(roadNo){
  192. this.$u.api.monthInfo({roadNo: this.roadNo})
  193. .then(res => {
  194. if (res.code === 200){
  195. this.lastActiveDate = res.data.lastActiveDate;
  196. this.form.monthAmount=res.data.monthAmount;
  197. this.carLicenseList = [];
  198. let vehicleNoItem = null
  199. res.data.vehicleList.forEach(item => {
  200. const obj = {
  201. value: item.energyType,
  202. label: item.vehicleNo,
  203. energyType:item.energyType
  204. }
  205. if (this.vehicleNo == item.vehicleNo) {
  206. vehicleNoItem = obj
  207. }
  208. this.carLicenseList.push(obj)
  209. });
  210. // 判断是否url存在车牌号,存在则选中项默认选中
  211. if (vehicleNoItem) {
  212. this.form.carLicense = vehicleNoItem
  213. } else {
  214. this.form.carLicense = this.carLicenseList[0]
  215. }
  216. }
  217. })
  218. },
  219. submit(roadNo){
  220. this.$u.api.createMonth({
  221. roadNo:this.roadNo,
  222. vehicleNo:this.form.carLicense.label,
  223. energyType:this.form.carLicense.energyType,
  224. monthStartTime:this.monthStartTime,
  225. monthEndTime:this.monthEndTime,
  226. monthCount:this.form.month})
  227. .then(res => {
  228. console.log("createMonth",res)
  229. if(res.code === 200){
  230. this.monthId = res.data.monthId
  231. console.log(this.monthId)
  232. this.payWayPop = true
  233. }else{
  234. this.$refs.uToast.show({
  235. title: res.msg,
  236. type: 'error',
  237. });
  238. }
  239. }).catch(err=>{
  240. this.$refs.uToast.show({
  241. title: '程序错误!',
  242. type: 'error',
  243. });
  244. });
  245. },
  246. gyBankPay() {
  247. console.log(this.jumpUrl)
  248. this.$u.api.monthPay({
  249. monthId: this.monthId,
  250. jumpUrl: this.jumpUrl
  251. }).then(res => {
  252. if(res.code === 200){
  253. window.location.href = res.data.url
  254. } else {
  255. this.$refs.uToast.show({
  256. title: res.msg,
  257. type: 'error',
  258. });
  259. }
  260. })
  261. },
  262. /**
  263. * 微信支付
  264. * 判断vuex中是否存在openId
  265. * 存在直接调起微信支付
  266. * 不存在则通过微信登录去获取用户的code
  267. * 完成后通过code去获取用户的openId等信息
  268. * 最后再调起微信支付
  269. * */
  270. wechatPay() {
  271. // const openId = this.$store.state.vuex_wxinfo.openId
  272. // if (openId) {
  273. // this.getWXPay()
  274. // } else {
  275. // this.getCode()
  276. // }
  277. this.getWXPayByJava()
  278. },
  279. /**
  280. * 调起微信支付接口
  281. * @param {Array} list 需要支付的订单组合数组
  282. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  283. * */
  284. async getWXPay(){
  285. // 支付成功跳转到包月页面
  286. let params = {
  287. monthId: this.monthId,
  288. openid: this.$store.state.vuex_wxinfo.openId
  289. };
  290. await this.$wxApi.config();
  291. this.$pay.wechatPay(params, '/client/monthpay/wechat', this.jumpUrl).then(res =>{
  292. switch (Number(res.code)) {
  293. case 0: // 成功
  294. //#ifdef H5
  295. window.location.reload();
  296. //#endif
  297. break;
  298. case 1: // 取消
  299. this.$refs.uToast.show({
  300. title: '已取消支付',
  301. type: 'info',
  302. });
  303. break;
  304. case 2: // 支付失败
  305. this.$refs.uToast.show({
  306. title: '支付失败,请检查!',
  307. type: 'error',
  308. });
  309. break;
  310. }
  311. });
  312. },
  313. /**
  314. * 直接通过后台获取贵阳银行微信支付地址
  315. * @param {Array} list 需要支付的订单组合数组
  316. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  317. * */
  318. getWXPayByJava(orderList, deviceNo) {
  319. // 支付成功跳转到包月页面
  320. let params = {
  321. monthId: this.monthId,
  322. openid: '',
  323. jumpUrl: this.jumpUrl
  324. };
  325. this.$u.api.monthlyWxPay(params)
  326. .then(res => {
  327. if (res.code === 200) {
  328. location.href = res.data.qrCodeUrl
  329. } else {
  330. this.$refs.uToast.show({
  331. title: res.msg,
  332. type: 'error',
  333. });
  334. }
  335. })
  336. .catch(err => {
  337. this.$refs.uToast.show({
  338. title: '无法调起微信支付!',
  339. type: 'error',
  340. });
  341. })
  342. },
  343. /**
  344. * 获取code
  345. * 1 微信登录获取code
  346. * 2 url中截取
  347. * */
  348. getCode () {
  349. // 获取页面完整url
  350. const local = window.location.href
  351. // 获取url后面的参数
  352. const locationLocaturl = window.location.search;
  353. // 截取url中的code
  354. this.code = getUrlParams(locationLocaturl, "code");
  355. // 如果没有code,则去请求
  356. if (this.code == null || this.code === '') {
  357. 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`
  358. } else {
  359. // 把code传给后台获取用户信息
  360. this.handleGetWXInfo(this.code)
  361. }
  362. },
  363. /**
  364. * 通过code获取openId等用户信息
  365. * 拿到用户信息后再调起微信支付
  366. * */
  367. handleGetWXInfo (code) {
  368. let _this = this
  369. this.$u.api.getWXInfo(code).then((res) => {
  370. if (res.code === 200 ) {
  371. this.$u.vuex('vuex_wxinfo', res.data);
  372. this.getWXPay(this.currentItem)
  373. }
  374. }).catch((err) => {
  375. this.$refs.uToast.show({
  376. title: err.msg,
  377. type: 'error',
  378. });
  379. })
  380. },
  381. /**
  382. * 获取包月说明
  383. * */
  384. getSysterms(termsType) {
  385. this.$u.api.getSysterms({
  386. termsType: termsType
  387. })
  388. .then(res => {
  389. if (res.code === 200) {
  390. this.monthlyContent = res.data?.content
  391. } else {
  392. this.$refs.uToast.show({
  393. title: res.msg,
  394. type: 'error',
  395. })
  396. }
  397. })
  398. .catch(err => {
  399. this.$refs.uToast.show({
  400. title: '系统错误!',
  401. type: 'error',
  402. })
  403. })
  404. }
  405. },
  406. computed:{
  407. dateRange:function(){
  408. return this.getMonthRange(this.lastActiveDate,this.form.month)
  409. },
  410. },
  411. filters:{
  412. verifyStatusFilter(value) {
  413. if (value === 0) {
  414. return '';
  415. } else if(value === 1){
  416. return '汽油车';
  417. } else if(value === 2){
  418. return '新能源';
  419. } else {
  420. return '';
  421. }
  422. },
  423. }
  424. }
  425. </script>
  426. <style lang="scss" scoped>
  427. @import './handleMonthly.scss';
  428. @import '../paymentMethod/paymentMethod.scss'
  429. </style>