purchase.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <template>
  2. <layout
  3. :bgImgName="currentLoading ? 'purchase-img' : ''"
  4. bgColor="#FDF2E3"
  5. bgHeight="219"
  6. @goBack="goBack"
  7. >
  8. <div class="purchase" v-if="currentLoading">
  9. <div class="purchase-privilege">
  10. <div>
  11. <img src="@/assets/image/claimCloudPhone/privilege-1.png" alt="" />
  12. 应用预装已完成
  13. </div>
  14. <div style="animation-delay: 0.2s">
  15. <img src="@/assets/image/claimCloudPhone/privilege-2.png" alt="" />
  16. 任意下单
  17. </div>
  18. <div style="animation-delay: 0.4s">
  19. <img src="@/assets/image/claimCloudPhone/privilege-3.png" alt="" />
  20. 立即使用云机
  21. </div>
  22. </div>
  23. <template v-for="item in packageList">
  24. <setMealItem
  25. :key="item.serialNumber"
  26. :data="item"
  27. v-if="item.mealList && item.mealList.length"
  28. :type="0"
  29. @buy="buy"
  30. />
  31. </template>
  32. <van-popup
  33. v-model="visible"
  34. position="bottom"
  35. :style="{ background: 'transparent' }"
  36. >
  37. <div class="payment-container">
  38. <div class="payment-container-title">新增云手机</div>
  39. <div class="payment-container-info">
  40. <div>
  41. <div class="payment-container-info_value">
  42. <span>¥</span>{{ currentData.actualPrice }}
  43. </div>
  44. <div class="payment-container-info_name">
  45. {{ packageType[currentData.phoneType]
  46. }}{{ currentData.day }}天卡
  47. </div>
  48. </div>
  49. </div>
  50. <div class="payment-container-num">
  51. 数量:<van-stepper button-size="18" v-model="stepper" />
  52. </div>
  53. <div class="payment-container-method">
  54. <div class="payment-container-method_title">选择支付方式</div>
  55. <div class="payment-container-method_select">
  56. <template v-for="item in paymentList">
  57. <div
  58. :key="item.key"
  59. v-if="
  60. currentData.paySupportTypeList &&
  61. currentData.paySupportTypeList.includes(item.key)
  62. "
  63. :class="{ active: active === item.key }"
  64. @click="active = item.key"
  65. >
  66. <img
  67. :src="active === item.key ? item.activeImg : item.img"
  68. alt=""
  69. />
  70. {{ item.name }}
  71. <div v-if="active === item.key" class="active-icon">
  72. <van-icon name="success" />
  73. </div>
  74. </div>
  75. </template>
  76. </div>
  77. </div>
  78. <div class="payment-container-amount">
  79. <div>
  80. 需支付金额:<span
  81. ><span>¥</span>{{ currentData.actualPrice * stepper }}
  82. </span>
  83. </div>
  84. <div @click="payment" :class="{ disabled: btnLoading }">
  85. <template v-if="btnLoading"> 正在支付中... </template>
  86. <template v-else> 确认协议并付款</template>
  87. </div>
  88. </div>
  89. <div class="payment-container-agreement">
  90. 购买前阅读<span @click="toAgreement">
  91. 《双子星云手机服务协议》
  92. </span>
  93. </div>
  94. </div>
  95. </van-popup>
  96. <van-dialog
  97. v-model="activityPurchaseVisible"
  98. @cancel="confirm(false)"
  99. @confirm="confirm(true)"
  100. show-cancel-button
  101. confirmButtonText="已完成支付"
  102. confirmButtonColor="#3367d1"
  103. >
  104. <div class="payment-tips">如果您已支付成功</div>
  105. <div class="payment-tips">请点击"已完成支付"按钮</div>
  106. </van-dialog>
  107. </div>
  108. </layout>
  109. </template>
  110. <script>
  111. import layout from './components/layout';
  112. import setMealItem from './components/setMealItem.vue';
  113. import common from './mixins/common.js';
  114. const RSA = require('@/plugins/wx_rsa.js');
  115. export default {
  116. auth: false,
  117. name: 'purchase',
  118. head: {
  119. title: '0元购机,尽情享受',
  120. },
  121. mixins: [common],
  122. data() {
  123. return {
  124. visible: false,
  125. currentData: {},
  126. packageType: {
  127. VIP: '星动',
  128. SVIP: '星曜',
  129. STARRYSKY: '星空',
  130. STAR: '唔即',
  131. STARPRO: '唔即Pro',
  132. },
  133. stepper: 1,
  134. active: '',
  135. paymentList: [
  136. {
  137. name: '微信',
  138. img: require('@/assets/image/claimCloudPhone/weChat.png'),
  139. activeImg: require('@/assets/image/claimCloudPhone/weChatActvie.png'),
  140. key: 'wxPay',
  141. },
  142. {
  143. name: '支付宝',
  144. img: require('@/assets/image/claimCloudPhone/alipay.png'),
  145. activeImg: require('@/assets/image/claimCloudPhone/alipayActive.png'),
  146. key: 'aliPay',
  147. },
  148. ],
  149. btnLoading: false,
  150. activityPurchaseVisible: false,
  151. };
  152. },
  153. mounted() {
  154. if (sessionStorage.getItem('isAgreementBool')) {
  155. this.currentData = JSON.parse(sessionStorage.getItem('currentData'));
  156. this.stepper = sessionStorage.getItem('stepper');
  157. this.active = sessionStorage.getItem('active');
  158. this.visible = true;
  159. sessionStorage.removeItem('isAgreementBool');
  160. sessionStorage.removeItem('currentData');
  161. sessionStorage.removeItem('active');
  162. sessionStorage.removeItem('stepper');
  163. }
  164. if (localStorage.getItem('activityPurchaseVisible')) {
  165. this.activityPurchaseVisible = true;
  166. localStorage.removeItem('activityPurchaseVisible');
  167. }
  168. this.getActivitySortRuleAndActivityMealList({
  169. personnelMealType: 2,
  170. });
  171. },
  172. components: { layout, setMealItem },
  173. methods: {
  174. buy(data) {
  175. console.log(data);
  176. this.stepper = 1;
  177. this.visible = true;
  178. this.currentData = JSON.parse(JSON.stringify(data));
  179. this.currentData.paySupportTypeList =
  180. this.currentData.paySupportTypeList.split(',');
  181. this.active = this.currentData.paySupportTypeList[0];
  182. },
  183. // 确认支付
  184. payment() {
  185. let params = {
  186. buyType: 1,
  187. quantity: this.stepper,
  188. id: this.currentData.id,
  189. phoneType: this.currentData.phoneType,
  190. activityId: 690009,
  191. returnUrl: location.origin + '/h5/claimCloudPhone/confirmation',
  192. };
  193. params = this.sort_ASCII(params);
  194. console.log(params);
  195. const sign = this.jiaqian(JSON.stringify(params));
  196. this.btnLoading = true;
  197. this.$axios
  198. .$post('pay/v1/order/create', params, { headers: { sign } })
  199. .then((res) => {
  200. console.log(res);
  201. const obj = {
  202. aliPay: 'pay/v1/alipay/h5/spend',
  203. wxPay: 'pay/v1/wxPay/h5/spend',
  204. };
  205. if (res.success) {
  206. localStorage.setItem(
  207. 'activityPurchaseMyOrderNum',
  208. res.data.myOrderNum,
  209. );
  210. const data = {
  211. myOrderNum: res.data.myOrderNum,
  212. };
  213. const headers = {
  214. sign: this.jiaqian(JSON.stringify(data)),
  215. };
  216. this.$axios
  217. .$get(obj[this.active], { headers, params: data })
  218. .then((res) => {
  219. if (this.active === 'aliPay') {
  220. const div = document.createElement('div');
  221. div.innerHTML = res.data;
  222. document.body.appendChild(div);
  223. document.forms[0].submit();
  224. // 这个是为了兼容安卓支付宝没有跳转页面
  225. localStorage.setItem('activityPurchaseVisible', 1);
  226. setTimeout(() => {
  227. this.activityPurchaseVisible = true;
  228. }, 3000);
  229. div.remove();
  230. } else {
  231. window.location.replace(res.data);
  232. }
  233. })
  234. .catch((error) => {
  235. setTimeout(() => {
  236. this.$toast(error.message);
  237. });
  238. })
  239. .finally(() => {
  240. this.btnLoading = false;
  241. });
  242. }
  243. })
  244. .catch((error) => {
  245. this.$toast(error.message);
  246. this.btnLoading = false;
  247. });
  248. // function
  249. },
  250. sort_ASCII(obj) {
  251. var arr = [];
  252. var num = 0;
  253. for (const i in obj) {
  254. arr[num] = i;
  255. num++;
  256. }
  257. var sortArr = arr.sort();
  258. var sortObj = {};
  259. for (var i in sortArr) {
  260. sortObj[sortArr[i]] = obj[sortArr[i]];
  261. }
  262. return sortObj;
  263. },
  264. jiaqian(content) {
  265. console.log(content);
  266. const PrivateKey =
  267. '-----BEGIN PRIVATE KEY-----MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKCIK/zTSJCP4XhNsb7Mc5lALog+oAja/spMjg8U6rAmVzRtKv8qhw1HK0CRbW/XV66uM+kY7fhjaYbjbbzu2PMMfs2GVpG15jCWLug9fn2hvPT1wkXfooJX61yHK7+inxAXPi4vPNi263mSQGbhZTeqbU5p7nLeRGbdFyBQXVKpAgMBAAECgYAu/475RxZAlI8rPHvkY1EYteypoMQTs6HSslUI31PSXHc9dxSWfenqHkLwdWM30jDuiDvUa6MIDHrRrfXr0XWcQ0IJ93jT7ABkFCdxcKEOG1WE8f1kZ5JyPDJjeQiI9R4jJCukpGU0DdzO7ORvRb4oTFQ15quM+3+SjnK5TtfUsQJBAOLLk03D2s7t2R0GPLZq+WL/ebowbRSy4VHP/IQi4K1bJrll0HLznov60m9UML1ATlS2ub98fBRFXEAaAwJE2O0CQQC1NDEWhrAPU5o3xjjcxIUbbYskskbhjaiX/1Vz0UzS4XfYek4SL68WBWPGWTrSbgbvXtaXj0gmcChF5jxOHtUtAkA4mPsqxfy99UdgYeUW1P1lgkH7gAhIyRdH1nK6+wU83el9DPaHKVrgrfiEBeuf3wNtSqhyK/u/B0wtRxCHKW1FAkAXfwcGdryJoDuVE9z3s3vXDKNIRN2wDaBY5UD9XZxqk9XoeiN5dDltz5EafSOFecLocxG8YVXntg9i0PHs506ZAkEAge9AKaXisZ4jCNHRn1LR2R82RtHTLb2mN3Cc6sGo+SnAKczwRwVg9RgnmaLG4Z/7kJpq0ALgEBlkOmy+9joxAw==-----END PRIVATE KEY-----';
  268. const signature = new RSA.KJUR.crypto.Signature({
  269. alg: 'SHA256withRSA',
  270. });
  271. signature.init(PrivateKey);
  272. signature.updateString(content);
  273. const signData = signature.sign();
  274. // 将内容转成base64
  275. return RSA.hex2b64(signData);
  276. },
  277. toAgreement() {
  278. sessionStorage.setItem('currentData', JSON.stringify(this.currentData));
  279. sessionStorage.setItem('active', this.active);
  280. sessionStorage.setItem('stepper', this.stepper);
  281. this.$router.push(
  282. '/claimCloudPhone/agreement?agreementCoding=XYPZYHXY2002',
  283. );
  284. },
  285. goBack() {
  286. this.$router.push('/claimCloudPhone/inviteeExits');
  287. },
  288. confirm(bool) {
  289. if (bool) return this.$router.replace('/claimCloudPhone/confirmation');
  290. this.activityPurchaseVisible = false;
  291. localStorage.removeItem('activityPurchaseVisible');
  292. },
  293. },
  294. };
  295. </script>
  296. <style lang="less" scoped>
  297. .purchase {
  298. height: 100%;
  299. box-sizing: border-box;
  300. padding-top: 210px;
  301. .purchase-privilege {
  302. padding: 16px;
  303. height: 102px;
  304. background: #ffffff;
  305. box-shadow: 0px 2px 4px 0px #f6e5d3;
  306. border-radius: 8px;
  307. display: flex;
  308. justify-content: space-between;
  309. & > div {
  310. opacity: 0;
  311. animation: purchase 0.3s forwards linear;
  312. text-align: center;
  313. font-family: PingFangSC, PingFang SC;
  314. font-weight: 400;
  315. font-size: 14px;
  316. color: #1c2023;
  317. line-height: 20px;
  318. font-style: normal;
  319. & > img {
  320. width: 42px;
  321. height: 42px;
  322. display: block;
  323. margin: 0 auto;
  324. }
  325. }
  326. }
  327. .payment-container {
  328. border-radius: 10px 10px 0 0;
  329. padding: 16px;
  330. display: flex;
  331. flex-direction: column;
  332. background: #f4f6f8;
  333. overflow-y: auto;
  334. .payment-container-title {
  335. font-family: PingFangSC, PingFang SC;
  336. font-weight: 500;
  337. font-size: 18px;
  338. color: #0a132b;
  339. line-height: 20px;
  340. text-align: center;
  341. font-style: normal;
  342. }
  343. .payment-container-info {
  344. margin-top: 16px;
  345. height: 100px;
  346. background: #ffffff;
  347. border-radius: 16px;
  348. display: flex;
  349. justify-content: center;
  350. align-items: center;
  351. .payment-container-info_value {
  352. font-family: PingFangSC, PingFang SC;
  353. font-weight: 500;
  354. font-size: 28px;
  355. color: #0a132b;
  356. line-height: 32px;
  357. text-align: center;
  358. font-style: normal;
  359. span {
  360. font-size: 18px;
  361. }
  362. }
  363. .payment-container-info_name {
  364. font-family: PingFangSC, PingFang SC;
  365. font-weight: 400;
  366. font-size: 14px;
  367. color: #0a132b;
  368. line-height: 18px;
  369. text-align: center;
  370. font-style: normal;
  371. }
  372. }
  373. .payment-container-num {
  374. margin-top: 16px;
  375. padding: 16px;
  376. box-sizing: border-box;
  377. height: 50px;
  378. background: #ffffff;
  379. border-radius: 16px;
  380. font-family: PingFangSC, PingFang SC;
  381. font-weight: bold;
  382. font-size: 14px;
  383. color: #0a132b;
  384. line-height: 18px;
  385. text-align: left;
  386. display: flex;
  387. font-style: normal;
  388. .van-stepper {
  389. margin-left: 10px;
  390. }
  391. }
  392. .payment-container-method {
  393. .payment-container-method_title {
  394. font-family: PingFangSC, PingFang SC;
  395. font-weight: bold;
  396. font-size: 14px;
  397. color: #0a132b;
  398. line-height: 18px;
  399. text-align: left;
  400. font-style: normal;
  401. margin: 16px 0;
  402. }
  403. .payment-container-method_select {
  404. display: grid;
  405. grid-gap: 10px;
  406. grid-template-columns: repeat(3, 1fr);
  407. & > div {
  408. height: 54px;
  409. line-height: 54px;
  410. background: #edeef0;
  411. border-radius: 6px;
  412. display: flex;
  413. justify-content: center;
  414. align-items: center;
  415. font-family: PingFangSC, PingFang SC;
  416. color: #666666;
  417. border: 1px solid transparent;
  418. font-style: normal;
  419. font-weight: 500;
  420. font-size: 14px;
  421. line-height: 18px;
  422. font-style: normal;
  423. &.active {
  424. background: #ffffff;
  425. border-radius: 6px;
  426. border: 1px solid #3b7fff;
  427. position: relative;
  428. .active-icon {
  429. position: absolute;
  430. top: 0;
  431. right: 0;
  432. width: 26px;
  433. height: 15px;
  434. background: #3a86fe;
  435. border-radius: 0px 6px 0px 6px;
  436. display: flex;
  437. justify-content: center;
  438. align-items: center;
  439. .van-icon-success {
  440. color: #fff;
  441. }
  442. }
  443. }
  444. & > img {
  445. width: 24px;
  446. height: 24px;
  447. margin-right: 4px;
  448. }
  449. }
  450. }
  451. }
  452. .payment-container-amount {
  453. background: #ffffff;
  454. box-shadow: 0px 0px 13px 0px rgba(206, 206, 206, 0.5);
  455. border-radius: 16px;
  456. display: flex;
  457. justify-content: space-between;
  458. margin-top: 24px;
  459. & > div:first-of-type {
  460. font-family: PingFangSC, PingFang SC;
  461. font-weight: 500;
  462. font-size: 14px;
  463. color: #0a132b;
  464. line-height: 20px;
  465. font-style: normal;
  466. padding: 16px 0 16px 16px;
  467. & > span {
  468. font-weight: 500;
  469. font-size: 24px;
  470. color: #f04646;
  471. line-height: 20px;
  472. text-align: left;
  473. font-style: normal;
  474. span {
  475. font-size: 14px;
  476. }
  477. }
  478. }
  479. & > div:last-of-type {
  480. font-family: PingFangSC, PingFang SC;
  481. font-weight: 600;
  482. font-size: 16px;
  483. color: #ffffff;
  484. line-height: 22px;
  485. text-align: center;
  486. font-style: normal;
  487. line-height: 55px;
  488. height: 55px;
  489. width: 136px;
  490. background: linear-gradient(90deg, #38aefc 0%, #3b7fff 100%);
  491. border-radius: 16px;
  492. }
  493. }
  494. .payment-container-agreement {
  495. margin-top: 9px;
  496. font-family: PingFangSC, PingFang SC;
  497. font-weight: 500;
  498. font-size: 12px;
  499. color: #bbbbbb;
  500. line-height: 16px;
  501. text-align: center;
  502. font-style: normal;
  503. span {
  504. color: #3a86fe;
  505. }
  506. }
  507. }
  508. }
  509. .payment-tips {
  510. font-size: 18px;
  511. font-weight: bold;
  512. text-align: center;
  513. padding-top: 10px;
  514. &:last-of-type {
  515. padding-bottom: 10px;
  516. }
  517. }
  518. .disabled {
  519. opacity: 0.3;
  520. }
  521. @keyframes purchase {
  522. 0% {
  523. opacity: 0;
  524. }
  525. 100% {
  526. opacity: 1;
  527. }
  528. }
  529. </style>