monthlyCardBuy.vue 9.3 KB

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