|
|
@@ -1,5 +1,7 @@
|
|
|
import DGTMessage from '@/utils/message'//浏览器下载文件
|
|
|
import { signUp } from '@/api/apply.js'
|
|
|
+import { ElMessageBox } from 'element-plus'
|
|
|
+import { createOrder } from '@/api/order.js'
|
|
|
export function downloadFile(url, fileName) {
|
|
|
if (!url) {
|
|
|
DGTMessage.error('文件地址不存在');
|
|
|
@@ -46,3 +48,47 @@ export function formatDeadline(deadline) {
|
|
|
const diffHours = Math.ceil(diffTime / (1000 * 60 * 60)) % 24;
|
|
|
return {diffDays,diffHours};
|
|
|
}
|
|
|
+export function confirmBuy({type='baoMiBalance',price=0,callback,appStore,router,t,payMethod,orderType,productId}){
|
|
|
+ const balance = appStore.userInfo?.[type] || 0;
|
|
|
+ if(balance < price ){
|
|
|
+ ElMessageBox.confirm('您的余额不足,是否前往充值?', t('common.tip'), {
|
|
|
+ confirmButtonText: t('common.confirm'),
|
|
|
+ cancelButtonText: t('common.cancel'),
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ // 确认购买
|
|
|
+ router.push({
|
|
|
+ path: `/order-confirm`,
|
|
|
+ })
|
|
|
+ }).catch(() => {
|
|
|
+ // 取消购买
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ const unit = type === 'baoMiBalance' ? t('common.baomibi') : t('common.mibi');
|
|
|
+ const ms = `${t('common.payNow')} ${price} ${unit}?`
|
|
|
+ ElMessageBox.confirm(ms, t('common.tip'), {
|
|
|
+ confirmButtonText: t('common.confirm'),
|
|
|
+ cancelButtonText: t('common.cancel'),
|
|
|
+ type: 'warning'
|
|
|
+ }).then(async () => {
|
|
|
+ const res = await createOrder({
|
|
|
+ payMethod,
|
|
|
+ orderType,
|
|
|
+ orderAmt:price,
|
|
|
+ productId,
|
|
|
+ orderNum:1
|
|
|
+ })
|
|
|
+ if(res.code === 200){
|
|
|
+ DGTMessage.success(t('common.buy')+t('common.success'));
|
|
|
+ if(callback && typeof callback === 'function'){
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ // DGTMessage.error(res.msg || t('common.buy')+t('common.fail'));
|
|
|
+ }
|
|
|
+
|
|
|
+ }).catch(() => {
|
|
|
+ // 取消购买
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|