|
-
- <template>
- <div class="package-list-container">
- <van-nav-bar :left-arrow="false" :border="true">
- <template #title>
- <h5 style="font-size: 16px">{{topupTitle}}</h5>
- </template>
- </van-nav-bar>
-
- <div class="gray-line"></div>
-
- <div class="order-description" v-show="packageOrderList.length">
- <h5>套餐说明:</h5>
- <h5>每月200分钟通话时长,1G流量。</h5>
- </div>
-
- <div class="topup-container">
- <div class="main">
-
-
-
- <div class="noData_container" v-show="packageOrderList.length === 0 && isShowNoData">
- <p>暂无相关套餐数据,请您联系管理员~</p>
- </div>
-
- <div
- class="package-order-container"
-
- v-for="(item, index) in packageOrderList"
- :key="index"
- >
-
- <div class="recom" v-show="index === 0">
- <div class="shape"></div>
- <div class="square">
- <p>推荐</p>
- </div>
- </div>
-
- <div class="order-content">
- <div class="title">
- <p>{{item.packageName}}{{(item.packagePrice/item.packageIssue).toFixed(0)}}</p>
- </div>
- <div class="details">
- <p>
- 低至
- <span
- class="orange"
- >{{(item.packagePrice/(item.packageIssue === 0 ? 1: item.packageIssue)).toFixed(0)}}</span>元/月
- </p>
- <p class="orange">
- <span class="orange price">{{item.packagePrice}}元</span>
- </p>
- <div class="buy-btn" @click="onBuy(item)">
- <p>话费充值</p>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </template>
-
- <script>
- import APIWx from "@/api/wx";
- import { APIPay } from "@/api/pay";
- let wx = require("weixin-js-sdk");
- import APICore from "@/api/core";
- import axios from "axios";
- import { isNotNull } from "@/utils/index";
- export default {
- name: "packageList",
- data() {
- return {
- topupTitle: "请选择套餐充值激活电话卡",
- wxItem: "",
- packageOrderList: [],
- outTradeNo: "",
- price: "",
- isShowNoData: false,
- params: {
- imei: '',
- iccid: '',
- manufactorId: '',
- appId: '',
-
- },
- };
- },
- computed: {
- isCanTopup() {
- return this.$route.query.isCanTopup;
- },
- serialNo() {
- return this.$route.query.serialNo;
- }
- },
- created() {
- this.getParams();
- this.getWxAutograph();
- this.getLiveBasePackage();
- },
-
-
- methods: {
-
- getOpenId() {
- let code = this.$store.getters.wxAuthCode;
- let openId = this.$store.getters.openId;
- if(isNotNull(openId)) {
- console.log("已经存在openId");
- } else {
- APIPay.getOpenId(code).then(res => {
- let data= res.data;
- if(data.code === 20000) {
- this.$store.commit("openId", data.data.openId);
- }
- })
- }
- },
-
- getAuth() {
- let manufactorId = "5bf13062-a41e-4d00-ba14-1101aad12650";
- APICore.getAuth({ manufactorId: manufactorId }).then(res => {
- this.$store.commit("gatewayToken", res.data.data);
- });
- },
-
- getParams() {
- let params = this.$route.query;
- if (params) {
- let url = window.location.href.split("?code=")[1];
- if ( isNotNull(url) || window.location.href.indexOf("code") > -1) {
- let timeStamp = new Date().getTime();
- let code = url.split("&")[0];
- if (isNotNull(code)) {
- this.$store.commit("wxAuthCode", `${code}`);
- this.getOpenId();
- }
- }
- this.params = {...params};
- }
- },
-
- getLiveBasePackage() {
- this.$toast.loading({
- message: "获取套餐中",
- duration: 1500
- });
- let reqBody = {
- manufactorId:"",
- productModelId:0,
- iccid:"",
- pageNumber:1,
- begNumber:20
- }
- APICore.cardPackageList(reqBody)
- .then(res => {
- console.log("data", res.data);
- if (res.data.code === 106 || res.data.code === 104) {
-
- this.getAuth();
- setTimeout(() => {
- this.getLiveBasePackage();
- }, 1500);
- } else if (res.data.code === 0 && res.data.data === null) {
- this.isShowNoData = true;
- }else {
- let data = res.data.data.list;
- if(data === null) {
- this.isShowNoData = true;
- } else {
- this.packageOrderList = data.filter(item => {
- return item.pechargeUrl === '1629405716684029952' || item.pechargeUrl === '1629405558344859648';
- });
- console.log("套餐数据::", data);
- }
- }
- this.$toast.success({
- message: "成功获取套餐",
- duration: 1500
- });
- })
- .catch(error => {
- this.$dialog.confirm({
- title: "获取套餐数据失败",
- message: error
- });
- })
- .finally(() => {
- setTimeout(() => {
- this.$toast.clear();
- }, 1500);
- });
- },
-
- onNavBack() {
- },
-
- getWxAutograph() {
- let that = this;
- return new Promise((resolve, reject) => {
- APIWx.createJSSDK({
- sUrl: window.location.href.split("#")[0],
- userId: '',
- appId: this.params.appId
- })
- .then(res => {
- let item = res.data.data;
- this.wxItem = res.data.data;
- wx.config({
- debug: false,
- appId: item.appId,
- timestamp: item.timeStamp,
- nonceStr: item.nonceStr,
- signature: item.signature,
- jsApiList: ["chooseWXPay"]
- });
-
- wx.ready(() => {
- resolve(true);
-
- });
- })
- .catch(err => {
- reject(false);
- console.log(err);
- });
- });
- },
-
- onBuy(data) {
- let payType = data.packagePayType;
- this.price = data.packagePrice;
-
- if (payType === 2) {
- this.aliPay(data);
- } else {
- let openId = this.$store.getters.openId;
- if(openId === null || openId === 'null') {
- this.$dialog.confirm({
- message: '微信支付在调整中,请选择其它支付方式'
- })
- } else {
- this.wxPay(data);
- console.log("openid为空");
- }
- }
- },
-
- wxPay(data) {
- this.$toast.loading({
- message: "加载中"
- });
- console.log("微信支付", data);
- let orderData = data;
- let reqBody = {
- openId: this.$store.getters.openId,
- imei: this.params.imei,
- productId: data.pechargeUrl,
- packageName: data.productModel + ',' + data.packageName,
- packagePayType: data.packagePayType,
- packageIssue: data.packageIssue,
- packagePrice: process.env.NODE_ENV === "production" ? data.packagePrice * 100 : 1
- };
- APICore.payLiveBaseDevice(reqBody)
- .then(res => {
- this.$toast.clear();
- if (res.data.code === 104 || res.data.code === 106) {
- this.getAuth();
- setTimeout(() => {
- this.wxPay(orderData);
- }, 1000);
- }
- let that = this;
- let wxData = res.data.data;
- that.outTradeNo = wxData.out_trade_no;
- console.log("wxData", wxData);
-
-
-
- wx.chooseWXPay({
- timestamp: wxData.timeStamp,
- nonceStr: wxData.nonceStr,
- package: wxData.package,
- signType: wxData.signType,
- paySign: wxData.paySign,
- success: function(res) {
-
- that.$router.push({
- name: "payResult",
- query: {
- outTradeNo: that.outTradeNo,
- price: that.price,
- rechargeUrl: data.rechargeUrl,
- iccid: that.params.iccid,
- isAdmin: that.$route.query.isAdmin || false,
- serialNo: that.params.imei,
- issue: data.packageIssue
- }
- });
- console.log("微信支付成功::", res);
- },
- fail: err => {
- console.log("支付出错了::", err);
- that.$dialog.confirm({
- title: "支付失败",
- message: "出错了,请您重新进入"
- });
- },
- cancel: function(err) {
-
- that.$dialog.confirm({
- message: "您取消了支付"
- });
- console.log("用户取消了支付::", err);
- }
- });
- })
- .catch(error => {
- console.log("error", error);
- })
- .finally(() => {
- this.$toast.clear();
- });
- },
-
- aliPay(data) {
- console.log("选择了支付宝::", data);
- this.$toast.loading({
- message: "加载中"
- });
- let orderData = data;
- let reqBody = {
- openId: this.$store.getters.openId,
- imei: this.params.imei,
- productId: data.pechargeUrl,
- packageName: data.productModel + ',' + data.packageName,
- packagePayType: data.packagePayType,
- packageIssue: data.packageIssue,
- packagePrice: process.env.NODE_ENV === "production" ? data.packagePrice * 100 : 1
- };
- this.$toast.clear();
- APICore.payLiveBaseDevice(reqBody)
- .then(res => {
- if (res.data.code === 104 || res.data.code === 106) {
- this.getAuth();
- setTimeout(() => {
- this.aliPay(orderData);
- }, 1000);
- }
- let that = this;
- let alipayData = res.data.data.xmlStrMap;
- that.outTradeNo = alipayData.outTradeNo;
- let alipayForm = decodeURI(alipayData.payXmlStr);
- that.$store.commit("isFromWx", true);
- let alipayUserId = process.env.NODE_ENV === "production" ? 42 : 18
- this.$router.push({
- name: "payResult",
- query: {
- rechargeUrl:
- data.rechargeUrl ||
- `https://id.ssjlai.com/frontend/#/alipay`,
- outTradeNo: that.outTradeNo,
- price: that.price,
- alipayForm: alipayForm,
- iccid: that.params.iccid,
- isAdmin: that.$route.query.isAdmin || false,
- serialNo: that.params.imei,
- alipayUserId: alipayUserId,
- productId: data.pechargeUrl
- }
- });
- })
- .catch(error => {
- console.log("error", error);
- })
- .finally(() => {
- this.$toast.clear();
- });
- },
-
- shiftType(type) {
- switch (type) {
- case "微信":
- return "1"
-
- case "支付宝花呗":
- return "2"
-
- }
- }
- }
- };
- </script>
- <style lang="scss">
- .van-nav-bar__title {
- max-width: 80% !important;
- font-size: 16px;
- }
- </style>
- <style lang="scss" scoped>
- .package-list-container {
- background-color: white;
- height: 100vh;
- .topup-container {
- display: flex;
- justify-content: space-between;
- align-items: center;
- flex-direction: column;
- background-color: white;
- overflow: scroll;
- height: calc(100vh - 4rem);
- .main {
- padding: 0 10px;
- display: flex;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- .tips {
- padding: 10px;
- }
- .noData_container {
- margin: 100px auto 0;
- height: 120px;
- /* background: url(../../../assets/img/news-noData.png) center no-repeat; */
- background-size: 165px 120px;
- display: flex;
- justify-content: center;
- align-items: flex-end;
- font-size: 16px;
- color: #999;
- p {
- font-size: 16px;
- }
- /* @include colorAndFont(#999, 28); */
- }
- p {
- padding: 10px;
- font-size: 16px;
- }
- .cancel-button {
- width: 30vw;
- border-radius: 5px;
- background-color: #2599ff;
- color: #fff;
- min-height: 40px;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 16px;
- }
- .package-order-container {
- position: relative;
- height: 120px;
- width: 300px;
- padding: 5px 20px;
- margin: 10px 0;
- z-index: 999;
- box-shadow: rgba(14, 30, 37, 0.12) 0 3px 5px 0,
- rgba(14, 30, 37, 0.32) 0 2px 16px 0;
- .recom {
- position: absolute;
- top: -7px;
- left: -26px;
- border-style: solid;
- border-width: 0 40px 40px;
- border-color: transparent transparent red;
- transform: rotate(-45deg);
- text-align: center;
- z-index: 9999;
- p {
- padding: 0;
- color: white;
- font-size: 14px;
- }
- .shape {
- position: absolute;
- top: -1px;
- left: -21px;
- border-style: solid;
- border-width: 0 21px 21px;
- border-color: transparent transparent white;
- }
- .square {
- height: 15px;
- width: 35px;
- position: absolute;
- top: 21px;
- left: -20px;
- background: red;
- font-size: 14px;
- }
- }
- .order-content {
- padding-top: 25px;
- .title {
- display: flex;
- justify-content: flex-start;
- p {
- font-size: 14px;
- font-weight: bold;
- }
- }
- .details {
- display: flex;
- justify-content: space-between;
- align-items: center;
- p {
- font-size: 14px;
- }
- .orange {
- color: orange;
- }
- .price {
- font-size: 14px;
- font-weight: bold;
- padding-right: 5px;
- }
- .buy-btn {
- height: 30px;
- width: 90px;
- display: flex;
- justify-content: center;
- align-items: center;
- background: orange;
- border-radius: 20px;
- p {
- padding: 0;
- color: white;
- }
- }
- }
- }
- .content {
- font-size: 14px;
- }
- }
- }
- }
- .gray-line {
- height: 10px;
- width: 100%;
- background: #f2f4f5;
-
- }
- .order-description {
- height: 60px;
- display: flex;
- justify-content: flex-start;
- align-items: flex-start;
- flex-direction: column;
- padding: 5px 0 10px 25px;
- h5 {
- font-size: 14px;
- padding: 10px 0 0 0;
- }
- }
- }
- </style>
|