monthlyCardBuy.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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" >
  23. 仅限车主购买,适用于平台对外开放充电站
  24. </view>
  25. <view class="slogan-4" @click="gotoUrl('pages/monthlyCardActivity/monthlyCardList?cardId='+cardId)">
  26. 查看适用站点
  27. </view>
  28. <u-action-sheet :list="list" @click="click" v-model="show"></u-action-sheet>
  29. <u-modal v-model="showModel" :show-cancel-button="true" @cancel="getUserInfo()" @confirm="confirm" confirm-text="支付成功?" title="扫码支付">
  30. <view style="
  31. text-align: center;
  32. ">
  33. <img id="qrcode2" :src="qrCodeImg">
  34. </view>
  35. <view style="
  36. text-align: center;
  37. ">请使用支付宝扫码</view>
  38. </u-modal>
  39. <img id="qrcode" style="display: none;">
  40. <!-- 立即开通 -->
  41. <view class="bottom" v-if="islogin" >
  42. <button class="dredge" >已购买</button>
  43. </view>
  44. <!-- 立即开通 -->
  45. <view class="bottom" v-else-if="!islogin&&detail.price" >
  46. <button class="dredge" v-if="detail.putShelf&&!detail.isVip" @click="show = true">立即开通 ¥{{detail.price.toFixed(2)}}/月</button>
  47. <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>
  48. <button class="dredge" v-if="!detail.putShelf" @click="putShelf" > 已下架</button>
  49. <p>开通表示阅读并同意
  50. <text class="agreement" @click="gotoUrl('pages/article/details?code=FWFZKXY')">《服务费折扣协议》</text>
  51. </p>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import * as Pay from '@/apis/weixin.js'
  57. import * as API from '@/apis/card.js'
  58. import * as loginApi from '@/apis/login.js'
  59. import QRCode from 'qrcodejs2'
  60. import {
  61. convertCanvasToImage,
  62. } from '@/utils'
  63. import {
  64. wxPayJs
  65. } from '@/utils/wxpay'
  66. export default {
  67. data() {
  68. return {
  69. cardId:'3e1b0f8f-61b0-405f-a285-929b5346479f',
  70. qrCodeImg: "",
  71. showModel: false,
  72. list: [{
  73. text: '微信',
  74. }, {
  75. text: '支付宝'
  76. }],
  77. show: false,
  78. submitForm:{},
  79. detail:{},
  80. islogin:true,
  81. }
  82. },
  83. onReady() {
  84. this.getInfo();
  85. this.getUserInfo()
  86. },
  87. onShow(){
  88. this.getUserInfo();
  89. },
  90. methods: {
  91. userCardBool(userCard){
  92. if(userCard){
  93. var date=new Date().getTime()
  94. var date2=new Date(userCard.endTime).getTime();
  95. if(date<date2){
  96. return true;
  97. }
  98. }
  99. return false
  100. },
  101. getUserInfo(){
  102. uni.showLoading({
  103. title: "加载中",
  104. mask: true,
  105. })
  106. loginApi.findByOpenId({
  107. openId: this.carhelp.getOpenId(),
  108. onerror:true
  109. }).then((res) => {
  110. uni.hideLoading();
  111. if (res.code == 200&&res.result) {
  112. if(res.data.regUser){
  113. var userCard=res.data.userCard;
  114. this.islogin= this.userCardBool(userCard)
  115. }else{
  116. }
  117. }
  118. }).catch(error => {
  119. uni.showToast({
  120. title: error,
  121. icon: "none"
  122. })
  123. })
  124. },
  125. putShelf2(){
  126. uni.showToast({
  127. title:"暂不支持重复购买"
  128. })
  129. },
  130. putShelf(){
  131. uni.showToast({
  132. title:"已下架,暂不支持购买"
  133. })
  134. },
  135. getInfo(){
  136. uni.showLoading({
  137. title: "加载中",
  138. mask: true,
  139. })
  140. API.cardDetail({
  141. cardId:this.cardId
  142. }).then((response) => {
  143. console.log(response)
  144. this.detail=response.data.monthlyRentCard
  145. uni.hideLoading()
  146. }).catch(error => {
  147. uni.showToast({
  148. title: error
  149. })
  150. })
  151. },
  152. submit(type){
  153. uni.showLoading({
  154. title: "加载中",
  155. mask: true,
  156. })
  157. API.openCard({
  158. cardId:this.cardId
  159. }).then((response) => {
  160. this.submitForm.id=response.data.orderInfoId
  161. if(type==0){
  162. this.wxpy()
  163. }
  164. if(type==1){
  165. this.alpy()
  166. }
  167. }).catch(error => {
  168. uni.showToast({
  169. title: error
  170. })
  171. })
  172. },
  173. alpy() {
  174. uni.showLoading({
  175. title: "加载中",
  176. mask: true,
  177. })
  178. Pay.alpay(this.submitForm).then((response) => {
  179. let qrcode = new QRCode('qrcode', {
  180. width: 200,
  181. height: 200,
  182. text: response.data.qr_code,
  183. correctLevel: QRCode.CorrectLevel.M,
  184. })
  185. this.outOrderNo = response.data.outOrderNo;
  186. var canvas = document.getElementsByTagName('canvas')[0];
  187. this.qrCodeImg = convertCanvasToImage(canvas);
  188. uni.hideLoading()
  189. this.showModel = true
  190. }).catch(error => {
  191. uni.showToast({
  192. title: error
  193. })
  194. })
  195. },
  196. wxpy() {
  197. Pay.wxpay(this.submitForm).then((response) => {
  198. if (!response.result) {
  199. uni.showToast({
  200. title: response.message
  201. })
  202. return
  203. }
  204. var data = response.data
  205. uni.hideLoading()
  206. //("Pay+"+new Date().getTime())
  207. wxPayJs(data);
  208. }).catch(error => {
  209. uni.showToast({
  210. title: error
  211. })
  212. })
  213. },
  214. confirm() {
  215. this.getUserInfo();
  216. uni.redirectTo({
  217. url: "/pages/user/finance/rechargeRes?id=" + this.outOrderNo
  218. })
  219. },
  220. click(index) {
  221. console.log(`点击了第${index + 1}项,内容为:${this.list[index].text}`)
  222. this.submit(index);
  223. }
  224. }
  225. }
  226. </script>
  227. <style lang="scss" scoped>
  228. page {
  229. background-color: #2a2c31;
  230. }
  231. // 卡片
  232. .monthly-card {
  233. margin: 20px;
  234. border-radius: 16px;
  235. height: 150px;
  236. background: linear-gradient(#F2E6CA, #C9A87B);
  237. position: relative;
  238. .main {
  239. padding: 24px 0 24px 24px;
  240. height: 100%;
  241. background: url(@/assets/img/card@3.png);
  242. background-repeat: no-repeat;
  243. background-position: 30% 10%;
  244. background-size: cover;
  245. color: rgba(255, 255, 255, 100);
  246. border-radius: 6px;
  247. .title-1 {
  248. line-height: 28px;
  249. font-size: 56rpx;
  250. margin-bottom: 8px;
  251. }
  252. .title-2 {
  253. line-height: 24px;
  254. font-size: 34rpx;
  255. }
  256. }
  257. .cover {
  258. width: 102%;
  259. position: absolute;
  260. bottom: -10px;
  261. left: -2px;
  262. right: 0;
  263. }
  264. }
  265. .slogan-1 {
  266. height: 36px;
  267. color: rgba(234, 217, 180, 100);
  268. font-size: 48rpx;
  269. text-align: center;
  270. margin-bottom: 4px;
  271. }
  272. .slogan-2 {
  273. height: 36px;
  274. color: rgba(234, 217, 180, 100);
  275. font-size: 56rpx;
  276. text-align: center;
  277. margin-bottom: 12px;
  278. }
  279. .slogan-3 {
  280. height: 20px;
  281. color: rgba(255, 255, 255, 100);
  282. font-size: 28rpx;
  283. text-align: center;
  284. }
  285. .slogan-4 {
  286. text-decoration:underline;
  287. height: 20px;
  288. color: #9F9C99;
  289. font-size: 32rpx;
  290. text-align: center;
  291. }
  292. // 立即开通
  293. .bottom {
  294. position: fixed;
  295. background-color: #2a2c31;
  296. bottom: 0px;
  297. padding-bottom: 40px;
  298. left: 0;
  299. right: 0;
  300. .dredge {
  301. // width: 72.2%;
  302. margin: 0 20px;
  303. border-radius: 50px;
  304. font-size: 36rpx;
  305. background: linear-gradient(to right, #C9A87B, #F2E6CA);
  306. margin-bottom: 12px;
  307. }
  308. p {
  309. height: 20px;
  310. color: rgba(226, 222, 217, 100);
  311. font-size: 14px;
  312. text-align: center;
  313. }
  314. .agreement {
  315. color: #897a69;
  316. }
  317. }
  318. </style>