import urlAlias from '../url' import request from '../request' const { orderBuild, buyNow, pay } = urlAlias const state = { list: [], param: {} } const mutations = { LIST: (state, list) => { state.list = list }, SAVE: (state, param) => { state.param = param }, } const actions = { // 立即购买->创建订单 buyNow({ commit }, param) { return new Promise((resolve) => request({ url: buyNow, data: param, success: (res) => { resolve(res) }, fail: () => { uni.showModal({ content: '创建订单失败', showCancel: false, }) }, })) }, // 购物车->创建订单 build({ commit }, param) { return new Promise((resolve, reject) => request({ url: orderBuild, data: param, success: (res) => { resolve(res.data) }, fail: () => { uni.showModal({ content: '订单生成失败', showCancel: false, }) }, })) }, // 支付 pay({ commit }, param) { return new Promise((resolve, reject) => request({ url: pay, data: param, success: (res) => { resolve(res.data) }, fail: () => { uni.showModal({ content: '订单生成失败', showCancel: false, }) }, })) }, // 储存创建订单参数 saveParams({ commit }, param) { console.log('save', param) commit('SAVE', param) }, } export default { namespaced: true, state, mutations, actions, }