/** *Created by ZHJY on 2020/7/14. */ var payContainer = new Vue({ el:"#payContainer", data: { isSubMitStatus:false, payInfo:{ payBankNum: '', //支付类型 payOrderId: '', //订单ID payUnpaidaMount: '', //待支付金额 payAmount: 0,//本次支付金额 payMobileUrl: '',//二维码生成链接 payData:{}, //支付数据 payUserType:'ENTERPRISE', payType:'', }, bankListData:[], methodTab:['线上支付','转账支付'], mobileData:[ {imgUrl:'/img/pay/iconbank-ali@2x.png',bankName:'支付宝支付',bankNum:'ALIPAY'}, {imgUrl:'/img/pay/iconbank-wx@2x.png',bankName:'微信支付',bankNum:'WEIXIN'}, {imgUrl:'/img/pay/iconbank-B2Bbank@2x.png',bankName:'网银支付',bankNum:'ICBC_B2B'}, {imgUrl:'/img/pay/iconbank-B2Cbank@2x.png',bankName:'个人网银',bankNum:'ICBC_B2C'} ], pageType:'',//页面跳转类型 1 二手支付 paidAmount:'',//订单待付金额 payableAmount:'',//应付金额 receiptAmount:'',//已支付金额 balanceAmount:'',//应付剩余金额 payAmount:'',//本次支付金额 paymentIimit:5000, paymentIimitText:'', discernReceiptList:[],//支付记录列表 tabIndex:0,//支付方式 0 移动支付 1网银支付 2线下转账 mbOrderId:'',//支付订单ID BankUserType:1, mobileTabIndex:null, bankTabIndex:0, isRequest:false, isPayAlert:false, isPaySwitch:false, paySuccessCounter:'', bankPayLink_url:'', orderIdentificationId:'',//订单标识 receiptStatus:'', isReceiptStatus:false, onlinePay:1, payStatusText:'使用微信和企业网银支付全部金额后,供应商会在24小时后发货(周末、节假日顺延)。若着急发货,可以选择使用线下转账进行付款。', productID:'',//发布商品的ID is_Wechat_bowcr:false, comboInfo: null, //选中的svip套餐信息 vipRecordId: undefined, }, filters: { NumFormat:function(value) { if(!value) return '0.00'; var intPart = Number(value) - Number(value)%1; //获取整数部分(这里是windy93的方法) var intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); //将整数部分逢三一断 var floatPart = ".00"; //预定义小数部分 var value2Array = value.toString().split("."); if(value2Array.length == 2) { //=2表示数据有小数位 floatPart = value2Array[1].toString(); //拿到小数部分 if(floatPart.length == 1) { //补0,实际上用不着 return intPartFormat + "." + floatPart + '0'; } else { return intPartFormat + "." + floatPart; } } else { return intPartFormat + floatPart; } } }, methods: { infoPayOrderCheckoutCounter:function(){//初始化订单数据 var _self = this; PayApi.PayOrderCheckoutCounter({orderId:_self.payInfo.payOrderId},function(response){ if(response.code == 0){ // console.log(response); var data = response.data; //金额初始化 _self.payInfo.payUnpaidaMount = (data.order.payableAmount - data.order.receiptAmount).toFixed(2); _self.payInfo.payAmount = (data.order.payableAmount-data.order.receiptAmount).toFixed(2); _self.discernReceiptList = data.discernReceipt; _self.paidAmount = (data.order.payableAmount-data.order.receiptAmount).toFixed(2); _self.receiptAmount = data.order.receiptAmount; _self.payableAmount= data.order.payableAmount; _self.balanceAmount = ( _self.payableAmount - _self.receiptAmount).toFixed(2) - _self.payInfo.payAmount; _self.payAmount = (_self.payableAmount - _self.receiptAmount).toFixed(2);//本次支付金额 _self.paySuccessCounter = data.order.paySuccessCounter; _self.receiptStatus = data.order.receiptStatus; _self.onlinePay = data.onlinePay ; if(_self.receiptAmount>0){ _self.payStatusText = '使用微信和网银支付全部金额后,供应商会在24小时后发货(周末、节假日顺延)。'; _self.isReceiptStatus = false; }else{ _self.payStatusText = '使用微信和网银支付全部金额后,供应商会在24小时后发货(周末、节假日顺延)。若着急发货,可以选择使用线下转账进行付款。'; _self.isReceiptStatus = true; } _self.isRequest = true; _self.PayOrderOnLineSwitch(); }else{ CAIMEI.Alert(response.msg,'确定',false); } }) }, getBankList:function () {// 获取网银支付银行列表 var _self = this; PayApi.PayGetBankCode({},function(response){ if(response.code == 0){ _self.bankListData = response.data.list; }else{ console.log('获取网银支付银行列表异常') } }) }, PayOrderOnLineSwitch:function(){//获取是否可以先上支付 var _self = this; PayApi.PayOrderOnLineSwitch({},function(response){ if(response.code == 0){ if(response.data === 0){ _self.isPaySwitch = true; if (_self.pageType === '2') { CAIMEI.dialog('支付系统遇到点小问题,请稍后重试', false); return; } CAIMEI.Alert('线上支付功能正在维护中,请前往订单详情页面查看线下转账方式后进行付款','确定',true,function(){ window.location.href='/user/order/detail.html?orderId='+_self.payInfo.payOrderId; }); } }else{ CAIMEI.Alert(response.msg,'确定',false); } }) }, PayMobileSubmitFn:function(){//点击移动支付方式 var _self = this; if(_self.isPaySwitch && _self.pageType === '2'){ CAIMEI.dialog('支付系统遇到点小问题,请稍后重试', false); return; } if(_self.onlinePay == 2){ _self.layerConfirm(); }else{ if(_self.payInfo.payBankNum == ''){ CAIMEI.dialog('请选择支付方式'); return; } if(_self.payAmount == ''){ CAIMEI.dialog('请输入本次支付金额'); return; } if(_self.payAmount == 0){ CAIMEI.dialog('本次支付金额不能为0'); return; } if(_self.payAmount*100 < 2){ CAIMEI.dialog('本次支付金额必须大于¥0.02'); return; } if(_self.payAmount > _self.paymentIimit){ switch (_self.payInfo.payBankNum) { case 'WEIXIN': _self.paymentIimitText = '本次支付金额已超出微信支付限额,请输入小于5千的金额进行支付'; break; case 'ALIPAY': _self.paymentIimitText = '本次支付金额已超出支付宝限额,请输入小于5千的金额进行支付'; break; } CAIMEI.Alert(_self.paymentIimitText,'知道了'); return; } if(_self.payInfo.payBankNum == "WEIXIN"){ if(_self.pageType === '1'){ if(!isPC){ var orderInfo = {//二手微信二维码参数 pageType:1, productId:_self.productID, payAmount:_self.payAmount }; _self.payInfo.payMobileUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxea43a0f9ebce9e66&redirect_uri=https://www.caimei365.com/pay/wechatpay.html&response_type=code&scope=snsapi_base&state="+JSON.stringify(orderInfo)+"#wechat_redirect"; location.href = _self.payInfo.payMobileUrl; }else{ _self.payInfo.payData = {//二手 type:_self.payInfo.payBankNum, productId:_self.productID, amount:_self.payAmount, url:_self.payInfo.payMobileUrl }; CAIMEI.Storage.setItem('payData',JSON.stringify(_self.payInfo.payData)); window.open("/pay/caimei-paymobile.html?pageType=1"); _self.isPayAlert = true; } }else if(_self.pageType === '2'){ // 微信支付会员 _self.payVipMiniWxPay(); }else{ if(!isPC){ var orderInfo = {//普通订单微信二维码参数 pageType:0, orderID:_self.payInfo.payOrderId, payAmount:_self.payAmount }; _self.payInfo.payMobileUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxea43a0f9ebce9e66&redirect_uri=https://www.caimei365.com/pay/wechatpay.html&response_type=code&scope=snsapi_base&state="+JSON.stringify(orderInfo)+"#wechat_redirect"; location.href = _self.payInfo.payMobileUrl; }else{ _self.payInfo.payData = {//正常订单 type:_self.payInfo.payBankNum, orderid:_self.payInfo.payOrderId, amount:_self.payAmount, url:_self.payInfo.payMobileUrl }; CAIMEI.Storage.setItem('payData',JSON.stringify(_self.payInfo.payData)); window.open("/pay/caimei-paymobile.html?pageType=0"); _self.isPayAlert = true; } } }else if(_self.payInfo.payBankNum == "ALIPAY"){//支付宝支付 if(_self.pageType === '1'){// 二手 var params = {//二手 returnUrl:'https://www.caimei365.com/', productId:_self.productID, }; _self.PayOrdersecondAliPay(params); }else if(_self.pageType === '2'){ // 支付宝支付会员 _self.payVipAliPay(); }else{ var params = {//正常订单 payAmount:Math.round(_self.payAmount*100), returnUrl:'https://www.caimei365.com/', orderId:_self.payInfo.payOrderId }; _self.PayOrderPcMallAlipay(params); } }else{// 网银支付 if(_self.pageType === '1'){ var params = {//二手 payWay:_self.payInfo.payBankNum, returnUrl:'https://www.caimei365.com/', productId:_self.productID, }; _self.PayOrdersecondUnion(params,_self.payInfo.payBankNum); }else if(_self.pageType === '2'){ // 网银支付会员 console.log('网银支付会员'); }else{ var params = {//正常订单 payWay:_self.payInfo.payBankNum, payAmount:Math.round(_self.payAmount*100), returnUrl:'https://www.caimei365.com/', orderId:_self.payInfo.payOrderId }; _self.PayOrderPcMallPay(params,_self.payInfo.payBankNum); } } } }, PaySubmitFn:function(){//点击网银支付方式 var _self = this; if(_self.isPaySwitch && _self.pageType === '2'){ CAIMEI.dialog('支付系统遇到点小问题,请稍后重试', false); return; } if(_self.onlinePay == 2){ _self.layerConfirm(); }else{ if(_self.payInfo.payBankNum == ''){ CAIMEI.dialog('请选择银行!'); return; } if(_self.payAmount <= 10){ CAIMEI.dialog('网银支付的金额必须大于¥10.00'); return; } if(_self.pageType === '1'){ var params = {//二手 bankCode:_self.payInfo.payBankNum, returnUrl:'https://www.caimei365.com/pay/success.html?pageType=www&type=success&payAmount='+_self.payAmount, productId:_self.productID, userType:_self.payInfo.payUserType, }; _self.PayOrdersecondUnion(params); } else if (_self.pageType === '2') { // 网银付会员 _self.payVipPcMallPay(); } else { var params = {//正常订单 payAmount:Math.round(_self.payAmount*100), bankCode:_self.payInfo.payBankNum, returnUrl:'https://www.caimei365.com/pay/success.html?pageType=www&type=success&payAmount='+_self.payAmount, orderId:_self.payInfo.payOrderId, userType:_self.payInfo.payUserType }; _self.PayOrderPcMallPay(params,_self.payInfo.payBankNum); } } }, PayOrderPcMallPay:function(params){// 正常订单网银支付 var _self = this; _self.isSubMitStatus=true; PayApi.PayOrderPcMallPay(params,function(response){ if(response.code == 0){ _self.isPayAlert = true; _self.isSubMitStatus=false; _self.mbOrderId = response.data.data.mbOrderId; window.open(response.data.data.payUrl); }else{ _self.isSubMitStatus=false; CAIMEI.Alert(response.msg,'确定',false); } }) }, PayOrderPcMallAlipay:function (params){// 正常订单支付宝支付 var _self = this; _self.isSubMitStatus=true; PayApi.PayOrderPcMallAlipay(params,function(response){ if(response.code == 0){ _self.isPayAlert = true; _self.isSubMitStatus=false; _self.mbOrderId = response.data.data.mbOrderId; _self.payInfo.payMobileUrl = response.data.data.payUrl; _self.payInfo.payData = { mbOrderId:_self.mbOrderId, type:_self.payInfo.payBankNum, orderid:_self.payInfo.payOrderId, amount:_self.payAmount, url:_self.payInfo.payMobileUrl }; CAIMEI.Storage.setItem('payData',JSON.stringify(_self.payInfo.payData)); if(!isPC){ location.href = _self.payInfo.payMobileUrl; }else{ window.open("/pay/caimei-paymobile.html?pageType=1"); } }else{ CAIMEI.Alert(response.msg,'确定',false); _self.isSubMitStatus=false; } }) }, PayOrdersecondAliPay:function (params){// 二手支付宝支付 var _self = this; _self.isSubMitStatus=true; PayApi.PayOrdersecondAliPay(params,function(response){ if(response.code == 0){ _self.isPayAlert = true; _self.isSubMitStatus=false; _self.mbOrderId = response.data.data.mbOrderId; _self.payInfo.payMobileUrl = response.data.data.payUrl; _self.payInfo.payData = { mbOrderId:_self.mbOrderId, type:_self.payInfo.payBankNum, productId:_self.productID, amount:_self.payAmount, url:_self.payInfo.payMobileUrl }; CAIMEI.Storage.setItem('payData',JSON.stringify(_self.payInfo.payData)); window.open("/pay/caimei-paymobile.html?pageType=1"); }else{ CAIMEI.Alert(response.msg,'确定',false); _self.isSubMitStatus=false; } }) }, PayOrdersecondUnion:function (params){// 二手网银支付 var _self = this; _self.isSubMitStatus=true; PayApi.PayOrdersecondUnion(params,function(response){ if(response.code == 0){ _self.isPayAlert = true; _self.isSubMitStatus=false; _self.mbOrderId = response.data.data.mbOrderId; window.open(response.data.data.payUrl); }else{ CAIMEI.Alert(response.msg,'确定',false); _self.isSubMitStatus=false; } }) }, changePayAmount:function(event){//输入支付金额控制 var _self = this; var value = event.target.value; if(value == "" || value <0 ){//判断是否等于0 或者为空 _self.payAmount = ''; _self.payInfo.payAmount = _self.payInfo.payUnpaidaMount; _self.balanceAmount = _self.toFixedFn(_self.payInfo.payUnpaidaMount); return; }else if(Number(value) > _self.payInfo.payUnpaidaMount){//判断大于应付金额 _self.payAmount = _self.payInfo.payUnpaidaMount; _self.payInfo.payAmount = _self.payAmount; _self.balanceAmount = _self.toFixedFn(_self.payInfo.payUnpaidaMount-_self.payInfo.payAmount); }else{ _self.payAmount = value; _self.payInfo.payAmount = _self.payAmount; _self.balanceAmount = _self.toFixedFn(_self.payInfo.payUnpaidaMount-_self.payInfo.payAmount); } }, changePayAmountBlur:function(event){//失去焦点设置金额 var _self = this; _self.payAmount = _self.toFixedFn(event.target.value); _self.payInfo.payAmount = _self.payAmount; }, changeTab:function(index,item){//选择支付方式切换 this.tabIndex = index; switch (this.tabIndex) { case 0: this.payInfo.payBankNum = 'ALIPAY'; break; case 1: this.payInfo.payBankNum = ''; break; } }, checkMobilePay:function(index,bankNum){//选择移动支付方式 var _self = this; _self.mobileTabIndex = index; _self.payInfo.payBankNum = bankNum; if( _self.mobileTabIndex==2){ _self.bankTabIndex = 0 _self.payInfo.payType = '1'; _self.payInfo.payUserType = 'ENTERPRISE'; }else if(_self.mobileTabIndex == 3){ _self.bankTabIndex = 0 _self.payInfo.payType = '2'; _self.payInfo.payUserType = 'USER'; } }, checkBankPay:function(index,item){//选择网银支付方式-选择银行 var _self = this; _self.bankTabIndex = index; if( _self.mobileTabIndex == 2 ){ _self.payInfo.payBankNum = item.B2bNum; }else if( _self.mobileTabIndex ==3 ){ _self.payInfo.payBankNum = item.B2cNum; } }, copyLinkPaySubmitFn:function(){//复制网银支付链接 var _self = this; if(_self.isPaySwitch && _self.pageType === '2'){ CAIMEI.dialog('支付系统遇到点小问题,请稍后重试', false); return; } if(_self.onlinePay == 2){ _self.layerConfirm(); }else{ if(_self.payAmount == ''){ CAIMEI.dialog('请输入本次支付金额'); return; } if(_self.payAmount == 0){ CAIMEI.dialog('本次支付金额不能为0'); return; } if(_self.payAmount <= 10){ CAIMEI.dialog('网银支付的金额必须大于¥10.00'); return; } var params = {}; if(_self.pageType == 2){ params = { unpaidAmount:_self.payAmount, vipRecordId: _self.vipRecordId, payType:_self.payInfo.payType, } }else{ params = { unpaidAmount:_self.payAmount, orderId:_self.payInfo.payOrderId, payType:_self.payInfo.payType } } PayApi.PayOrderPayLink(params,function(response){ _self.bankPayLink_url = response.data; var oInput = document.createElement("textarea"); oInput.value = _self.bankPayLink_url; document.body.appendChild(oInput); oInput.select(); // 选择对象 document.execCommand("Copy"); // 执行浏览器复制命令 document.body.removeChild(oInput); CAIMEI.dialog('复制成功'); } ) } }, copyOrderBtnSubmitFn:function(){//复制订单标识 var _self = this; var oInput = document.createElement("textarea"); oInput.value = _self.orderIdentificationId; document.body.appendChild(oInput); oInput.select(); // 选择对象 document.execCommand("Copy"); // 执行浏览器复制命令 document.body.removeChild(oInput); CAIMEI.dialog('复制成功'); }, hidePayAlert:function(){//隐藏已支付弹窗 var _self = this; _self.isPayAlert = false; }, RefreshBody:function(){//刷新页面 var _self = this; // 验证支付(支付会员) if(_self.pageType == 2){ PayApi.PayOrderFindOrderStatus({mbOrderId:_self.mbOrderId},function(response){ _self.isPayAlert = false; var data = response.data.data; if(data.status === '1'){ _self.windowLocationHref('success'); }else{ _self.windowLocationHref('error'); } }); return; } if(_self.payInfo.payBankNum == 'WEIXIN'){ PayApi.PayOrderPayWhetherSuccess({orderId: _self.payInfo.payOrderId, paySuccessCounter:_self.paySuccessCounter},function(response){ _self.isPayAlert = false; if(response.code === 0){ _self.windowLocationHref('success'); }else{ _self.windowLocationHref('error'); } }); }else{ PayApi.PayOrderFindOrderStatus({mbOrderId:_self.mbOrderId},function(response){ _self.isPayAlert = false; var data = response.data.data; if(data.status === '1'){ _self.windowLocationHref('success'); }else{ _self.windowLocationHref('error'); } }); } }, windowLocationHref:function(state){ var _self = this; if( _self.pageType === '1'){ window.location.href = '/pay/success.html?pageType=second&type='+state+'&payAmount='+_self.payAmount; }else if(_self.pageType === '2'){ window.location.href = '/pay/success.html?pageType=vip&type='+state+'&payAmount='+_self.payAmount; }else{ window.location.href = '/pay/success.html?pageType=www&type='+state+'&payAmount='+_self.payAmount; } }, payTypeText:function(state){//处理支付记录文字 var stateText = '', stateTextObject={ 12:'企业网银', 13:'微信支付', 14:'支付宝', 15:'微信支付', 16:'余额抵扣', }; Object.keys(stateTextObject).forEach(function(key) { if(key == state){ stateText = stateTextObject[key] } }); return stateText; }, toFixedFn:function(text){//处理小数点后两位数 return Number(text).toFixed(2); }, layerConfirm:function(){ var _self = this; CAIMEI.Alert('本次交易暂不支持线上支付,请使用线下转账方式付款。','知道了',true,function () { _self.payStatusText = '使用微信和网银支付全部金额后,供应商会在24小时后发货(周末、节假日顺延)。若着急发货,可以选择使用线下转账进行付款。'; _self.isReceiptStatus = true; }); }, // 网银支付会员 payVipPcMallPay: function(){ console.log('网银支付会员'); var _self = this; var params = { bankCode: this.payInfo.payBankNum, returnUrl: 'https://www.caimei365.com/pay/success.html?pageType=www&type=success&payAmount='+_self.payAmount, userType: _self.payInfo.payUserType, vipRecordId: _self.vipRecordId }; PayApi.PayVipPcMallPay(params, function (response) { if (response.code == 0) { _self.isPayAlert = true; _self.isSubMitStatus = false; _self.mbOrderId = response.data.data.mbOrderId; window.open(response.data.data.payUrl); } else { _self.isSubMitStatus = false; CAIMEI.Alert(response.msg, '确定', false); } }); }, // 支付宝支付会员 payVipAliPay: function(){ console.log('支付宝支付会员'); var _self = this; var params = { bankCode: _self.payInfo.payBankNum, returnUrl: 'https://www.caimei365.com/', userType: _self.payInfo.payUserType, vipRecordId: _self.vipRecordId }; console.log(params); PayApi.PayVipAliPay(params, function(response){ console.log(response); if (response.code === 0) { _self.isPayAlert = true; _self.mbOrderId = response.data.data.mbOrderId; _self.payInfo.payMobileUrl = response.data.data.payUrl; _self.payInfo.payData = { mbOrderId: _self.mbOrderId, type: _self.payInfo.payBankNum, amount: _self.payAmount, url: _self.payInfo.payMobileUrl, }; CAIMEI.Storage.setItem('payData', JSON.stringify(_self.payInfo.payData)); if (!isPC) { location.href = _self.payInfo.payMobileUrl; } else { window.open("/pay/caimei-paymobile.html?pageType=2&duration=" + _self.comboInfo.duration); } } else { CAIMEI.Alert(response.msg, '确定', false); _self.isSubMitStatus = false; } }); }, // 微信支付会员 payVipMiniWxPay: function(){ if (!isPC) { var orderInfo = {//普通订单微信二维码参数 pageType: 2, vipId: this.comboInfo.id, vipRecordId: this.vipRecordId, payAmount: this.payAmount }; this.payInfo.payMobileUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxea43a0f9ebce9e66&redirect_uri=https://www.caimei365.com/pay/wechatpay.html&response_type=code&scope=snsapi_base&state=" + JSON.stringify(orderInfo) + "#wechat_redirect"; location.href = this.payInfo.payMobileUrl; } else { this.payInfo.payData = { type: this.payInfo.payBankNum, vipId: this.comboInfo.id, vipRecordId: this.vipRecordId, amount: this.payAmount, duration: this.comboInfo.duration, }; CAIMEI.Storage.setItem('payData', JSON.stringify(this.payInfo.payData)); window.open("/pay/caimei-paymobile.html?pageType=2"); this.isPayAlert = true; } }, }, mounted: function () { var _self = this; // 判断当前支付是订单支付 _self.pageType = CAIMEI.getUrlParam('pageType'); _self.vipRecordId = parseInt(CAIMEI.getUrlParam('vipRecordId')); if (_self.pageType === '1') {//二手 _self.productID = CAIMEI.getUrlParam('productID'); _self.payAmount = _self.toFixedFn(100); _self.isRequest = true; _self.payStatusText = ''; } else if (_self.pageType === '2') { // 支付会员 this.PayOrderOnLineSwitch(); // 从本地获取选中的svip套餐信息后删除本地信息 this.comboInfo = JSON.parse(CAIMEI.Storage.getItem('comboInfo')); // CAIMEI.Storage.removeItem('comboInfo'); // 设置支付金额 this.payAmount = _self.toFixedFn(this.comboInfo.price); this.getBankList(); // 获取银行列表 } else { var HrefType = CAIMEI.getUrlParam('type'); if (HrefType == 'payfirm') { _self.payInfo.payOrderId = CAIMEI.getUrlParam('orderId'); _self.orderIdentificationId = '#' + _self.payInfo.payOrderId + '#'; } else { var data = JSON.parse(localStorage.getItem("confirmOrderInfo")); _self.payInfo.payOrderId = data.data.orderId; _self.orderIdentificationId = '#' + _self.payInfo.payOrderId + '#'; } this.getBankList(); // 获取银行列表 this.infoPayOrderCheckoutCounter();//正常订单初始化 } var viewer = window.navigator.userAgent.toLowerCase(); if(viewer.match(/MicroMessenger/i) == 'micromessenger'){ _self.is_Wechat_bowcr = true; _self.payInfo.payBankNum = 'WEIXIN'; _self.mobileTabIndex = 1; }else{ _self.is_Wechat_bowcr = false; _self.payInfo.payBankNum = 'ALIPAY'; _self.mobileTabIndex = 0; } } });