monthlyCardBuy.vue 13 KB

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