1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- export default{
- //开启命名空间
- namespaced:true,
- //数据
- state:()=>({
- // orders:JSON.parse(uni.getStorageSync('orders')||'[]'),
- orders:[],
- //重定向Object对象
- redirectInfo:null,
- }),
- //方法
- mutations:{
- //更新收货地址
- async putOrder(state,order){
- try {
- const response = await uni.request({
- url: uni.$http.baseUrl + 'orders/createOrder',
- method: 'POST',
- header: {
- 'content-type': 'application/json',
- 'token': uni.$http.testToken,
- },
- data: order
- });
- console.log(response,"什么吗是什么三十年")
- if (response.data && response.data.code === '200') {
- // 如果请求成功并且返回的数据中包含 code 为 '200',则提交 mutation 更新店面数据
- // commit('setShops', response.data.data);
- console.log(response.data.data,"aaa")
- } else {
- console.error('请求失败或返回的数据不符合预期');
- }
- } catch (error) {
- console.error('请求失败:', error);
- }
- state.orders=[...state.orders,order]
- // this.commit('m_user/saveOrderToStorage')
- },
- setOrders(state,orders){
- state.orders=orders
- },
- //持久化储存orders
- saveOrderToStorage(state){
- uni.setStorageSync('orders',JSON.stringify(state.orders))
- },
- updateRedirectInfo(state,info){
- state.redirectInfo=info
- console.log(state.redirectInfo);
- },
- },
- actions: {
- //后端请求得到所有的店面的数据,保存入shops
- async fetchOrder({ commit }) {
- // return
- console.log('哈哈哈哈哈')
- try {
- const response = await uni.request({
- url: uni.$http.baseUrl + 'orders/selectAll',
- method: 'GET',
- header: {
- 'content-type': 'application/json',
- 'token': uni.$http.testToken
- }
- });
- if (response.data && response.data.code === '200') {
- // 如果请求成功并且返回的数据中包含 code 为 '200',则提交 mutation 更新店面数据
- commit('setOrders', response.data.data);
- console.log(response.data.data,"aaa啊怎么办呢")
- } else {
- console.error('请求失败或返回的数据不符合预期');
- }
- } catch (error) {
- console.error('请求失败:', error);
- }
- }
- },
- getters:{
- //收货地址
- getOrdersByType(state,type){
- return state.orders.filter(order=>order.orderType===type)
- },
- getOrders(state){
- return state.orders
- }
- }
- }
|