handleMonthly.vue 12 KB

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