123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477 |
- <template>
- <view class="pay">
- <!-- <view class="shop-info" v-if="!isVisual">
- <view class="shop-name">
- {{info.shopName}}
- </view>
- <view class="address">
- {{info.address}}
- </view>
- </view> -->
- <view class="pay-info">
- <view class="goods-info">
- <image class="goods-img" :src="info.goodsImg" mode=""></image>
- <view class="info">
- <view class="goods-name">
- {{info.goodsName}}
- </view>
- <view class="num">
- {{info.goodsDescribe}}
- </view>
- <view class="price">
- ¥{{info.realPrice}}
- </view>
- </view>
- </view>
-
- <view class="coupon">
- <view class="label">
- 优惠券
- </view>
- <view class="choose-coupon none" @click="choose">
- 暂无可用
- <image class="icon" src="@/static/jiantou-icon.png" mode=""></image>
- </view>
- </view>
- </view>
-
- <view class="input-box" v-if="isVisual">
-
- <view class="label">
- 充值账号
- </view>
- <view class="value">
- {{form.account}}
- </view>
- </view>
- <view class="btn-box">
- <view class="total-price">
- <view class="label">
- 合计:
- </view>
- <view class="price">
- ¥ {{info.realPrice}}
- </view>
- </view>
- <button class="btn" type="default" :loading="loading" @click="creat">提交订单</button>
- </view>
- </view>
- </template>
- <script>
- import {
- calculate
- } from '@/api/order.js';
- import {
- creat
- } from '@/api/goods.js'
- import {
- creatPayOrder,
- queryPayOrder,
- payDetails
- } from '@/api/payment.js'
- import guid from '@/utils/guid.js'
- export default {
- data() {
- return {
- isVisual:false,//是否是虚拟商品
- loading: false,
- info: {},
- form:{
- account:''
- },
- query: {
- "msgType": "wx.unifiedOrder",
- "orderDesc": "测试",
- "orderNo": "",
- "subOpenId": "",
- "userId": ""
- },
- // 支付信息
- payData: {
- }
- }
- },
- computed: {
-
- },
- methods: {
- choose() {
- let that = this
- uni.navigateTo({
- url: '/pay/coupon?couponId=' + this.info.couponId,
- success: function(res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('pay', that.info)
- }
- })
- },
- //创建订单
- creat() {
- if (this.loading) return
-
- this.loading = true
- uni.showLoading({
- title: '支付中'
- })
- let that = this
- if (!this.payData.timeStamp) {
- // 处理扩展字段 暂时只有研学商品和视频会员 视频会员是字符串的JSON 研学是字符串
- let extend
- try{
- if(JSON.parse(this.info.extend)){
- extend = this.info.extend
- }
- }catch(e){
- extend = this.info.reservationTime || ''
- }
-
- creat({
- discountId: (this.info.couponId || this.info.couponId == -1) ? [this.info.couponId
- ] : [],
- extend,
- channel:'ZhongShu',
- goodsList: this.info.goodsId ? [this.info.goodsId] : [],
- idempotent: guid(),
- shopId: this.info.shopId
- }).then(res => {
- this.loading = false
- if (res.state == 'Success') {
- if (!this.info.realPrice) { //价格为0
- uni.hideLoading()
- uni.reLaunch({
- url: '/my/order/index'
- })
- } else {
- this.query.orderNo = res.content.orderNo
- this.query.subOpenId = JSON.parse(uni.getStorageSync('userInfo')).openId
- this.query.orderDesc = this.info.goodsName
- creatPayOrder(this.query).then(data => {
- that.payData = JSON.parse(data.content.miniPayRequest)
- if (data.content.miniPayRequest == null) return uni.hideLoading()
- uni.requestPayment({
- "provider": "wxpay",
- "orderInfo": that.payData,
- "appid": that.payData
- .appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
- "paySign": that.payData.paySign,
- "nonceStr": that.payData.nonceStr, // 随机字符串
- "package": that.payData.package, // 固定值
- // "prepayid": that.payData.package, // 统一下单订单号
- "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
- "signType": that.payData.signType, //签名算法
- success(msg) {
- console.log('msg', msg, res);
- queryPayOrder(that.query.orderNo).then(res1 => {
- if (res1.state == 'Success') {
- uni.hideLoading()
- uni.reLaunch({
- url: '/my/order/index'
- })
- }
- })
- },
- fail(e) {
- console.log('err', e);
- that.loading = false
- uni.hideLoading()
- uni.showToast({
- title: '取消支付',
- icon: 'fail'
- })
- // 取消支付后
- uni.reLaunch({
- url:'/my/order/detail?id='+that.query.orderNo
- })
- // // 取消支付后,获取支付信息以备再次支付
- // payDetails(that.query.orderNo).then(r => {
- // if (r.state == 'Success') {
- // that.payData = JSON.parse(r.content.miniPayRequest)
- // }
- // })
- }
- })
- })
- }
- }
- })
- } else { // 取消支付后再次支付
- uni.requestPayment({
- "provider": "wxpay",
- "orderInfo": that.payData,
- "appid": that.payData.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
- "paySign": that.payData.paySign,
- "nonceStr": that.payData.nonceStr, // 随机字符串
- "package": that.payData.package, // 固定值
- // "prepayid": that.payData.package, // 统一下单订单号
- "timeStamp": that.payData.timeStamp, // 时间戳(单位:秒)
- "signType": that.payData.signType, //签名算法
- success(msg) {
- console.log('msg', msg);
- queryPayOrder(that.query.orderNo).then(res1 => {
- if (res1.state == 'Success') {
- uni.hideLoading()
- uni.reLaunch({
- url: '/my/order/index'
- })
- }
- })
- },
- fail(e) {
- that.loading = false
- uni.hideLoading()
- uni.showToast({
- title: '取消支付',
- icon: 'fail'
- })
- // 取消支付后,获取支付信息以备再次支付
- payDetails(that.query.orderNo).then(r => {
- if (r.state == 'Success') {
- that.payData = JSON.parse(r.content.miniPayRequest)
- }
- })
- console.log('err', e);
- }
- })
- }
- }
- },
- onReady() {
-
- },
- onLoad() {
- let userInfo = JSON.parse(uni.getStorageSync('userInfo'))
- this.query.userId = userInfo.userId
- let that = this
- const eventChannel = this.getOpenerEventChannel();
- eventChannel.on('pay', function(data) {
- that.info = data
- try{
- let extend = JSON.parse(that.info.extend)
- if(extend.account){
- that.isVisual = true
- that.form.account = extend.account
- }
- }catch(e){
- //TODO handle the exception
- }
- console.log('data', data);
- })
- }
- }
- </script>
- <style lang="scss">
- .pay {
- background: #F9F9F9;
- min-height: 100vh;
- padding-top: 20rpx;
- .shop-info {
- margin: 0 30rpx 20rpx;
- width: 690rpx;
- padding: 24rpx;
- box-sizing: border-box;
- background: #FFFFFF;
- border-radius: 16rpx 16rpx 16rpx 16rpx;
- .shop-name {
- color: #181818;
- font-size: 32rpx;
- }
- .address {
- color: #999999;
- font-size: 24rpx;
- margin-top: 12rpx;
- }
- }
- .pay-info {
- margin: 0 30rpx;
- background: #FFFFFF;
- border-radius: 16rpx 16rpx 16rpx 16rpx;
- padding: 28rpx 24rpx;
- .goods-info {
- display: flex;
- margin-bottom: 30rpx;
- .goods-img {
- width: 164rpx;
- height: 164rpx;
- border-radius: 16rpx;
- }
- .info {
- margin-left: 28rpx;
- flex: 1;
- .goods-name {
- font-weight: bold;
- color: #181818;
- font-size: 32rpx;
- width: 100%;
- word-break: break-all;
- text-overflow: ellipsis;
- overflow: hidden;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- /* 这里是超出几行省略 */
- }
- .num {
- color: #999999;
- font-size: 24rpx;
- margin-top: 16rpx;
- }
- .price {
- font-weight: bold;
- color: #181818;
- font-size: 32rpx;
- margin-top: 26rpx;
- }
- }
- }
-
-
- .coupon {
- display: flex;
- align-items: center;
- justify-content: space-between;
- border-bottom: 2rpx dashed #f3f3f3;
- padding: 28rpx 0;
- .label {
- color: #222222;
- font-size: 28rpx;
- }
-
- .choose-coupon.none{
- color: #AAAAAA;
- }
- .choose-coupon {
- color: #FF4848;
- font-size: 28rpx;
- display: flex;
- align-items: center;
- .icon {
- width: 28rpx;
- height: 28rpx;
- display: block;
- margin-left: 10rpx;
- }
- }
- }
- .explain {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding-top: 28rpx;
- .label {
- color: #AAAAAA;
- font-size: 28rpx;
- }
- .right {
- display: flex;
- align-items: center;
- font-size: 24rpx;
- .red {
- font-weight: 500;
- color: #FF4848;
- margin: 0 10rpx;
- }
- .fs28 {
- font-size: 28rpx !important;
- }
- }
- }
- }
-
- .input-box{
- margin: 20rpx 30rpx;
- padding: 28rpx 24rpx;
- background: #FFFFFF;
- border-radius: 16rpx 16rpx 16rpx 16rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- .label {
- color: #222;
- font-size: 28rpx;
- }
-
- .value {
- font-size: 28rpx;
- color: #AAAAAA;
- }
- }
- .btn-box {
- position: fixed;
- bottom: 0%;
- left: 0%;
- width: 100%;
- height: 98rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- box-sizing: border-box;
- padding: 0 30rpx;
- border-top: 1rpx solid #EEEEEE;
- .total-price {
- display: flex;
- align-items: center;
- .label {
- color: #181818;
- font-size: 28rpx;
- }
- .price {
- font-size: 36rpx;
- font-weight: 800;
- color: #FF4848;
- margin-left: 10rpx;
- }
- }
- .btn {
- width: 280rpx;
- height: 80rpx;
- line-height: 80rpx;
- text-align: center;
- background: $uni-color-primary;
- box-shadow: inset 0rpx 6rpx 12rpx 2rpx rgba(255, 255, 255, 0.16);
- border-radius: 46rpx 46rpx 46rpx 46rpx;
- font-weight: 800;
- color: #FFFFFF;
- font-size: 28rpx;
- margin: 0;
- }
- }
- }
- </style>
|