monthlyCardBuy.vue 10 KB

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