123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540 |
- <template>
- <view class="">
- <u-navbar
- title="收银台"
- :placeholder="true"
- @leftClick="leftClick"
- :autoBack="false"
- :safeAreaInsetTop="true"
- >
- </u-navbar>
- <view class="page-wrap">
- <view class="pay-way page-wrap">
- <u-radio-group v-model="params.paymentMode" placement="column" @change="groupChange">
- <view class="pay-way-item u-flex u-row-between" @click="selectPayment('wx')">
- <view class="left u-flex">
- <image class="icon" :src="staticUrl+'/img/payway-wx.png'" mode="aspectFill"></image>
- <view class="name">微信支付</view>
- </view>
- <u-radio name="wx" activeColor="#1677FF" size="36rpx"></u-radio>
- </view>
- <view :class="{disabled:balanceInfo.balance<params.payAmount}" @click="selectPayment('yue')" class="pay-way-item u-flex u-row-between">
- <view class="left u-flex">
- <image class="icon" :src="staticUrl+'/img/pyway-yue.png'" mode="aspectFill"></image>
- <view class="name">账户余额</view>
- ¥ {{balanceInfo.balance}}
- </view>
- <u-radio name="yue" :disabled="balanceInfo.balance<params.payAmount" activeColor="#1677FF" size="36rpx"></u-radio>
- </view>
- <view :class="{disabled:balanceInfo.grantSurplus<params.payAmount}" @click="selectPayment('shouxin')" class="pay-way-item u-flex u-row-between">
- <view class="left u-flex">
- <image class="icon" :src="staticUrl+'/img/pyway-shouxin.png'" mode="aspectFill"></image>
- <view class="name">授信余额</view>
- ¥ {{balanceInfo.grantSurplus}}
- </view>
- <u-radio name="shouxin" :disabled="balanceInfo.grantSurplus<params.payAmount" activeColor="#1677FF" size="36rpx"></u-radio>
- </view>
- <view class="repayment-time pay-way-item u-flex u-row-between" @click="showDate = true" v-if="params.paymentMode === 'shouxin'">
- <view class="label">账期</view>
- <view class="value">{{ params.rePaymentTime||'请选择账期' }}</view>
- </view>
- </u-radio-group>
- </view>
- <u-datetime-picker
- :show="showDate"
- :value="params.rePaymentTime"
- mode="date"
- @confirm="confirmDateChange"
- @cancel="showDate = false"
- :minDate="minDate"
- :maxDate="maxDate"
- ></u-datetime-picker>
- <view class="full-btn" v-if="params.paymentMode&&cansubmit" @click="payRoute">去支付<text>¥ {{params.payAmount}}</text></view>
- <view class="full-btn gray" v-else>去支付<text>¥ {{params.payAmount}}</text></view>
- <u-popup :show="checkPassShow" @close="checkPassClose" mode="center">
- <view class="check-pass">
- <view class="title">请输入支付密码</view>
-
- <view class="number">¥{{params.payAmount}}</view>
- <view class="the-way u-flex u-row-between">
- <view class="left">支付方式</view>
- <view class="right u-flex">
- <u--image class="image" :src="staticUrl+'/img/qian.png'" width="32rpx" height="32rpx"></u--image>
- <text style="margin-left: 10px;">余额</text>
- </view>
- </view>
- <u-code-input v-model="paypass"
- :space="0"
- :size="40"
- @finish="checkPayPassword"
- :maxlength="6"
- :adjustPosition="true"
- :dot="true"
- :focus="true"
- :disabled-keyboard="false" >
- </u-code-input>
-
- </view>
- </u-popup>
- </view>
- </view>
- </template>
- <script>
-
- import wxH5 from "weixin-jsapi";
-
- export default {
- data() {
- return {
- staticUrl:this.$commonConfig.staticUrl,
- fromPage:'',
- customBalance:'',
- credit:'',
- params:{
- paymentMode:null,
- orderId:'',
- openid:'',
- payAmount:'',
- payResult:{},
- rePaymentTime: '',
- },
- checkPassShow:false,
- paypass:'',
- noPaypass:true,
- balanceInfo:{
- balance:0,
- grantQuota:0,
- grantUsed:0,
- grantSurplus:0,
- isSetPayPassword:0,
- },
- cansubmit:true,
- needPayQuery:0,
- payerId:'',
- showDate: false,
- minDate: new Date().getTime(),
- maxDate: new Date(new Date().getFullYear() + 1, 11, 31).getTime(),
- }
- },
- onShow(page) {
-
- let allPages = getCurrentPages();
-
- let lastPages = allPages.length - 1;
- console.log(lastPages);
- let option = allPages[lastPages].options;
- console.log(option);
- if(option.needPayQuery){
- this.cansubmit = false;
- this.payQuery();
- }
-
- this.getBalanceInfo();
- },
- onLoad(page) {
- console.log('page',page);
- this.fromPage = page.fromPage;
- this.params.orderId = page.orderId;
- this.params.openid = this.vuex_wechatOpenid;
- this.params.payAmount = page.payAmount;
- this.params.paymentMode = page.paymentMode;
- this.needPayQuery = page.needPayQuery;
- this.payerId = page.payerId;
- if(page.needPayQuery){
- this.cansubmit = false;
- this.payQuery();
- }
- },
- methods: {
- leftClick(){
- uni.showModal({
- title: '提示',
- content: '是否放弃本次付款!',
- success: res => {
- if (res.confirm) {
- uni.navigateBack()
- } else if (res.cancel) {
- console.log('用户点击取消');
- }
- }
- });
- },
- getBalanceInfo(){
- this.$u.api.balanceInfo({id:this.vuex_user_info.userid,payerId:this.payerId}).then(res=>{
- this.balanceInfo= res.data;
- }).catch(err=>{
- console.log('balanceInfo',err.data);
- })
- },
- checkPassClose(){
- this.checkPassShow = false;
- },
- payRoute(){
- if(this.params.paymentMode!='wx'){
- if(this.params.paymentMode=='shouxin'&&!this.params.rePaymentTime){
- uni.showToast({
- title: '请选择账期',
- icon: 'none'
- });
- return;
- }
- this.checkExistPayPassword();
- }else{
- this.gotoPay();
- }
- this.cansubmit = false;
- },
- checkExistPayPassword(){
- if(this.balanceInfo.isSetPayPassword==0){
- this.noPaypass = true;
- uni.showModal({
- title: '还未设置支付密码',
- content: '请先设置支付密码!',
- success: res => {
- if (res.confirm) {
- uni.$u.route('/center/setPaypass', {
- from: 'pay',
- backUrl:'/shopping/order'
- });
- }
- }
- })
- }else{
- this.noPaypass = false;
- this.checkPassShow = true
- }
- },
- checkPayPassword(){
- this.$u.api.checkPayPassword({payPassword:this.paypass}).then(res=>{
-
- if(res.msg=='操作成功'){
- if(this.params.paymentMode=='wx'){
- this.gotoPay();
- }else if(this.params.paymentMode=='yue'){
- this.gotoBalancePay()
- }else if(this.params.paymentMode=='shouxin'){
- this.gotoQuotaPay()
- }
- }else{
- this.paypass = '';
- uni.showToast({
- title:'密码错误',
- icon:'error'
- });
- }
-
- }).catch(err=>{
- this.paypass = '';
- uni.showToast({
- title:'密码错误',
- icon:'error'
- });
- console.log('checkPayPassword',err);
- })
- },
- gotoPay() {
- this.$u.api.gotoPay({...this.params,payerId:this.payerId}).then(res => {
-
-
-
-
- if(!res.data.needPay){
-
- uni.$u.route('/center/orderdetails', {
- type:'redirectTo',
- id: this.params.orderId
- });
- }else {
- window.location.href = res.data.payInfo;
-
- return
-
- this.payResult = res.data.payInfo;
- this.payResult.package = res.data.payInfo.packageValue;
-
-
- this.initConfig(this.payResult)
-
-
- this.wxPay()
-
- }
-
-
-
-
-
-
-
- }).catch(err => {
- this.cansubmit = true;
-
-
- console.log('gotoPay', err);
- })
- },
- gotoBalancePay(){
- let that = this;
- this.$u.api.balancePay({orderId:this.params.orderId,payerId:this.payerId}).then(res=>{
-
- uni.showToast({
- title:res.msg,
- icon:'none'
- })
- setTimeout(()=>{
- uni.reLaunch({
- url: `/center/orderdetails?type=redirectTo&id=${that.params.orderId}`
- });
- },1500)
- }).catch(err=>{
- console.log('balancePay',err.data);
- }).finally(()=>{
- this.cansubmit = true;
- })
- },
- gotoQuotaPay(){
- let that = this;
- this.$u.api.quotaPay({orderId:this.params.orderId,payerId:this.payerId,rePaymentTime:this.params.rePaymentTime}).then(res=>{
-
- uni.showToast({
- title:res.msg,
- icon:'none'
- })
- setTimeout(()=>{
- uni.reLaunch({
- url: `/center/orderdetails?type=redirectTo&id=${that.params.orderId}`
- });
- },1500)
- }).catch(err=>{
- console.log('quotaPay',err.data);
- }).finally(()=>{
- this.cansubmit = true;
- })
- },
- wxPay(){
- uni.requestPayment({
- ... this.payResult,
- "provider": "wxpay",
- "orderInfo": {
-
-
-
-
-
-
-
- },
- success(res) {
- uni.$u.route('/shopping/paysuccess');
- },
- fail(e) {
- console.log('wxPayfail',e);
- }
- })
- },
-
- initConfig() {
-
- let that = this
- wxH5.config({
- debug: false,
- appId: that.payResult.appId,
- timestamp: that.payResult.timeStamp,
- nonceStr: that.payResult.nonceStr,
- signature: that.payResult.paySign,
- jsApiList: ['chooseWXPay', 'checkJsApi']
- })
- wxH5.ready(() => {
- wxH5.chooseWXPay({
- timestamp: that.payResult.timeStamp,
- nonceStr: that.payResult.nonceStr,
- package: that.payResult.packageValue,
- signType: 'SHA1',
- paySign: that.payResult.paySign,
- success: () => {
-
-
-
-
-
-
- that.payQuery();
- },
- fail: (e) => {
- uni.$u.route('/center/order', {
- status: 0
- });
- console.log('wxPayfail', e);
- },
- cancel: () => {
- uni.$u.route('/center/order', {
- status: 0
- });
- that.cansubmit = true;
- }
- })
- })
-
- },
- payQuery(){
- let that = this;
- let retryCount = 0;
- let maxRetryCount = 5;
- let interval = 2000;
- let timeout = 10000;
- let timer;
- uni.showLoading({
- title:'支付结果查询中'
- })
- timer = setInterval(() => {
- retryCount++;
- if (retryCount > maxRetryCount || retryCount * interval > timeout) {
- clearInterval(timer);
- uni.hideLoading();
- console.log("支付查询超时或达到最大重试次数");
-
- this.reloadList()
- } else {
- console.log("第" + retryCount + "次查询");
-
-
-
- this.$u.api.payQuery({orderId:this.params.orderId}).then(res=>{
-
- let payStatus = res.data.payStatus;
- if(payStatus===1){
- uni.reLaunch({
- url: `/center/orderdetails?type=redirectTo&id=${that.params.orderId}`
- });
- }else if(payStatus===0||payStatus===2){
- this.payQuery()
- }else if(payStatus===3){
- that.cansubmit = true;
- uni.toast('支付失败')
- }
- clearInterval(timer);
- }).catch(err=>{
- that.cansubmit = true;
- console.log('payQuery',err);
- }).finally(()=>{
- uni.hideLoading()
- })
- }
- }, interval);
- },
- groupChange(e){
- console.log('groupChange',e);
- },
- selectPayment(paymentType) {
- this.params.paymentMode = paymentType;
- },
- confirmDateChange(e) {
- console.log('confirmDateChange',e);
- this.params.rePaymentTime = this.$u.timeFormat(e.value, 'yyyy-mm-dd');
- console.log('this.params.rePaymentTime',this.params.rePaymentTime);
- this.showDate = false;
- },
- }
- }
- </script>
- <style>
- page{
- background-color: #F5F5F5;
- }
- </style>
- <style lang="scss" scoped>
- .pay-way{
- background-color: #fff;
- border-radius: 8rpx;
- .pay-way-item {
- padding: 30rpx 10rpx;
- .left{
- .icon{
- width: 40rpx;
- height: 40rpx;
- margin-right: 16rpx;
- }
- .name{
- font-weight: bold;
- margin-right: 40rpx;
- }
- }
- &:not(:last-child){
- border-bottom: 0.5px solid #eee;
- }
- &.disabled{
- .left{
- color: #D8D8D8;
- }
- }
- &.repayment-time{
- padding-bottom: 0;
- }
- }
- .left{
- font-size: 30rpx;
- font-weight: 500;
- color: #333333;
- line-height: 42rpx;
- }
- }
- .full-btn{
- margin-top: 100rpx;
- }
- /deep/ .u-popup__content{
- overflow: hidden;
- border-radius: 8rpx;
- }
- .check-pass{
- padding: 24rpx 40rpx 40rpx;
- .title{
- margin-bottom: 30rpx;
- font-size: 36rpx;
- font-weight: 600;
- color: #333333;
- line-height: 50rpx;
- text-align: center;
- }
- .name{
- text-align: center;
- font-size: 30rpx;
- font-weight: 400;
- color: #666666;
- line-height: 42rpx;
- margin-bottom: 10rpx;
- }
- .number{
- text-align: center;
- font-size: 58rpx;
- font-weight: 600;
- color: #FF3538;
- line-height: 81rpx;
- margin-bottom: 30rpx;
- }
- .the-way{
- font-size: 30rpx;
- font-weight: 400;
- color: #333333;
- line-height: 42rpx;
- margin-bottom: 25rpx;
- }
- .btn-wrap{
-
- }
- }
- .repayment-time {
- .label {
- font-size: 30rpx;
- font-weight: 500;
- color: #333333;
- line-height: 42rpx;
- margin-bottom: 10rpx;
- }
- }
- </style>
|