monthlyCardBuy3.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <template>
  2. <view>
  3. <ujp-navbar title="包月卡购买"></ujp-navbar>
  4. <!-- 卡片 -->
  5. <view class="monthly-card-bgc">
  6. <view class="monthly-card">
  7. <view class="main">
  8. <view class="title-1">
  9. 充电服务费包月卡
  10. </view>
  11. <view class="title-2">
  12. 到期时间:{{userCard&&ispay?userCard.endTime:'未购买'}}<br />
  13. 有效期内,合约充电站使用度数无上限
  14. </view>
  15. </view>
  16. <img class="cover" src="../../assets/img/cover@3.png" alt="">
  17. </view>
  18. </view>
  19. <view class="slogan-1">
  20. 充电服务费包月卡
  21. </view>
  22. <view class="slogan-2">
  23. 单次购买、整月受益!
  24. </view>
  25. <!-- <view class="slogan-3" style="color: #ead9b4;" >
  26. 限时活动结束时间2022年8月8日0点结束
  27. </view> -->
  28. <!-- 营运车辆 -->
  29. <template v-for="(item,i) in cardList" >
  30. <view class="operating" :class="{
  31. 'operating-coach':item.monthlyRentCard.id==cardId,
  32. 'non-operational-car':item.monthlyRentCard.id!=cardId,
  33. }"
  34. @click="cardId=item.monthlyRentCard.id,detail=item.monthlyRentCard"
  35. :key="i">
  36. <view class="type">
  37. <view class="title">
  38. <text class="img">
  39. <img v-if="item.monthlyRentCard.id==cardId" src="../../assets/img/antFill-crown@3x.png" alt="">
  40. <img v-else src="../../assets/img/antFill-crown2.svg" alt="">
  41. </text>{{item.monthlyRentCard.name}}
  42. </view>
  43. <view class="hint">
  44. {{item.monthlyRentCard.remark}}
  45. </view>
  46. </view>
  47. <view class="price">
  48. <text class="num">{{item.monthlyRentCard.price.toFixed(2)}}</text>
  49. <text class="unit">元</text>
  50. </view>
  51. </view>
  52. </template>
  53. <view class="slogan-3">
  54. <view v-html="ykgz"></view>
  55. <view class="slogan-4"
  56. v-if="cardId||ispay"
  57. @click="gotoUrl('pages/monthlyCardActivity/monthlyCardList?cardId='+(ispay?userCard.rentCardId:cardId))">
  58. 查看本活动适用站点
  59. </view>
  60. </view>
  61. <u-action-sheet :list="list" @click="click" v-model="show"></u-action-sheet>
  62. <u-modal v-model="showModel" :show-cancel-button="true" @cancel="getUserInfo()" @confirm="confirm"
  63. confirm-text="支付成功?" title="扫码支付">
  64. <view style="
  65. text-align: center;
  66. ">
  67. <img id="qrcode2" :src="qrCodeImg">
  68. </view>
  69. <view style="
  70. text-align: center;
  71. ">请使用支付宝扫码</view>
  72. </u-modal>
  73. <img id="qrcode" style="display: none;">
  74. <!-- 立即开通 -->
  75. <view class="bottom" v-if="ispay">
  76. <button class="dredge">已购买</button>
  77. </view>
  78. <view class="bottom" v-else-if="!endCardBool">
  79. <button class="dredge">已下架</button>
  80. </view>
  81. <view class="bottom" v-else-if="!show2" @click="gotoGz">
  82. <button class="dredge">关注公众号</button>
  83. </view>
  84. <view class="bottom" v-else-if="!infoSet" @click="gotoUrl('pages/user/dataSet')">
  85. <button class="dredge">完善个人信息</button>
  86. </view>
  87. <!-- 立即开通 -->
  88. <view class="bottom" v-else-if="!ispay">
  89. <button class="dredge" v-if="detail.putShelf&&!detail.isVip" @click="show = true">立即开通
  90. ¥{{detail.price.toFixed(2)}}/月</button>
  91. <button class="dredge" v-if="detail.putShelf&&detail.isVip" @click="show = true">{{detail.platformText}}车主特惠
  92. ¥{{detail.price.toFixed(2)}}/月<span
  93. style="font-size: 12px; text-decoration: line-through;">¥{{detail.oldPrice.toFixed(2)}}</span></button>
  94. <button class="dredge" v-if="!cardList.length" @click="putShelf"> 已下架</button>
  95. <p>开通表示阅读并同意
  96. <text class="agreement" @click="gotoUrl('pages/article/details?code=FWFZKXY')">《服务费折扣协议》</text>
  97. </p>
  98. </view>
  99. <u-modal v-model="show1" @confirm="gotoGz" cancel-text="暂不关注" confirm-text="前往关注" confirm-color="#53b56b"
  100. :show-cancel-button="true" ref="uModal2" :asyncClose="true">
  101. <view style="padding: 15px;">请先关注<span style=" color: #53b56b;">{{projectName}}</span>公众号,购买月卡</view>
  102. </u-modal>
  103. <u-modal v-model="infoSet1" @confirm="infoSet1=false,gotoUrl('pages/user/dataSet')" cancel-text="取消"
  104. confirm-text="完善个人信息" confirm-color="#53b56b" :show-cancel-button="true" ref="uModal2" :asyncClose="true">
  105. <view style="padding: 15px;">购买月卡需要完善以下2点<br />
  106. 1.填写真实姓名<br />
  107. 2.填写车牌号<br />
  108. </view>
  109. </u-modal>
  110. </view>
  111. </template>
  112. <script>
  113. import * as API_weixin from '@/apis/weixin.js'
  114. import * as Pay from '@/apis/weixin.js'
  115. import * as API from '@/apis/card.js'
  116. import * as loginApi from '@/apis/login.js'
  117. import QRCode from 'qrcodejs2'
  118. import {
  119. newDate,
  120. convertCanvasToImage,
  121. } from '@/utils'
  122. import {
  123. wxPayJs
  124. } from '@/utils/wxpay'
  125. export default {
  126. data() {
  127. return {
  128. cardId: '',
  129. qrCodeImg: "",
  130. showModel: false,
  131. cardList:[],
  132. projectName: "",
  133. list: [{
  134. text: '微信',
  135. }, {
  136. text: '支付宝'
  137. }],
  138. show: false,
  139. submitForm: {},
  140. ykgz: '',
  141. detail: {},
  142. ispay: false,
  143. show2: false,
  144. show1: false,
  145. infoSet: false,
  146. infoSet1: false,
  147. userCard: null,
  148. }
  149. },
  150. onLoad() {
  151. this.projectName = process.car.ProjectName;
  152. },
  153. onReady() {
  154. this.ykgz = this.carhelp.getConfig().ykgz
  155. //this.checkSubscribe()
  156. },
  157. onShow() {
  158. this.checkSubscribe();
  159. },
  160. computed: {
  161. endCardBool() {
  162. if(!this.cardList.length){
  163. return false;
  164. }
  165. var date = new Date().getTime()
  166. if (!this.detail.endTime) {
  167. return true;
  168. }
  169. var date2 = newDate(this.detail.endTime).getTime();
  170. if (date < date2) {
  171. return true;
  172. } else {
  173. return false;
  174. }
  175. }
  176. },
  177. methods: {
  178. gotoGz() {
  179. this.carhelp.setGzDate()
  180. var url = "https://mp.weixin.qq.com/s/mCHz1nNvg0xAICiBeIyKRQ";
  181. window.location.href = url
  182. },
  183. checkSubscribe() {
  184. API_weixin.checkSubscribe({
  185. openId: this.carhelp.getOpenId()
  186. }).then((res) => {
  187. if (res.data == "0") {
  188. this.show1 = true
  189. } else {
  190. //this.getInfo();
  191. this.getCardList();
  192. this.show2 = true;
  193. //this.carhelp.setGzDate()
  194. }
  195. //setGzDate
  196. }).catch(error => {
  197. uni.showToast({
  198. title: error
  199. })
  200. })
  201. },
  202. userCardBool(userCard) {
  203. if (userCard) {
  204. var date = new Date().getTime()
  205. var date2 = newDate(userCard.endTime).getTime();
  206. if (date < date2) {
  207. return true;
  208. }
  209. }
  210. return false
  211. },
  212. getCardList(){
  213. uni.showLoading({
  214. title: "加载中",
  215. mask: true,
  216. })
  217. API.cardList({
  218. }).then((response) => {
  219. this.cardList=response.data.cardList;
  220. if(this.cardList.length){
  221. this.detail = this.cardList[0].monthlyRentCard
  222. this.cardId=this.detail.id;
  223. }
  224. this.getUserInfo()
  225. console.log(this.cardList)
  226. //cardId: this.cardId
  227. uni.hideLoading()
  228. }).catch(error => {
  229. uni.showToast({
  230. title: error
  231. })
  232. })
  233. },
  234. getUserInfo() {
  235. uni.showLoading({
  236. title: "加载中",
  237. mask: true,
  238. })
  239. loginApi.findByOpenId({
  240. openId: this.carhelp.getOpenId(),
  241. noerror: true
  242. }).then((res) => {
  243. uni.hideLoading();
  244. if (res.code == 200 && res.result) {
  245. if (res.data.regUser) {
  246. var userInfo = res.data.regUser
  247. if (userInfo.carId && userInfo.realName) {
  248. this.infoSet = true;
  249. } else {
  250. this.infoSet = false;
  251. if(this.endCardBool){
  252. this.infoSet1 = true;
  253. }
  254. }
  255. var userCard = res.data.userCard;
  256. this.userCard = userCard
  257. this.ispay = this.userCardBool(userCard)
  258. } else {
  259. }
  260. }
  261. }).catch(error => {
  262. uni.showToast({
  263. title: error,
  264. icon: "none"
  265. })
  266. })
  267. },
  268. putShelf2() {
  269. uni.showToast({
  270. title: "暂不支持重复购买"
  271. })
  272. },
  273. putShelf() {
  274. uni.showToast({
  275. title: "已下架,暂不支持购买"
  276. })
  277. },
  278. getInfo() {
  279. uni.showLoading({
  280. title: "加载中",
  281. mask: true,
  282. })
  283. API.cardDetail({
  284. cardId: this.cardId
  285. }).then((response) => {
  286. console.log(response)
  287. this.detail = response.data.monthlyRentCard
  288. uni.hideLoading()
  289. }).catch(error => {
  290. uni.showToast({
  291. title: error
  292. })
  293. })
  294. },
  295. submit(type) {
  296. if (!this.endCardBool) {
  297. return
  298. }
  299. uni.showLoading({
  300. title: "加载中",
  301. mask: true,
  302. })
  303. API.openCard({
  304. cardId: this.cardId
  305. }).then((response) => {
  306. this.submitForm.id = response.data.orderInfoId
  307. if (type == 0) {
  308. this.wxpy()
  309. }
  310. if (type == 1) {
  311. this.alpy()
  312. }
  313. }).catch(error => {
  314. uni.showToast({
  315. title: error
  316. })
  317. })
  318. },
  319. alpy() {
  320. uni.showLoading({
  321. title: "加载中",
  322. mask: true,
  323. })
  324. var listcanvas=document.getElementsByTagName('canvas')
  325. console.log(listcanvas.length)
  326. if(listcanvas.length>0){
  327. document.getElementById("qrcode").removeChild(document.getElementsByTagName('canvas')[0]);
  328. }
  329. Pay.alpay(this.submitForm).then((response) => {
  330. let qrcode = new QRCode('qrcode', {
  331. width: 200,
  332. height: 200,
  333. text: response.data.qr_code,
  334. correctLevel: QRCode.CorrectLevel.M,
  335. })
  336. this.outOrderNo = response.data.outOrderNo;
  337. var canvas = document.getElementsByTagName('canvas')[0];
  338. this.qrCodeImg = convertCanvasToImage(canvas);
  339. uni.hideLoading()
  340. this.showModel = true
  341. }).catch(error => {
  342. uni.showToast({
  343. title: error
  344. })
  345. })
  346. },
  347. wxpy() {
  348. Pay.wxpay(this.submitForm).then((response) => {
  349. if (!response.result) {
  350. uni.showToast({
  351. title: response.message
  352. })
  353. return
  354. }
  355. var data = response.data
  356. uni.hideLoading()
  357. //("Pay+"+new Date().getTime())
  358. wxPayJs(data);
  359. }).catch(error => {
  360. uni.showToast({
  361. title: error
  362. })
  363. })
  364. },
  365. confirm() {
  366. this.getUserInfo();
  367. uni.redirectTo({
  368. url: "/pages/user/finance/rechargeRes?id=" + this.outOrderNo
  369. })
  370. },
  371. click(index) {
  372. console.log(`点击了第${index + 1}项,内容为:${this.list[index].text}`)
  373. this.submit(index);
  374. }
  375. }
  376. }
  377. </script>
  378. <style lang="scss" scoped>
  379. page {
  380. background-color: #2a2c31;
  381. padding-bottom: 200px;
  382. }
  383. .monthly-card-bgc {
  384. padding: 20px;
  385. background-color: #101010;
  386. height: 150px;
  387. position: relative;
  388. }
  389. // 卡片
  390. .monthly-card {
  391. border-radius: 16px;
  392. height: 150px;
  393. background: linear-gradient(#F2E6CA, #C9A87B);
  394. .main {
  395. padding: 24px 0 24px 24px;
  396. height: 100%;
  397. background: url(@/assets/img/card@3.png);
  398. background-repeat: no-repeat;
  399. background-position: 30% 10%;
  400. background-size: cover;
  401. color: rgba(255, 255, 255, 100);
  402. border-radius: 6px;
  403. .title-1 {
  404. line-height: 28px;
  405. font-size: 56rpx;
  406. margin-bottom: 8px;
  407. }
  408. .title-2 {
  409. line-height: 24px;
  410. font-size: 34rpx;
  411. }
  412. }
  413. .cover {
  414. width: 100%;
  415. position: absolute;
  416. bottom: -30px;
  417. left: 0px;
  418. right: 0;
  419. }
  420. }
  421. .slogan-1 {
  422. margin-top: 40px;
  423. height: 36px;
  424. color: rgba(234, 217, 180, 100);
  425. font-size: 48rpx;
  426. text-align: center;
  427. margin-bottom: 4px;
  428. }
  429. .slogan-2 {
  430. height: 36px;
  431. color: rgba(234, 217, 180, 100);
  432. font-size: 56rpx;
  433. text-align: center;
  434. margin-bottom: 12px;
  435. }
  436. .slogan-3 {
  437. text-align: initial;
  438. padding: 0 40px;
  439. line-height: 24px;
  440. color: #CCCCCC;
  441. font-size: 28rpx;
  442. }
  443. .slogan-4 {
  444. margin-top: 10px;
  445. text-decoration: underline;
  446. height: 20px;
  447. color: #9F9C99;
  448. font-size: 32rpx;
  449. text-align: center;
  450. }
  451. .operating{
  452. border: 1px solid rgba(100, 90, 77, 100);
  453. padding: 30rpx;
  454. margin: 32rpx 40rpx 0;
  455. //background: linear-gradient(to right, #bc9663, #79674d);
  456. display: flex;
  457. justify-content: space-between;
  458. color: #fff;
  459. border-radius: 12px;
  460. .title {
  461. color: rgba(255, 255, 255, 100);
  462. font-size: 18px;
  463. line-height: 20px;
  464. .img {
  465. display: inline-block;
  466. background-color: #fff;
  467. width: 40rpx;
  468. height: 40rpx;
  469. border-radius: 8rpx;
  470. line-height: 36rpx;
  471. margin-right: 8rpx;
  472. img {
  473. width: 24rpx;
  474. height: 24rpx;
  475. margin-left: 8rpx;
  476. }
  477. }
  478. }
  479. .hint {
  480. color: rgba(255, 255, 255, 100);
  481. font-size: 12px;
  482. line-height: 24px;
  483. margin-top: 4px;
  484. }
  485. .price {
  486. color: rgba(255, 255, 255, 100);
  487. margin: auto 0;
  488. .num {
  489. font-size:56rpx;
  490. }
  491. .unit {
  492. font-size: 32rpx;
  493. margin-left: 8rpx;
  494. }
  495. }
  496. }
  497. // 营运车辆,非营业车辆
  498. .operating-coach {
  499. background: linear-gradient(to right, #bc9663, #79674d);
  500. .title {
  501. .img {
  502. background-color: #fff;
  503. }
  504. }
  505. .price {
  506. color: rgba(255, 255, 255, 100);
  507. }
  508. }
  509. .non-operational-car{
  510. .title {
  511. .img {
  512. background:linear-gradient(#f2e6ca,#c9a87b) ;
  513. }
  514. }
  515. .price {
  516. color: rgba(211, 189, 158, 100);
  517. }
  518. }
  519. // 立即开通
  520. .bottom {
  521. position: fixed;
  522. background-color: #2a2c31;
  523. bottom: 0px;
  524. padding-bottom: 40px;
  525. left: 0;
  526. right: 0;
  527. .dredge {
  528. // width: 72.2%;
  529. margin: 0 20px;
  530. border-radius: 50px;
  531. font-size: 36rpx;
  532. background: linear-gradient(to right, #C9A87B, #F2E6CA);
  533. margin-bottom: 12px;
  534. }
  535. p {
  536. height: 20px;
  537. color: rgba(226, 222, 217, 100);
  538. font-size: 14px;
  539. text-align: center;
  540. }
  541. .agreement {
  542. color: #897a69;
  543. }
  544. }
  545. </style>