123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- <template>
- <view class="pagecon">
- <view class="conwarp">
- <view class="gdHead"><view class="head textgrey">选择文档</view></view>
- <view class="cl-one"><video-list :selType="pay_type" @getItem="getItem" :flag="3" :list="goodInfo.files"></video-list></view>
- </view>
- <view v-if="!hidePay" class="conwarp">
- <view class="gdHead"><view class="head textgrey">选择支付方式</view></view>
- <view class="monBox">
- <view @click="selHandle(1)" class="payInfo bb dfsb">
- <image class="payicon" src="/static/img/pro/paywx.png" mode=""></image>
- <view class="flex1"><text class="blank fontmid">微信支付</text></view>
- <image class="payselicon" :src="pay_type == 1 ? '/static/img/pro/chenggong.png' : '/static/img/pro/wxz.png'" mode=""></image>
- </view>
- <view @click="selHandle(2)" class="payInfo bb dfsb">
- <image class="payicon" src="/static/img/pro/payxd.png" mode=""></image>
- <view class="dffd flex1">
- <text class="blank fontmid">学豆支付</text>
- <view class="textgrey fontssm">
- 剩余学豆:
- <text class="prosecond fontssm">{{ userInfo.userInfo.bean || 0 }}</text>
- </view>
- </view>
- <image class="payselicon" :src="pay_type == 2 ? '/static/img/pro/chenggong.png' : '/static/img/pro/wxz.png'" mode=""></image>
- </view>
- <view class="payInfo bb dfsb">
- <image class="payicon" src="/static/img/pro/payyh.png" mode=""></image>
- <view class="dffd flex1">
- <text class="blank fontmid">使用优惠券 -{{ coupon.reduce || 0 }}</text>
- <view @click.stop="nextTo" class="textgrey fontssm dffs">
- 查看当前可使用的优惠券
- <u-icon name="arrow-down" color="#999" size="14"></u-icon>
- </view>
- </view>
- <!-- <image class="payselicon" :src="pay_type == 3 ? '/static/img/pro/chenggong.png' : '/static/img/pro/wxz.png'" mode=""></image> -->
- </view>
- </view>
- </view>
- <view class="fixBox dffs">
- <view class="fontbase">应付:</view>
- <text class=" prosecond">{{ pay_type == 1 ? money : bean }}</text>
- <text class="fontsm flex1">会员折扣{{ userInfo.userInfo.jing_discount || 0 }}折</text>
- <view @click="creatOrd()" class="clickbtn fontmid">{{ hidePay ? '免费下载': '确定下载' }}</view>
- </view>
- <pay-password-keyboard :showPass="payShow" @close="payShow = false" @getPass="balancePay"></pay-password-keyboard>
- </view>
- </template>
- <script>
- import videoList from '@/pages/index/components/wordlist.vue';
- import payPasswordKeyboard from '@/components/pay-password-keyboard/pay-password-keyboard.vue';
- import { mapState } from 'vuex';
- export default {
- components: {
- videoList,
- payPasswordKeyboard
- },
- data() {
- return {
- hidePay: false, //如果选择下载并且 价格为0 隐藏支付方式
- id: '',
- goodInfo: { tags: '' },
- // pay_type: 1, //2微信 1 学豆
- pay_type: 1, //1=微信 2=学豆
- money: 0, //应付
- bean: 0, //应付
- payShow: false, //支付密码
- coupon: { reduce: 0 },
- ids: '',
- ordId: ''
- };
- },
- computed: {
- ...mapState({ userInfo: state => state.userInfo })
- },
- async onLoad(opt) {
- this.id = opt.id;
- await this.$store.dispatch('getUserInfo');
- await this.loadData();
- },
- methods: {
- selHandle(val) {
- console.log(val);
- if (val == 2 && this.userInfo.userInfo.level_time == 0) {
- this.$api.toast('请先开通会员');
- setTimeout(res => {
- uni.navigateTo({
- url: '/pages/user/mine/member'
- });
- }, 600);
- } else {
- this.pay_type = val;
- }
- },
- /**
- * 请求数据只是为了代码不那么乱
- * 分次请求未作整合
- */
- async loadData() {
- let url = 'index/getClassInfo';
- this.$api
- .request(url, {
- id: this.id
- })
- .then(res => {
- if (res.code == '200') {
- let data = res.data;
- data.files.forEach(item => {
- item.sel = false;
- });
- this.goodInfo = data;
- }
- });
- },
- // 选择优惠券
- nextTo() {
- if (this.pay_type == 1) return this.$api.toast('余额支付不能使用优惠券');
- uni.navigateTo({
- url: '/pages/user/coupon/myCoup?money=' + this.money
- });
- },
- // 点击
- getItem(sel, index) {
- this.goodInfo.files[index].sel = sel;
- let arr = this.goodInfo.files;
- let mon = 0;
- let beans = 0;
- let id = [];
- arr.forEach(res => {
- if (res.sel) {
- mon = parseFloat(mon) + parseFloat(res.price);
- beans = parseFloat(beans) + parseFloat(res.bean);
- id.push(res.id);
- }
- });
- let total =
- this.userInfo.userInfo.jing_discount == 0
- ? parseFloat(mon - this.coupon.reduce).toFixed(2)
- : parseFloat((mon * this.userInfo.userInfo.jing_discount) / 10 - this.coupon.reduce).toFixed(2);
- this.money = total;
- this.bean = parseFloat(beans).toFixed(2) || '';
- this.ids = id.toString();
- // console.log('bean: ',this.bean);
- if ((this.money == 0 && this.ids) || (this.bean == 0 && this.ids)) {
- this.hidePay = true;
- } else {
- this.hidePay = false;
- }
- },
- // 学豆支付
- balancePay(val) {
- this.payShow = false;
- console.log(val);
- this.$api
- .request('user/checkMd', {
- pay_pass: val
- })
- .then(data => {
- if (data.code == 200) {
- this.emitHandle();
- } else {
- this.$api.toast(data.msg);
- }
- });
- },
- // 点击支付
- creatOrd() {
- // return;
- let url = 'files_order/create';
- let money = parseFloat(this.money) * parseFloat(this.userInfo.userInfo.jing_discount / 10) - parseFloat(this.coupon.reduce);
- if ((this.hidePay && this.pay_type == 2) || money <= 0) {
- this.pay_type = 3;
- }
- this.$api
- .request(url, {
- ids: this.ids,
- coupon_id: this.coupon.id || '',
- pay_type: this.pay_type
- })
- .then(data => {
- if (data.code == 200) {
- this.ordId = data.data;
- if (this.pay_type == 1) {
- this.emitHandle();
- } else if (this.pay_type == 2) {
- this.payShow = true;
- } else {
- this.emitHandle();
- }
- } else {
- this.$api.toast(data.msg);
- }
- });
- },
- // 点击支付
- emitHandle() {
- // return;
- let url = 'payment/filePay';
- this.$api
- .request(url, {
- order_id: this.ordId || '',
- pay_type: this.pay_type
- })
- .then(data => {
- if (this.pay_type != 1) {
- this.$api.toast(data.msg);
- if (data.code == 200) {
- setTimeout(res => {
- uni.navigateTo({
- url: '/pages/user/mine/down'
- });
- }, 600);
- }
- } else {
- if (data.code && data.code != 200) {
- this.$api.toast(data.msg || '获取支付信息失败');
- return;
- }
- console.log(data);
- const orderInfo = data;
- const { timeStamp, nonceStr, paySign } = orderInfo;
- const payParams = {
- provider: 'wxpay',
- orderInfo: data,
- timeStamp,
- nonceStr,
- package: orderInfo.package,
- signType: 'MD5',
- paySign,
- success: e => {
- this.$api.toast('支付成功');
- setTimeout(res => {
- uni.navigateTo({
- url: '/pages/user/mine/down'
- });
- }, 600);
- },
- fail: err => {
- if (err.errMsg.indexOf('取消') > -1 || err.errMsg.indexOf('cancel') > 1 || err.errMsg.indexOf('-2') > -1) {
- this.$api.toast('取消支付');
- } else {
- this.$api.toast('支付遇到错误,请稍候重试');
- console.log(err);
- }
- }
- };
- uni.requestPayment(payParams);
- }
- });
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .pagecon {
- padding-bottom: 100rpx;
- .conwarp {
- background-color: #fff;
- padding: 26rpx 30rpx 39rpx;
- border-radius: 16rpx;
- margin-bottom: 20rpx;
- .gdHead {
- line-height: 58rpx;
- margin-bottom: 16rpx;
- .head {
- font-size: 34rpx;
- font-family: PingFangSC-Medium, PingFang SC;
- font-weight: 600;
- line-height: 48rpx;
- }
- }
- }
- .monBox {
- margin-top: 20rpx;
- background-color: #fff;
- .payInfo {
- padding: 35rpx 0;
- .payicon {
- width: 68rpx;
- height: 68rpx;
- }
- .flex1 {
- margin: 0 15rpx;
- }
- .fontmid {
- flex: 1;
- }
- .payselicon {
- width: 32rpx;
- height: 32rpx;
- }
- }
- }
- .fixBox {
- justify-content: flex-end;
- font-size: 32rpx;
- padding: 0 30rpx;
- .prosecond {
- // text-align: right;
- // flex: 1;
- text {
- font-size: 28rpx;
- color: $prosecond;
- }
- font-size: 42rpx;
- font-family: DIN-Regular, DIN;
- font-weight: 400;
- }
- .clickbtn {
- margin: 0 0 0 20rpx;
- width: 214rpx;
- height: 80rpx;
- line-height: 80rpx;
- background: #ed742f;
- border-radius: 40rpx;
- }
- }
- }
- </style>
|