|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798 |
-
- <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="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="false">
- <div class="shape"></div>
- <div class="square">
- <p>推荐</p>
- </div>
- </div>
-
- <div class="order-content">
- <div class="title">
- <p>{{item.packageName}}{{(item.packagesPrice/item.packageIssue).toFixed(0)}}</p>
- </div>
- <div class="remark">
- <p>每月200分钟通话时长,1G流量</p>
- </div>
- <div class="details">
- <p>
-
- <span class="orange large">¥{{(item.packagesPrice/(item.packageIssue === 0 ? 1: item.packageIssue)).toFixed(0)}}</span>元/月,
- </p>
- <p class="total">
- <span>合计</span><span class="orange price">{{item.packagesPrice}}元</span>
- </p>
- </div>
-
-
- <div class="radios-con">
- <div class="pay-type">
- <p>支付方式:</p>
- </div>
- <van-radio-group v-model="radio" direction="horizontal" @change="onRaidoChange">
- <van-radio name="1">
- <template #default>
- <div class="radio-con">
- <span>微信</span>
- <img src="../../assets/wx-pay.png"/>
- </div>
- </template>
- </van-radio>
- <van-radio name="2">
- <template #default>
- <div class="radio-con">
- <span>支付宝</span>
- <img src="../../assets/alipay.png"/>
- </div>
- </template>
- </van-radio>
- <van-radio name="3">
- <template #default>
- <div class="radio-con">
- <span>12期花呗</span>
- <img src="../../assets/antpay.png"/>
- </div>
- </template>
- </van-radio>
- </van-radio-group>
- </div>
- <div class="package-buy">
- <div class="buy-btn" @click="onBuy(item)">
- <p>第一步:充值话费</p>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </template>
-
- <script>
- import APIWx from "@/api/wx";
- import AppId from "@/config/appId";
- import { APIPay } from "@/api/pay";
- import APICore from "@/api/core";
- let wx = require("weixin-js-sdk");
- import { isNotNull } from "@/utils/index";
- export default {
- name: "packageList",
- data() {
- return {
- topupTitle: "请选择套餐充值电话卡",
-
- packageOrderList: [
-
-
- ],
- outTradeNo: "",
- price: "",
- isShowNoData: false,
-
- params: {
- imei: '',
- iccid: '',
- manufactorId: '',
- appId: '',
-
- },
- radio: '1',
- payProductId: null,
- packageIssue: null,
- payType: '1',
- };
- },
- created() {
- this.getAuth();
- this.getParams();
-
-
- this.getDevicePayPackage();
- },
- 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};
- }
- },
-
- getDevicePayPackage() {
- this.$toast.loading({
- message: "加载中",
- duration: 1500
- });
- APICore.devicePayPackage(this.params.imei)
- .then(res => {
- console.log("data", res.data);
- if (res.data.code === 106 || res.data.code === 104) {
-
- this.getAuth();
- setTimeout(() => {
- this.getDevicePayPackage();
- }, 1500);
- } else if (res.data.code === 0 && res.data.data === null) {
- this.isShowNoData = true;
- } else {
- if(res.data.data === null) {
- this.isShowNoData = false;
- } else {
- let data = res.data.data.packagesList;
-
-
- let packageList = data.filter(item => {
- return item.producModelId === 1
- });
- this.packageOrderList = packageList;
- console.log("套餐数据::", packageList);
- }
- this.$toast.success({
- message: "加载完成",
- duration: 1500
- });
- }
- })
- .catch(error => {
- this.$dialog.confirm({
- title: "获取套餐数据失败",
- message: error.message,
- showCancelButton: false,
- });
- })
- .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 || AppId
- })
- .then(res => {
- let item = 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) {
- this.price = data.packagesPrice;
-
- let payTypeToPackAgeId = data.payTypeList;
- console.log("购买的套餐数据data", payTypeToPackAgeId);
-
- if (this.payType === '2') {
-
- this.payProductId = payTypeToPackAgeId.filter(item => {
- return item.payType === '2' || item.payType === 2
- })[0].productId;
- this.packageIssue = 0;
- console.log("this.payProductId", this.payProductId);
- this.aliPay(data);
- } else if (this.payType === '3') {
-
- this.payProductId = payTypeToPackAgeId.filter(item => {
- return item.payType === '3' || item.payType === 3
- })[0].productId;
- this.packageIssue = 12;
- this.payType = '2';
- console.log("this.payProductId2", this.payProductId);
- this.aliPay(data);
- } else {
-
- let openId = this.$store.getters.openId;
- this.payProductId = payTypeToPackAgeId.filter(item => {
- return item.payType === '1' || item.payType === 1
- })[0].productId;
- this.packageIssue = 0;
- console.log("this.payProductId3", this.payProductId);
- if(openId === null || openId === 'null') {
- this.$dialog.confirm({
- message: '获取OpenId失败,请您重新进入',
- showCancelButton: false,
- })
- } else {
- this.wxPay(data);
- }
- }
- },
-
- wxPay(data) {
- this.$toast.loading({
- message: "加载中"
- });
- console.log("微信支付", data);
- let orderData = data;
- let reqBody = {
- openId: this.$store.getters.openId,
- imei: this.params.imei,
- iccid: this.params.iccid,
- productId: this.payProductId,
- packageName: data.packagesName,
- packagePayType: Number(this.payType),
- packageIssue: 0,
- packagePrice: process.env.NODE_ENV === "production" ? data.packagesPrice * 100 : 1
- };
- this.$toast.clear();
- APICore.payLiveBaseDevice(reqBody)
- .then(res => {
- if (res.data.code === 104 || res.data.code === 106) {
- this.getAuth();
- setTimeout(() => {
- this.wxPay(orderData);
- }, 1000);
- } else if (res.data.code === 104) {
- this.$dialog.confirm({
- message: `${res.data.message}`
- })
- }
- let that = this;
- let wxData = res.data.data;
- that.outTradeNo = wxData.out_trade_no;
- console.log("wxData", wxData);
-
-
-
-
-
- this.onWxPay(wxData);
- })
- .catch(error => {
- console.log("error", error);
- })
- .finally(() => {
- this.$toast.clear();
- });
- },
- onWxPay(data) {
- let that = this;
- function onBridgeReady() {
- WeixinJSBridge.invoke(
- "getBrandWCPayRequest",
- {
- appId: AppId,
- timeStamp: data.timeStamp,
- nonceStr: data.nonceStr,
- package: data.package,
- signType: data.signType,
- paySign: data.paySign
- },
- function(res) {
- if (res.err_msg == "get_brand_wcpay_request:ok") {
-
-
- that.$router.replace({
- 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: that.packageIssue
- }
- });
- } else {
- that.$dialog.confirm({
- message: "您取消了支付",
- showCancelButton: false
- });
- }
- }
- );
- }
- if (typeof WeixinJSBridge == "undefined") {
- if (document.addEventListener) {
- document.addEventListener(
- "WeixinJSBridgeReady",
- onBridgeReady,
- false
- );
- } else if (document.attachEvent) {
- document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
- document.attachEvent(
- "onWeixinJSBridgeReady",
- onBridgeReady
- );
- }
- } else {
- onBridgeReady();
- }
- },
-
- aliPay(data) {
- console.log("选择了支付宝::", data);
- this.$toast.loading({
- message: "加载中"
- });
- let orderData = data;
- let reqBody = {
- openId: this.$store.getters.openId,
- imei: this.params.imei,
- iccid: this.params.iccid,
- productId: this.payProductId,
- packageName: data.packagesName,
- packagePayType: Number(this.payType),
- packageIssue: this.packageIssue,
- packagePrice: process.env.NODE_ENV === "production" ? data.packagesPrice * 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" ? 69 : 18;
- this.$router.replace({
- 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: this.payProductId
- }
- });
- })
- .catch(error => {
- console.log("error", error);
- this.$dialog.confirm({
- message: `${error.message}`,
- showCancelButton: false
- })
- })
- .finally(() => {
- this.$toast.clear();
- });
- },
-
- onRaidoChange(value) {
- console.log("选择的支付类型是", value);
- this.payType = value;
- }
- }
- };
- </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 {
- position: relative;
- /* margin: 20px; */
- display: flex;
- justify-content: space-between;
- align-items: center;
- flex-direction: column;
- background-color: white;
- overflow: scroll;
- height: calc(100vh - 88px);
- .main {
- 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;
- margin: 10px 0;
- /* padding: 0 20px; */
- 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: 15px 10px;
- .title {
- display: flex;
- justify-content: flex-start;
- p {
- font-size: 16px;
- font-weight: bold;
- }
- }
- .details {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- p {
- height: 40px;
- @include center();
- font-size: 14px;
- padding: 5px 0 5px 10px;
- }
- .total {
- font-size: 16px;
- padding: 0;
- }
- .orange {
- color: orange;
- }
- .large {
- font-size: 26px;
- margin: 0 2px;
- }
- .price {
- font-size: 16px;
- }
- /* .buy-btn {
- height: 30px;
- width: 100px;
- display: flex;
- justify-content: center;
- align-items: center;
- background: orange;
- border-radius: 45px;
- p {
- font-size: 16px;
- padding: 0;
- color: red;
- }
- } */
- }
- .remark {
- display: flex;
- justify-content: flex-start;
- p {
- font-size: 14px;
- padding: 5px 10px;
- /* font-weight: bold; */
- }
- }
- .package-buy {
- @include center();
- padding: 5px 8px;
- @include center();
- .buy-btn {
- height: 40px;
- width: 200px;
- padding: 0 5px;
- display: flex;
- justify-content: center;
- align-items: center;
- background: orange;
- border-radius: 20px;
- p {
- font-size: 16px;
- padding: 0;
- color: white;
- }
- }
- }
- .radios-con {
- /* padding: 20px 10px; */
- /* @include center(); */
- /* align-items: center; */
- padding: 10px 0 10px 10px;
- font-size: 14px;
- /* box-shadow: rgba(14, 30, 37, 0.12) 0 3px 5px 0,
- rgba(14, 30, 37, 0.32) 0 2px 16px 0; */
- img {
- height: 20px;
- width: 20px;
- margin: 2px;
- }
- .pay-type {
- text-align: left;
- p {
- font-size: 14px;
- padding: 0 0 10px 0;
- }
- }
-
- .radio-con {
- @include center();
- }
- .van-cell-text {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- span {
- font-size: 14px;
- padding: 0 5px;
- }
- }
- }
- }
- .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 10px;
- h5 {
- font-size: 14px;
- padding: 10px 0 0 0;
- }
- }
- .pay-radios {
- position: relative;
- top: 0;
- width: 100%;
- /* background-color: red; */
- /* padding: 0 15px; */
- .radios-con {
- padding: 20px 10px;
- /* @include center(); */
- align-items: center;
- font-size: 18px;
- box-shadow: rgba(14, 30, 37, 0.12) 0 3px 5px 0,
- rgba(14, 30, 37, 0.32) 0 2px 16px 0;
- img {
- height: 35px;
- width: auto;
- }
- .van-cell-text {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- span {
- padding: 0 5px;
- }
- }
- }
- }
- }
- </style>
|