Blame view

src/store/modules/address.js 1.99 KB
7d6833f2c   范牧   地址列表
1
2
  import urlAlias from '../url'
  import request from '../request'
323398550   范牧   若干功能添加
3
  const { editAddress, addressList, getAddress, getDefaultAddress } = urlAlias
7d6833f2c   范牧   地址列表
4

323398550   范牧   若干功能添加
5
  const state = { list: [], detail: {}, defaultInfo: {} }
7d6833f2c   范牧   地址列表
6
7
8
9
10
11
12
  
  const mutations = {
    LIST: (state, list) => {
      state.list = list
    },
    DETAILS: (state, details) => {
      state.details = details
323398550   范牧   若干功能添加
13
14
15
    },
    DEFAULT: (state, data) => {
      state.defaultInfo = data
7d6833f2c   范牧   地址列表
16
17
18
19
20
    }
  }
  
  const actions = {
    edit(mutations, param, success) {
4e9d88ff7   范牧   新建地址修改
21
      return new Promise((resolve) => request({
7d6833f2c   范牧   地址列表
22
23
        url: editAddress,
        data: param,
4e9d88ff7   范牧   新建地址修改
24
25
26
        success: () => {
          resolve()
        },
7d6833f2c   范牧   地址列表
27
28
29
30
31
32
33
34
35
        fail: () => {
          uni.showModal({
            content: '编辑失败',
            showCancel: false
          })
        },
        complete: (res) => {
          console.log('complete status === > ', res)
        }
4e9d88ff7   范牧   新建地址修改
36
      }))
7d6833f2c   范牧   地址列表
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    },
    list({ commit }) {
      request({
        url: addressList,
        success: (res) => {
          commit('LIST', res.data.data)
        },
        fail: () => {
          uni.showModal({
            content: '获取地址列表失败',
            showCancel: false
          })
        }
      })
    },
323398550   范牧   若干功能添加
52
    details({ commit }, param) {
7d6833f2c   范牧   地址列表
53
54
55
56
57
      return new Promise((resolve, reject) => request({
        url: getAddress,
        data: param,
        success: (res) => {
          commit('DETAILS', res.data.data)
323398550   范牧   若干功能添加
58
59
60
61
          resolve({
            code: res.data.code,
            data: res.data.data
          })
7d6833f2c   范牧   地址列表
62
63
64
65
66
67
68
69
        },
        fail: () => {
          uni.showModal({
            content: '获取地址信息失败',
            showCancel: false
          })
        }
      }))
323398550   范牧   若干功能添加
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    },
    default({ commit }, param) {
      return new Promise((resolve, reject) => request({
        url: getDefaultAddress,
        data: param,
        success: (res) => {
          resolve({
            code: res.data.code,
            data: res.data.data
          })
        },
        fail: () => {
          uni.showModal({
            content: '获取默认地址信息失败',
            showCancel: false
          })
        }
      }))
7d6833f2c   范牧   地址列表
88
89
90
91
92
93
94
95
96
    }
  }
  
  export default {
    namespaced: true,
    state,
    mutations,
    actions
  }