App.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <div id="app">
  3. <div class="vip-container">
  4. <div class="vip-info">
  5. <div class="title">加入AI降临派VIP</div>
  6. <div class="desc">和我们一起探索AI的技术边界</div>
  7. <!-- <div class="date">
  8. <span class="oplist" @click="gotoOrderList" v-if="!isIOS">订单记录></span>
  9. <span v-if="isVIP">会员有效期至: {{ expireTime ? dateFormat(expireTime, 'yyyy-MM-dd') : '-'}}</span>
  10. </div> -->
  11. </div>
  12. <div>{{chatToken}}</div>
  13. <div>{{step}}</div>
  14. <div>{{error}}</div>
  15. <div class="vip-info vip-rights">
  16. <div class="title-view">
  17. <div class="tabitem" :class="{active: ctype == 1}" @click="ctype = 1">
  18. VIP会员权益
  19. </div>
  20. <div class="tabitem" :class="{active: ctype == 2}" @click="ctype = 2">
  21. AI能量包
  22. </div>
  23. </div>
  24. <div class="recharge-types">
  25. <div class="type-item" v-for="(item, index) in typelist" :class="{active: curIndex === index}"
  26. :key="index" @click="changeChargeType(index)">
  27. <div class="p1">{{ item.typename }}</div>
  28. <div class="p-now">{{ item.price }}</div>
  29. <div class="p-op">{{ item.op }}</div>
  30. <div class="p2" :class="{needScale: ctype == 1}">{{ item.desc }}</div>
  31. </div>
  32. </div>
  33. <div class="list" v-if="ctype == 1">
  34. <div class="list-item" v-for="(item, index) in list" :key="index">
  35. {{ item }}
  36. </div>
  37. </div>
  38. <div class="list" v-if="ctype == 2">
  39. <div class="list-item" v-for="(item, index) in list2" :key="index">
  40. {{ item }}
  41. </div>
  42. </div>
  43. </div>
  44. <div class="pay-view">
  45. <div class="pay-btn" @click="handlePay">
  46. 支付
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. import axios from 'axios'
  54. import { queryToObj } from './utils/index.js'
  55. const PAY_TYPE = {
  56. MONTHLY: 'MONTHLY', //包月
  57. SEASONALLY: 'SEASONALLY', //包季;
  58. YEARLY: 'YEARLY' ,// 包年
  59. S_PLUS: 'S_PLUS',
  60. M_PLUS: 'M_PLUS',
  61. L_PLUS: 'L_PLUS'
  62. }
  63. const baseurl = 'https://api.aibaidu.com.cn/'
  64. let chatSeq = 1000000
  65. export default {
  66. name: 'App',
  67. data() {
  68. return {
  69. chatToken: '',
  70. ctype: 1,
  71. list2: [
  72. '1、购买AI能量包立刻获得算力。',
  73. '2、多个AI能量包可重复可叠加购买,算力永不过期。'
  74. ],
  75. curIndex: 0,
  76. vipTypes: [
  77. { type: PAY_TYPE.MONTHLY, typename: '1个月VIP', op: '¥30', desc: '给程序员买杯咖啡'},
  78. { type: PAY_TYPE.SEASONALLY, typename: '3个月VIP', op: '¥90', desc: '请程序员喝个小酒'},
  79. { type: PAY_TYPE.YEARLY, typename: '12个月VIP', op: '¥360', desc: '请程序员吃顿大餐'}
  80. ],
  81. timesTypes: [
  82. { type: PAY_TYPE.S_PLUS, typename: '小能量包', op: '¥15', desc: '200点算力'},
  83. { type: PAY_TYPE.M_PLUS, typename: '中能量包', op: '¥30', desc: '400点算力'},
  84. { type: PAY_TYPE.L_PLUS, typename: '大能量包', op: '¥45', desc: '600点算力'}
  85. ],
  86. orderList: [],
  87. page: 1,
  88. step: 1,
  89. error: ''
  90. }
  91. },
  92. created() {
  93. const search = window.location.search
  94. const obj = queryToObj(search.substring(1))
  95. this.chatToken = obj.chatToken
  96. this.getProducts()
  97. },
  98. computed: {
  99. typelist() {
  100. if (this.ctype == 1) {
  101. return this.vipTypes
  102. } else if (this.ctype == 2) {
  103. return this.timesTypes
  104. } else {
  105. return []
  106. }
  107. },
  108. list() {
  109. const arr1 = [300, 1000, 5000]
  110. const arr2 = [10, 30, 120]
  111. return [
  112. `1、立即获得${arr1[this.curIndex]}点算力。`,
  113. `2、立即获得${arr2[this.curIndex]}次AI绘画插队权益。`,
  114. '3、每日签到领取20点算力,每月最多可领600点算力。',
  115. '4、每日签到领取2次AI绘画插队权益,每月最多可领60次绘画插队权益。',
  116. '5、在高峰时段获得AI智能问答优先回复,使用更顺畅。'
  117. ]
  118. }
  119. },
  120. methods: {
  121. async handlePay() {
  122. const type = this.typelist[this.curIndex].id
  123. const {data: res} = await axios({
  124. url: baseurl + 'wx-mp/preOrder',
  125. method: 'POST',
  126. headers: {
  127. 'content-type': 'application/x-www-form-urlencoded',
  128. 'chat-token': this.chatToken,
  129. 'chat-seq': chatSeq++
  130. },
  131. data: {
  132. type: type
  133. }
  134. })
  135. this.step = 2
  136. if (res.code === 0) {
  137. // eslint-disable-next-line
  138. this.payObj = res.data
  139. if (typeof WeixinJSBridge == "undefined") {
  140. this.error = 'WeixinJSBridge is undefined'
  141. if (document.addEventListener) {
  142. document.addEventListener(
  143. "WeixinJSBridgeReady",
  144. this.onBridgeReady,
  145. false
  146. );
  147. } else if (document.attachEvent) {
  148. document.attachEvent("WeixinJSBridgeReady", this.onBridgeReady);
  149. document.attachEvent("onWeixinJSBridgeReady", this.onBridgeReady);
  150. }
  151. } else {
  152. this.onBridgeReady();
  153. }
  154. }
  155. },
  156. onBridgeReady() {
  157. this.step = 3
  158. const that = this
  159. // eslint-disable-next-line
  160. WeixinJSBridge.invoke(
  161. "getBrandWCPayRequest",
  162. {
  163. appId: this.payObj.appId, //公众号ID,由商户传入
  164. timeStamp: this.payObj.timeStamp, //时间戳,自1970年以来的秒数
  165. nonceStr: this.payObj.nonceStr, //随机串
  166. package: this.payObj.packageVal,
  167. signType: this.payObj.signType, //微信签名方式:
  168. paySign: this.payObj.paySign, //微信签名
  169. },
  170. function (res) {
  171. that.error = JSON.stringify(res)
  172. that.step = 4
  173. console.log('支付结果:', res)
  174. if (res.err_msg == "get_brand_wcpay_request:ok") {
  175. // 使用以上方式判断前端返回,微信团队郑重提示:
  176. //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  177. alert("支付成功");
  178. }
  179. // that.closePage();
  180. }
  181. );
  182. },
  183. changeChargeType(index) {
  184. this.curIndex = index
  185. },
  186. async getProducts() {
  187. const {data: res} = await axios({
  188. url: baseurl + 'user/products',
  189. method: 'GET',
  190. headers: {
  191. 'content-type': 'application/x-www-form-urlencoded',
  192. 'chat-token': this.chatToken,
  193. 'chat-seq': chatSeq++
  194. }
  195. })
  196. if (res.code === 0) {
  197. const vips = []
  198. res.data.vip.map((m, index) => {
  199. const price = `¥${parseFloat((m.amount / 100).toFixed(2))}`
  200. vips[index] = {...this.vipTypes[index], ...m, price}
  201. })
  202. this.vipTypes = vips;
  203. const plus = []
  204. res.data.plus.map((m, index) => {
  205. const price = `¥${parseFloat((m.amount / 100).toFixed(2))}`
  206. plus[index] = {...this.timesTypes[index], ...m, price}
  207. })
  208. this.timesTypes = plus
  209. }
  210. },
  211. closePage() {
  212. var userAgent = navigator.userAgent;
  213. if (
  214. userAgent.indexOf("Firefox") != -1 ||
  215. userAgent.indexOf("Chrome") != -1
  216. ) {
  217. // Firefox或Chrome中关闭
  218. window.location.href = "about:blank";
  219. } else {
  220. window.opener = null;
  221. window.open("", "_self");
  222. window.close();
  223. }
  224. // eslint-disable-next-line
  225. if (WeixinJSBridge) {
  226. // 微信中关闭
  227. // eslint-disable-next-line
  228. wx.closeWindow();
  229. }
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="less" scoped>
  235. // @import url('./assets/mixin.less');
  236. .combtn(@fs: 28rpx, @lineHeight: 60rpx) {
  237. font-size: @fs;
  238. line-height: @lineHeight;
  239. background-color: @mainColor;
  240. border: none;
  241. color: #FFF;
  242. text-align: center;
  243. border-radius: 8rpx;
  244. &:active {
  245. background-color: lighten(@mainColor, 5%);
  246. }
  247. }
  248. #app {
  249. font-family: 'Avenir', Helvetica, Arial, sans-serif;
  250. -webkit-font-smoothing: antialiased;
  251. -moz-osx-font-smoothing: grayscale;
  252. text-align: left;
  253. color: #EFEFEF;
  254. /* margin-top: 60px; */
  255. background-color: #33373f;
  256. height: 100vh;
  257. }
  258. .vip-container {
  259. padding: 20px;
  260. background-color: @mainBg;
  261. height: 100%;
  262. color: #EDEDED;
  263. .iosview {
  264. margin-top: 15px;
  265. color: @fontColor;
  266. }
  267. .btnview {
  268. margin-top: 150px;
  269. padding: 30px;
  270. .subbtn {
  271. .combtn(16px, 50px);
  272. }
  273. }
  274. .vip-info {
  275. padding: 10px 15px;
  276. background-color: lighten(@mainBg, 10%);
  277. border-radius: 6px;
  278. .title {
  279. color: @mainColor;
  280. font-size: 18px;
  281. font-weight: 600;
  282. }
  283. .desc {
  284. font-size: 14px;
  285. padding-top: 2px;
  286. }
  287. .date {
  288. padding-top: 12px;
  289. display: flex;
  290. justify-content: space-between;
  291. .oplist {
  292. color: @mainColor;
  293. }
  294. }
  295. }
  296. .vip-rights {
  297. margin-top: 15px;
  298. padding-bottom: 20px;
  299. height: 400px;
  300. box-sizing: border-box;
  301. .title-view {
  302. display: flex;
  303. .tabitem {
  304. line-height: 36px;
  305. flex: 1;
  306. color: @fontColor;
  307. font-size: 16px;
  308. font-weight: 600;
  309. text-align: center;
  310. position: relative;
  311. &.active {
  312. color: @mainColor;
  313. }
  314. &:last-child::after {
  315. content: "";
  316. height: 14px;
  317. left: 0;
  318. top: 11px;
  319. width: 1px;
  320. background-color: #EDEDED;
  321. position: absolute;
  322. }
  323. }
  324. }
  325. .list {
  326. padding: 10px 0;
  327. .list-item {
  328. padding: 2px 0;
  329. }
  330. }
  331. .recharge-types {
  332. padding-top: 12px;
  333. display: flex;
  334. .type-item {
  335. flex: 1;
  336. border: 1px solid @mainColor;
  337. background-color: transparent;
  338. border-radius: 4px;
  339. text-align: center;
  340. font-size: 12px;
  341. padding: 10px 0;
  342. // font-weight: 600;
  343. &:not(:last-child) {
  344. margin-right: 10px;
  345. }
  346. &.active {
  347. color: #fff;
  348. background-color: #32715f;
  349. }
  350. .p1 {
  351. font-size: 14px;
  352. }
  353. .p-now {
  354. font-weight: 600;
  355. font-size: 24px;
  356. line-height: 50px;
  357. }
  358. .p-op {
  359. font-size: 14px;
  360. text-decoration: line-through;
  361. }
  362. .p2.needScale {
  363. line-height: 20px;
  364. transform: scale(0.85);
  365. word-break: keep-all;
  366. }
  367. }
  368. }
  369. }
  370. .pay-view {
  371. position: fixed;
  372. padding: 10px 0;
  373. bottom: 40px;
  374. left: 0;
  375. display: flex;
  376. flex-direction: column;
  377. justify-content: center;
  378. align-items: center;
  379. width: 100%;
  380. box-sizing: border-box;
  381. .pay-btn {
  382. width: 160px;
  383. line-height: 40px;
  384. text-align: center;
  385. background-color: @mainColor;
  386. border-radius: 4px;
  387. color: #fff;
  388. font-size: 16px;
  389. }
  390. .paydesc {
  391. text-align: center;
  392. font-size: 12px;
  393. padding: 5px 0;
  394. }
  395. }
  396. }
  397. </style>