handleMonthly.vue 13 KB

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