index.js 2.49 KB
Newer Older
张成 committed
1
import { $EventBus } from '@/utils/EventBus';
2
import context from '../../main.js'
3
import Order from '@/request/order/index.js'
zhangpeng committed
4
export default {
张成 committed
5 6 7 8 9 10 11 12 13 14 15 16
  // 获取菜单列表
  getMenuList(id) {
    return uni.$u.http
      .get('/weixin/infoByShop', {
        params: {
          shopId: id,
        },
      })
      .then((res) => {
        return res;
      })
      .catch((err) => {
17
        context.showToast({ title: '服务器错误', icon: 'none' });
张成 committed
18 19 20 21 22 23 24 25 26 27 28 29 30
      });
  },
  // 获取点单屏幕的订单信息
  getScreenShopCar(key, location) {
    return uni.$u.http
      .post('/application/getData', {
        key,
        location,
      })
      .then((res) => {
        return res;
      })
      .catch((err) => {
31
        context.showToast({
张成 committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
          title: '服务器错误',
          icon: 'none',
        });
        return err;
      });
  },
  // 下单获取预支付订单
  saveReserve(data) {
    return uni.$u.http
      .post('/order', data)
      .then((res) => {
        return res;
      })
      .catch((err) => { });
  },
  // saveReserve 为业务接口
  requestPayment(data, oldData, buyType) {
    // res为调起微信支付所需参数
    // 调起微信支付
宋冰琦 committed
51
    const { switchTab = true, callBack } = data
张成 committed
52 53 54 55 56 57 58
    uni.requestPayment({
      provider: 'wxpay', // 服务提提供商微信支付
      timeStamp: data.timeStamp, // 时间戳
      nonceStr: data.nonceStr, // 随机字符串
      package: data.package,
      signType: data.signType || 'MD5', // 签名算法
      paySign: data.paySign, // 签名
59
      success: async function (res) {
张成 committed
60 61 62 63
        if (res.errMsg == 'requestPayment:ok') {
          // 删除购物车数据后重新放回购物车
          uni.setStorageSync('shopCarInfo', []);
          $EventBus.$emit('updateCar');
64
          uni.setStorageSync('orderId', data.orderId);
宋冰琦 committed
65
          if(switchTab){
66
            let url = '/orderSubPackage/pages/orderInfo/index?from=settlement'
宋冰琦 committed
67 68 69 70
            uni.navigateTo({ url })
          }else{
            callBack()
          }
张成 committed
71
        }
zhangcheng committed
72

张成 committed
73 74
        // 业务逻辑。。。
      },
75
      fail: async function (err) {
76
        context.showToast({
张成 committed
77 78 79 80 81
          title: '支付失败',
          icon: 'error',
        });
        uni.setStorageSync('shopCarInfo', []);
        $EventBus.$emit('updateCar');
82
		  	uni.setStorageSync('orderId', data.orderId);
宋冰琦 committed
83
        if(switchTab){
84
          let url = '/orderSubPackage/pages/orderInfo/index?from=settlement'
宋冰琦 committed
85 86 87 88
          uni.navigateTo({ url })
        }else{
          callBack()
        }
张成 committed
89 90 91 92
      },
    });
  },
};