monthlyCardBuy.vue 8.1 KB

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