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

张成 committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77
        // 业务逻辑。。。
      },
      fail: function (err) {
        uni.showToast({
          title: '支付失败',
          icon: 'error',
        });
        uni.setStorageSync('shopCarInfo', []);
        $EventBus.$emit('updateCar');
        uni.switchTab({ url: '/pages/order/order' });
      },
    });
  },
};