monthlyCardBuy.vue 11 KB

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